Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0AC2A10001 for ; Tue, 11 Mar 2014 13:13:54 +0000 (UTC) Received: (qmail 52705 invoked by uid 500); 11 Mar 2014 13:13:21 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 52666 invoked by uid 500); 11 Mar 2014 13:13:19 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 49160 invoked by uid 99); 11 Mar 2014 13:12:59 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Mar 2014 13:12:59 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id D0A9A93EB06; Tue, 11 Mar 2014 13:12:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: muralireddy@apache.org To: commits@cloudstack.apache.org Date: Tue, 11 Mar 2014 13:13:09 -0000 Message-Id: <6256ca7d820b4bbcbec1f541ce87eda8@git.apache.org> In-Reply-To: <5875e6c868544ef8aee529bd3e883e37@git.apache.org> References: <5875e6c868544ef8aee529bd3e883e37@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [12/50] [abbrv] Removed unused methods from BaseCmd class. Moved some helper methods to AccountManagerImpl class http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b0c5cfc/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java b/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java index 867625d..0803a2b 100644 --- a/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java +++ b/server/test/com/cloud/api/dispatch/ParamGenericValidationWorkerTest.java @@ -16,16 +16,15 @@ // under the License. package com.cloud.api.dispatch; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,6 +32,9 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.log4j.Logger; +import org.junit.Test; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -40,8 +42,9 @@ import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; - -import org.apache.log4j.Logger; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; public class ParamGenericValidationWorkerTest { @@ -55,9 +58,9 @@ public class ParamGenericValidationWorkerTest { final ParamGenericValidationWorker genValidationWorker = new ParamGenericValidationWorker(); // We create a mock logger to verify the result - ParamGenericValidationWorker.s_logger = new Logger(""){ + ParamGenericValidationWorker.s_logger = new Logger("") { @Override - public void warn(final Object msg){ + public void warn(final Object msg) { loggerOutput = msg.toString(); } }; @@ -74,8 +77,15 @@ public class ParamGenericValidationWorkerTest { params.put(ApiConstants.COMMAND, ""); params.put("addedParam", ""); + Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString()); + CallContext.register(user, account); // Execute - driveTest(cmd, params); + try { + driveTest(cmd, params); + } finally { + CallContext.unregister(); + } // Assert assertEquals("There should be no errors since there are no unknown parameters for this command class", null, loggerOutput); @@ -91,8 +101,16 @@ public class ParamGenericValidationWorkerTest { params.put("addedParam", ""); params.put(unknownParamKey, ""); + Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString()); + CallContext.register(user, account); + // Execute - driveTest(cmd, params); + try { + driveTest(cmd, params); + } finally { + CallContext.unregister(); + } // Assert assertTrue("There should be error msg, since there is one unknown parameter", loggerOutput.contains(unknownParamKey)); @@ -102,6 +120,7 @@ public class ParamGenericValidationWorkerTest { @Test public void testHandleWithoutAuthorization() throws ResourceAllocationException { final short type = Account.ACCOUNT_TYPE_NORMAL; + driveAuthTest(type); // Assert @@ -112,25 +131,33 @@ public class ParamGenericValidationWorkerTest { @Test public void testHandleWithAuthorization() throws ResourceAllocationException { final short type = Account.ACCOUNT_TYPE_ADMIN; - driveAuthTest(type); + driveAuthTest(type); // Assert assertEquals("There should be no errors since parameters have authorization", null, loggerOutput); } protected void driveAuthTest(final short type) { + // Prepare final BaseCmd cmd = new FakeCmdWithRoleAdmin(); final Account account = mock(Account.class); ((FakeCmdWithRoleAdmin)cmd).account = account; when(account.getType()).thenReturn(type); + User user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString()); + CallContext.register(user, account); + final Map params = new HashMap(); params.put(ApiConstants.COMMAND, ""); params.put("addedParam", ""); params.put("paramWithRole", ""); // Execute - driveTest(cmd, params); + try { + driveTest(cmd, params); + } finally { + CallContext.unregister(); + } } } @@ -143,11 +170,6 @@ class FakeCmd extends BaseCmd { public Account account; - @Override - protected Account getCurrentContextAccount() { - return account; - } - // // Dummy methods for mere correct compilation // http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7b0c5cfc/server/test/com/cloud/user/MockAccountManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/user/MockAccountManagerImpl.java b/server/test/com/cloud/user/MockAccountManagerImpl.java index 62e7fc8..5a44800 100644 --- a/server/test/com/cloud/user/MockAccountManagerImpl.java +++ b/server/test/com/cloud/user/MockAccountManagerImpl.java @@ -22,8 +22,6 @@ import java.util.Map; import javax.ejb.Local; import javax.naming.ConfigurationException; -import org.springframework.stereotype.Component; - import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -31,6 +29,7 @@ import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd; import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd; import org.apache.cloudstack.api.command.admin.user.RegisterCmd; import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd; +import org.springframework.stereotype.Component; import com.cloud.api.query.vo.ControlledViewEntity; import com.cloud.domain.Domain; @@ -322,4 +321,10 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco return null; } + @Override + public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) { + // TODO Auto-generated method stub + return null; + } + }