cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [02/12] UserContext switched to CallContext. Added generic storage mechanism for other code to carry information throughout a call. Made the calling User and Account a must have. Added an interface to carry entities in error. Fixed up the code. Part
Date Tue, 16 Jul 2013 18:24:25 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/com/cloud/vpc/NetworkACLServiceTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/NetworkACLServiceTest.java b/server/test/com/cloud/vpc/NetworkACLServiceTest.java
index e71fabf..b2588aa 100644
--- a/server/test/com/cloud/vpc/NetworkACLServiceTest.java
+++ b/server/test/com/cloud/vpc/NetworkACLServiceTest.java
@@ -15,23 +15,15 @@
 
 package com.cloud.vpc;
 
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.network.NetworkManager;
-import com.cloud.network.NetworkModel;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.network.vpc.*;
-import com.cloud.network.vpc.dao.NetworkACLDao;
-import com.cloud.network.vpc.dao.VpcGatewayDao;
-import com.cloud.tags.dao.ResourceTagDao;
-import com.cloud.user.Account;
-import com.cloud.user.AccountManager;
-import com.cloud.user.AccountVO;
-import com.cloud.user.UserContext;
-import com.cloud.utils.component.ComponentContext;
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.inject.Inject;
+
 import junit.framework.TestCase;
-import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
-import org.apache.cloudstack.test.utils.SpringUtils;
+
 import org.apache.log4j.Logger;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -47,9 +39,31 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.test.context.support.AnnotationConfigContextLoader;
 
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.UUID;
+import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.test.utils.SpringUtils;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.NetworkACLItemDao;
+import com.cloud.network.vpc.NetworkACLItemVO;
+import com.cloud.network.vpc.NetworkACLManager;
+import com.cloud.network.vpc.NetworkACLService;
+import com.cloud.network.vpc.NetworkACLServiceImpl;
+import com.cloud.network.vpc.NetworkACLVO;
+import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.VpcVO;
+import com.cloud.network.vpc.dao.NetworkACLDao;
+import com.cloud.network.vpc.dao.VpcGatewayDao;
+import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.UserVO;
+import com.cloud.utils.component.ComponentContext;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@@ -74,11 +88,14 @@ public class NetworkACLServiceTest extends TestCase{
 
     private static final Logger s_logger = Logger.getLogger( NetworkACLServiceTest.class);
 
+    @Override
     @Before
     public void setUp() {
         ComponentContext.initComponentsLifeCycle();
         Account account = new AccountVO("testaccount", 1, "testdomain", (short) 0, UUID.randomUUID().toString());
-        UserContext.registerContext(1, account, null, true);
+        UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email",
"timezone", UUID.randomUUID().toString());
+
+        CallContext.register(user, account);
 
         createACLItemCmd = new CreateNetworkACLCmd(){
             @Override
@@ -118,6 +135,12 @@ public class NetworkACLServiceTest extends TestCase{
         };
     }
 
+    @Override
+    @After
+    public void tearDown() {
+        CallContext.unregister();
+    }
+
     @Test
     public void testCreateACL() throws Exception {
         Mockito.when(_vpcMgr.getVpc(Mockito.anyLong())).thenReturn(new VpcVO());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/com/cloud/vpc/VpcTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/VpcTest.java b/server/test/com/cloud/vpc/VpcTest.java
index 52e837e..24c011b 100644
--- a/server/test/com/cloud/vpc/VpcTest.java
+++ b/server/test/com/cloud/vpc/VpcTest.java
@@ -15,6 +15,33 @@
 
 package com.cloud.vpc;
 
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.inject.Inject;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.core.type.filter.TypeFilter;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.test.utils.SpringUtils;
+
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.dao.DataCenterDao;
@@ -27,7 +54,12 @@ import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.Site2SiteVpnGatewayDao;
-import com.cloud.network.vpc.*;
+import com.cloud.network.vpc.NetworkACLManager;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.VpcOfferingVO;
+import com.cloud.network.vpc.VpcService;
+import com.cloud.network.vpc.VpcVO;
 import com.cloud.network.vpc.dao.PrivateIpDao;
 import com.cloud.network.vpc.dao.StaticRouteDao;
 import com.cloud.network.vpc.dao.VpcDao;
@@ -43,34 +75,10 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
 import com.cloud.user.ResourceLimitService;
-import com.cloud.user.UserContext;
+import com.cloud.user.UserVO;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.vm.dao.DomainRouterDao;
 
-import junit.framework.TestCase;
-import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
-import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd;
-import org.apache.cloudstack.test.utils.SpringUtils;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.FilterType;
-import org.springframework.core.type.classreading.MetadataReader;
-import org.springframework.core.type.classreading.MetadataReaderFactory;
-import org.springframework.core.type.filter.TypeFilter;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.context.support.AnnotationConfigContextLoader;
-
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.UUID;
-
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(loader = AnnotationConfigContextLoader.class)
 public class VpcTest extends TestCase {
@@ -93,14 +101,23 @@ public class VpcTest extends TestCase {
     private VpcVO vpc;
     private static final Logger s_logger = Logger.getLogger(VpcTest.class);
 
+    @Override
     @Before
     public void setUp() {
         ComponentContext.initComponentsLifeCycle();
         Account account = new AccountVO("testaccount", 1, "testdomain", (short) 0, UUID.randomUUID().toString());
-        UserContext.registerContext(1, account, null, true);
+        UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email",
"timezone", UUID.randomUUID().toString());
+
+        CallContext.register(user, account);
         vpc = new VpcVO(1, "myvpc", "myvpc", 2, 1, 1, "10.0.1.0/16", "mydomain");
     }
 
+    @Override
+    @After
+    public void tearDown() {
+        CallContext.unregister();
+    }
+
     @Test
     public void testCreateVpc() throws Exception {
         Mockito.when(

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
index 8c1c114..d62b4ff 100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
@@ -17,7 +17,6 @@
 package org.apache.cloudstack.affinity;
 
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Matchers.anyLong;
 import static org.mockito.Matchers.anyObject;
@@ -28,13 +27,12 @@ import static org.mockito.Mockito.when;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.UUID;
 
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
-import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
-import org.apache.cloudstack.test.utils.SpringUtils;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -52,8 +50,13 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.test.context.support.AnnotationConfigContextLoader;
 
-import com.cloud.dc.dao.DedicatedResourceDao;
-import com.cloud.event.ActionEventUtils;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.test.utils.SpringUtils;
+
+import com.cloud.dc.dao.DedicatedResourceDao;
+import com.cloud.event.ActionEventUtils;
 import com.cloud.event.EventVO;
 import com.cloud.event.dao.EventDao;
 import com.cloud.exception.InvalidParameterValueException;
@@ -63,14 +66,12 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountService;
 import com.cloud.user.AccountVO;
-import com.cloud.user.UserContext;
+import com.cloud.user.UserVO;
 import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
 import com.cloud.utils.component.ComponentContext;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachine;
-import com.cloud.user.dao.UserDao;
 import com.cloud.vm.dao.UserVmDao;
 
 @RunWith(SpringJUnit4ClassRunner.class)
@@ -115,18 +116,20 @@ public class AffinityApiUnitTest {
 
 
     @BeforeClass
-    public static void setUp() throws ConfigurationException {
+    public static void setUpClass() throws ConfigurationException {
     }
 
     @Before
-    public void testSetUp() {
+    public void setUp() {
         ComponentContext.initComponentsLifeCycle();
         AccountVO acct = new AccountVO(200L);
         acct.setType(Account.ACCOUNT_TYPE_NORMAL);
         acct.setAccountName("user");
         acct.setDomainId(domainId);
 
-        UserContext.registerContext(1, acct, null, true);
+        UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email",
"timezone", UUID.randomUUID().toString());
+
+        CallContext.register(user, acct);
 
         when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
         when(_processor.getType()).thenReturn("mock");
@@ -141,6 +144,11 @@ public class AffinityApiUnitTest {
         Mockito.when(_eventDao.persist(Mockito.any(EventVO.class))).thenReturn(new EventVO());
     }
 
+    @After
+    public void tearDown() {
+        CallContext.unregister();
+    }
+
     @Test
     public void createAffinityGroupTest() {
         when(_groupDao.isNameInUse(anyLong(), anyLong(), eq("group1"))).thenReturn(false);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java b/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java
index 461cbbd..bd2374f 100644
--- a/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java
+++ b/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -24,9 +24,7 @@ import javax.inject.Inject;
 
 import junit.framework.TestCase;
 
-import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
-import org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl;
-import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -34,6 +32,11 @@ import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
+
 import com.cloud.event.dao.UsageEventDao;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
@@ -53,7 +56,6 @@ import com.cloud.network.rules.FirewallRuleVO;
 import com.cloud.network.rules.LoadBalancerContainer.Scheme;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
-import com.cloud.user.UserContext;
 import com.cloud.user.UserVO;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -94,6 +96,7 @@ public class ApplicationLoadBalancerTest extends TestCase{
 
 
     
+    @Override
     @Before
     public void setUp() {
         ComponentContext.initComponentsLifeCycle();
@@ -133,7 +136,7 @@ public class ApplicationLoadBalancerTest extends TestCase{
         
         Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
         Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
-        UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(),
null, false);
+        CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
         
         Mockito.when(_ntwkModel.areServicesSupportedInNetwork(Mockito.anyLong(), Mockito.any(Network.Service.class))).thenReturn(true);
         
@@ -146,6 +149,12 @@ public class ApplicationLoadBalancerTest extends TestCase{
         
     }
     
+    @Override
+    @After
+    public void tearDown() {
+        CallContext.unregister();
+    }
+
     /**
      * TESTS FOR .getApplicationLoadBalancer
      */
@@ -165,7 +174,7 @@ public class ApplicationLoadBalancerTest extends TestCase{
         try {
             rule = _appLbSvc.getApplicationLoadBalancer(nonExistingLbId);
             if (rule != null) {
-                notFound = false; 
+                notFound = false;
             }
         } catch (InvalidParameterValueException ex) {
             notFound = true;
@@ -182,11 +191,11 @@ public class ApplicationLoadBalancerTest extends TestCase{
     @Test
     //Positive test - delete existing lb
     public void deleteExistingLoadBalancer() {
-        boolean result = false; 
+        boolean result = false;
         try {
             result = _appLbSvc.deleteApplicationLoadBalancer(existingLbId);
         } finally {
-            assertTrue("Couldn't delete existing application load balancer", result);   
+            assertTrue("Couldn't delete existing application load balancer", result);
         }
     }
     
@@ -204,17 +213,17 @@ public class ApplicationLoadBalancerTest extends TestCase{
     
     /**
      * TESTS FOR .createApplicationLoadBalancer
-     * @throws NetworkRuleConflictException 
-     * @throws InsufficientVirtualNetworkCapcityException 
-     * @throws InsufficientAddressCapacityException 
+     * @throws NetworkRuleConflictException
+     * @throws InsufficientVirtualNetworkCapcityException
+     * @throws InsufficientAddressCapacityException
      */
     
     @Test (expected = CloudRuntimeException.class)
     //Positive test
     public void createValidLoadBalancer() throws InsufficientAddressCapacityException,
-        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {    
+        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {
         _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validGuestNetworkId,
validRequestedIp,
-                            22, 22, "roundrobin", validGuestNetworkId, validAccountId); 
+                            22, 22, "roundrobin", validGuestNetworkId, validAccountId);
     }
     
     
@@ -230,7 +239,7 @@ public class ApplicationLoadBalancerTest extends TestCase{
     @Test(expected = InvalidParameterValueException.class)
     //Negative test - invalid SourcePort
     public void createWithInvalidSourcePort() throws InsufficientAddressCapacityException,
-        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {      
 
+        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {
         _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validGuestNetworkId,
validRequestedIp,
                     65536, 22, "roundrobin", validGuestNetworkId, validAccountId);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
index 27faa4d..7760123 100644
--- a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
+++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
@@ -19,12 +19,6 @@ package org.apache.cloudstack.networkoffering;
 
 import java.io.IOException;
 
-
-import org.apache.cloudstack.acl.SecurityChecker;
-import org.apache.cloudstack.region.PortableIpDaoImpl;
-import org.apache.cloudstack.region.dao.RegionDaoImpl;
-import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
-import org.apache.cloudstack.test.utils.SpringUtils;
 import org.mockito.Mockito;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
@@ -35,7 +29,15 @@ import org.springframework.core.type.classreading.MetadataReader;
 import org.springframework.core.type.classreading.MetadataReaderFactory;
 import org.springframework.core.type.filter.TypeFilter;
 
+import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.region.PortableIpDaoImpl;
+import org.apache.cloudstack.region.PortableIpRangeDaoImpl;
+import org.apache.cloudstack.region.dao.RegionDaoImpl;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
+import org.apache.cloudstack.test.utils.SpringUtils;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.alert.AlertManager;
 import com.cloud.api.query.dao.UserAccountJoinDaoImpl;
@@ -106,8 +108,6 @@ import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.user.AccountDetailsDao;
 import com.cloud.user.AccountManager;
 import com.cloud.user.ResourceLimitService;
-import com.cloud.user.UserContext;
-import com.cloud.user.UserContextInitializer;
 import com.cloud.user.dao.AccountDaoImpl;
 import com.cloud.user.dao.UserDaoImpl;
 import com.cloud.vm.dao.InstanceGroupDaoImpl;
@@ -115,7 +115,6 @@ import com.cloud.vm.dao.NicDaoImpl;
 import com.cloud.vm.dao.NicSecondaryIpDaoImpl;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.VMInstanceDaoImpl;
-import org.apache.cloudstack.region.PortableIpRangeDaoImpl;
 
 @Configuration
 @ComponentScan(basePackageClasses={
@@ -296,13 +295,8 @@ public class ChildTestConfiguration {
     }
 
     @Bean
-    public UserContext userContext() {
-        return Mockito.mock(UserContext.class);
-    }
-
-    @Bean
-    public UserContextInitializer userContextInitializer() {
-        return Mockito.mock(UserContextInitializer.class);
+    public CallContext userContext() {
+        return Mockito.mock(CallContext.class);
     }
 
     @Bean

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
index 36564d9..9825cab 100644
--- a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
+++ b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
@@ -17,6 +17,25 @@
 
 package org.apache.cloudstack.networkoffering;
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import junit.framework.TestCase;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import org.apache.cloudstack.context.CallContext;
+
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.ConfigurationVO;
 import com.cloud.configuration.dao.ConfigurationDao;
@@ -33,22 +52,8 @@ import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
-import com.cloud.user.UserContext;
 import com.cloud.user.UserVO;
 import com.cloud.utils.component.ComponentContext;
-import junit.framework.TestCase;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import javax.inject.Inject;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations="classpath:/createNetworkOffering.xml")
@@ -73,6 +78,7 @@ public class CreateNetworkOfferingTest extends TestCase{
     @Inject
     VpcManager vpcMgr;
 
+    @Override
     @Before
     public void setUp() {
     	ComponentContext.initComponentsLifeCycle();
@@ -86,7 +92,13 @@ public class CreateNetworkOfferingTest extends TestCase{
         Mockito.when(accountMgr.getSystemUser()).thenReturn(new UserVO(1));
         Mockito.when(accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
 
-        UserContext.registerContext(accountMgr.getSystemUser().getId(), accountMgr.getSystemAccount(),
null, false);
+        CallContext.register(accountMgr.getSystemUser(), accountMgr.getSystemAccount());
+    }
+
+    @Override
+    @After
+    public void tearDown() {
+        CallContext.unregister();
     }
 
     //Test Shared network offerings

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/org/apache/cloudstack/region/RegionManagerTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/region/RegionManagerTest.java b/server/test/org/apache/cloudstack/region/RegionManagerTest.java
index b6d1969..db6bf20 100644
--- a/server/test/org/apache/cloudstack/region/RegionManagerTest.java
+++ b/server/test/org/apache/cloudstack/region/RegionManagerTest.java
@@ -22,7 +22,9 @@ import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.apache.cloudstack.api.command.admin.domain.DeleteDomainCmd;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.region.dao.RegionDao;
+
 import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Test;
@@ -30,7 +32,6 @@ import org.mockito.Mockito;
 
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 import com.cloud.user.dao.AccountDao;
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java
b/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java
index 6d49ec0..2355089 100644
--- a/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java
+++ b/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java
@@ -15,43 +15,72 @@
 
 package org.apache.cloudstack.region.gslb;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd;
+import org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd;
+import org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd;
+import org.apache.cloudstack.api.command.user.region.ha.gslb.RemoveFromGlobalLoadBalancerRuleCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.region.RegionVO;
+import org.apache.cloudstack.region.dao.RegionDao;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.network.dao.*;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.LoadBalancerDao;
+import com.cloud.network.dao.LoadBalancerVO;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.rules.FirewallRule;
 import com.cloud.network.rules.RulesManager;
 import com.cloud.region.ha.GlobalLoadBalancerRule;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
-import com.cloud.user.UserContext;
+import com.cloud.user.UserVO;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.net.Ip;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd;
-import org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd;
-import org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd;
-import org.apache.cloudstack.api.command.user.region.ha.gslb.RemoveFromGlobalLoadBalancerRuleCmd;
-import org.apache.cloudstack.region.RegionVO;
-import org.apache.cloudstack.region.dao.RegionDao;
-import org.apache.log4j.Logger;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.when;
 
 public class GlobalLoadBalancingRulesServiceImplTest extends TestCase {
 
     private static final Logger s_logger = Logger.getLogger( GlobalLoadBalancingRulesServiceImplTest.class);
 
+    @Override
+    @Before
+    public void setUp() {
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short)0, UUID.randomUUID().toString());
+
+        UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email",
"timezone", UUID.randomUUID().toString());
+
+        CallContext.register(user, account);
+    }
+
+    @Override
+    @After
+    public void tearDown() {
+        CallContext.unregister();
+    }
+
     @Test
     public void testCreateGlobalLoadBalancerRule() throws Exception {
 
@@ -157,7 +186,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         GlobalLoadBalancingRulesServiceImpl gslbServiceImpl =  new GlobalLoadBalancingRulesServiceImpl();
 
         gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
-        Account account = (Account) new AccountVO("testaccount", 1,
+        Account account = new AccountVO("testaccount", 1,
                 "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
@@ -222,7 +251,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         GlobalLoadBalancingRulesServiceImpl gslbServiceImpl =  new GlobalLoadBalancingRulesServiceImpl();
 
         gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
-        Account account = (Account) new AccountVO("testaccount", 1,
+        Account account = new AccountVO("testaccount", 1,
                 "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
@@ -287,7 +316,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         GlobalLoadBalancingRulesServiceImpl gslbServiceImpl =  new GlobalLoadBalancingRulesServiceImpl();
 
         gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
-        Account account = (Account) new AccountVO("testaccount", 1,
+        Account account = new AccountVO("testaccount", 1,
                 "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
@@ -352,7 +381,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         GlobalLoadBalancingRulesServiceImpl gslbServiceImpl =  new GlobalLoadBalancingRulesServiceImpl();
 
         gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
-        Account account = (Account) new AccountVO("testaccount", 1,
+        Account account = new AccountVO("testaccount", 1,
                 "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
@@ -417,7 +446,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         GlobalLoadBalancingRulesServiceImpl gslbServiceImpl =  new GlobalLoadBalancingRulesServiceImpl();
 
         gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
-        Account account = (Account) new AccountVO("testaccount", 1,
+        Account account = new AccountVO("testaccount", 1,
                 "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
@@ -496,11 +525,9 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         AssignToGlobalLoadBalancerRuleCmd assignCmd = new AssignToGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = assignCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
-        UserContext.registerContext(1, account, null, true);
-
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
         gslbRuleId.set(assignCmd, new Long(1));
@@ -561,11 +588,9 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         AssignToGlobalLoadBalancerRuleCmd assignCmd = new AssignToGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = assignCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 3, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 3, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
-        UserContext.registerContext(1, account, null, true);
-
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
         gslbRuleId.set(assignCmd, new Long(1));
@@ -648,11 +673,9 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         AssignToGlobalLoadBalancerRuleCmd assignCmd = new AssignToGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = assignCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
-        UserContext.registerContext(1, account, null, true);
-
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
         gslbRuleId.set(assignCmd, new Long(1));
@@ -708,9 +731,8 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd = new RemoveFromGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = removeFromGslbCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
-        UserContext.registerContext(1, account, null, true);
 
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
@@ -781,9 +803,8 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd = new RemoveFromGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = removeFromGslbCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
-        UserContext.registerContext(1, account, null, true);
 
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
@@ -843,9 +864,8 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd = new RemoveFromGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = removeFromGslbCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
-        UserContext.registerContext(1, account, null, true);
 
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
@@ -888,11 +908,9 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         DeleteGlobalLoadBalancerRuleCmd deleteCmd = new DeleteGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = deleteCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
-        UserContext.registerContext(1, account, null, true);
-
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
         gslbRuleId.set(deleteCmd, new Long(1));
@@ -936,11 +954,9 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
         DeleteGlobalLoadBalancerRuleCmd deleteCmd = new DeleteGlobalLoadBalancerRuleCmdExtn();
         Class<?> _class = deleteCmd.getClass().getSuperclass();
 
-        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
         when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
 
-        UserContext.registerContext(1, account, null, true);
-
         Field gslbRuleId = _class.getDeclaredField("id");
         gslbRuleId.setAccessible(true);
         gslbRuleId.set(deleteCmd, new Long(1));
@@ -965,24 +981,28 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase
{
     }
 
     public class CreateGlobalLoadBalancerRuleCmdExtn extends CreateGlobalLoadBalancerRuleCmd
{
+        @Override
         public long getEntityOwnerId() {
             return 1;
         }
     }
 
     public class AssignToGlobalLoadBalancerRuleCmdExtn extends AssignToGlobalLoadBalancerRuleCmd
{
+        @Override
         public long getEntityOwnerId() {
             return 1;
         }
     }
 
     public class RemoveFromGlobalLoadBalancerRuleCmdExtn extends RemoveFromGlobalLoadBalancerRuleCmd
{
+        @Override
         public long getEntityOwnerId() {
             return 1;
         }
     }
 
     public class DeleteGlobalLoadBalancerRuleCmdExtn extends DeleteGlobalLoadBalancerRuleCmd
{
+        @Override
         public long getEntityOwnerId() {
             return 1;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
index d3b4c19..cea3ac2 100755
--- a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
+++ b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
@@ -17,16 +17,20 @@
 package com.cloud.utils.exception;
 
 import java.util.ArrayList;
+import java.util.List;
 
+import com.cloud.utils.Pair;
 import com.cloud.utils.SerialVersionUID;
 
 /**
  * wrap exceptions that you know there's no point in dealing with.
  */
-public class CloudRuntimeException extends RuntimeException {
+public class CloudRuntimeException extends RuntimeException implements ErrorContext {
 
     private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException;
 
+    protected ArrayList<Pair<Class<?>, String>> uuidList = new ArrayList<Pair<Class<?>,
String>>();
+
     // This holds a list of uuids and their descriptive names.
     protected ArrayList<ExceptionProxyObject> idList = new ArrayList<ExceptionProxyObject>();
 
@@ -66,14 +70,25 @@ public class CloudRuntimeException extends RuntimeException {
     }
 
     public void setCSErrorCode(int cserrcode) {
-        this.csErrorCode = cserrcode;
+        csErrorCode = cserrcode;
     }
 
     public int getCSErrorCode() {
-        return this.csErrorCode;
+        return csErrorCode;
     }
 
     public CloudRuntimeException(Throwable t) {
         super(t);
     }
+
+    @Override
+    public CloudRuntimeException add(Class<?> entity, String uuid) {
+        uuidList.add(new Pair<Class<?>, String>(entity, uuid));
+        return this;
+    }
+
+    @Override
+    public List<Pair<Class<?>, String>> getEntitiesInError() {
+        return uuidList;
+    }
 }


Mime
View raw message