You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2013/04/15 15:10:11 UTC

[12/50] [abbrv] git commit: updated refs/heads/cisco-vnmc-api-integration to 7ce45ea

Reopening CLOUDSTACK-1884. Adding back the unit test, but still excluded due to component loading issue.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4958070b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4958070b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4958070b

Branch: refs/heads/cisco-vnmc-api-integration
Commit: 4958070b90bc153d55d0201776a4d1c4579dc707
Parents: 4600bd4
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Apr 11 15:43:12 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 15:43:54 2013 -0700

----------------------------------------------------------------------
 server/pom.xml                                     |    1 +
 .../cloudstack/affinity/AffinityApiUnitTest.java   |  154 ++++++++-------
 2 files changed, 81 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4958070b/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index a397195..a4f315b 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -160,6 +160,7 @@
             <exclude>com/cloud/network/security/SecurityGroupManagerImpl2Test.java</exclude>
             <!-- see CLOUDSTACK-1884 -->
             <exclude>org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java</exclude>
+            <exclude>org/apache/cloudstack/affinity/AffinityApiUnitTest.java</exclude>
           </excludes>
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4958070b/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 ee241de..a044611 100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
@@ -31,6 +31,7 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 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;
 
@@ -94,86 +95,91 @@ public class AffinityApiUnitTest {
 
     @Before
     public void testSetUp() {
-        // 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);
-         *
-         * when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(),
-         * anyLong(), anyLong())).thenReturn(acct);
-         * when(_processor.getType()).thenReturn("mock");
-         * when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
-         */
+        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);
+
+        when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
+        when(_processor.getType()).thenReturn("mock");
+        when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
+
+        AffinityGroupVO group = new AffinityGroupVO("group1", "mock", "mock group", domainId, 200L);
+        Mockito.when(_affinityGroupDao.persist(Mockito.any(AffinityGroupVO.class))).thenReturn(group);
+        Mockito.when(_affinityGroupDao.findById(Mockito.anyLong())).thenReturn(group);
+        Mockito.when(_affinityGroupDao.findByAccountAndName(Mockito.anyLong(), Mockito.anyString())).thenReturn(group);
+        Mockito.when(_affinityGroupDao.lockRow(Mockito.anyLong(), anyBoolean())).thenReturn(group);
+        Mockito.when(_affinityGroupDao.expunge(Mockito.anyLong())).thenReturn(true);
     }
 
     @Test
     public void createAffinityGroupTest() {
-        /*
-         * AffinityGroup group = _affinityService.createAffinityGroup("user",
-         * domainId, "group1", "mock", "affinity group one");
-         * assertNotNull("Affinity group 'group1' of type 'mock' failed to create "
-         * , group);
-         */
+        AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "mock",
+                "affinity group one");
+        assertNotNull("Affinity group 'group1' of type 'mock' failed to create ", group);
 
     }
 
-    /*
-     * @Test(expected = InvalidParameterValueException.class) public void
-     * invalidAffinityTypeTest() { AffinityGroup group =
-     * _affinityService.createAffinityGroup("user", domainId, "group1",
-     * "invalid", "affinity group one");
-     *
-     * }
-     *
-     * @Test(expected = InvalidParameterValueException.class) public void
-     * uniqueAffinityNameTest() { when(_groupDao.isNameInUse(anyLong(),
-     * anyLong(), eq("group1"))).thenReturn(true); AffinityGroup group2 =
-     * _affinityService.createAffinityGroup("user", domainId, "group1", "mock",
-     * "affinity group two"); }
-     *
-     * @Test(expected = InvalidParameterValueException.class) public void
-     * deleteAffinityGroupInvalidIdTest() throws ResourceInUseException {
-     * when(_groupDao.findById(20L)).thenReturn(null);
-     * _affinityService.deleteAffinityGroup(20L, "user", domainId, "group1"); }
-     *
-     * @Test(expected = InvalidParameterValueException.class) public void
-     * deleteAffinityGroupInvalidIdName() throws ResourceInUseException {
-     * when(_groupDao.findByAccountAndName(200L, "group1")).thenReturn(null);
-     * _affinityService.deleteAffinityGroup(null, "user", domainId, "group1"); }
-     *
-     * @Test(expected = InvalidParameterValueException.class) public void
-     * deleteAffinityGroupNullIdName() throws ResourceInUseException {
-     * _affinityService.deleteAffinityGroup(null, "user", domainId, null); }
-     *
-     * @Test(expected = ResourceInUseException.class) public void
-     * deleteAffinityGroupInUse() throws ResourceInUseException {
-     * List<AffinityGroupVMMapVO> affinityGroupVmMap = new
-     * ArrayList<AffinityGroupVMMapVO>(); AffinityGroupVMMapVO mapVO = new
-     * AffinityGroupVMMapVO(20L, 10L); affinityGroupVmMap.add(mapVO);
-     * when(_affinityGroupVMMapDao
-     * .listByAffinityGroup(20L)).thenReturn(affinityGroupVmMap);
-     *
-     * AffinityGroupVO groupVO = new AffinityGroupVO();
-     * when(_groupDao.findById(20L)).thenReturn(groupVO);
-     * when(_groupDao.lockRow(20L, true)).thenReturn(groupVO);
-     *
-     * _affinityService.deleteAffinityGroup(20L, "user", domainId, null); }
-     *
-     * @Test(expected = InvalidParameterValueException.class) public void
-     * updateAffinityGroupVMRunning() throws ResourceInUseException {
-     *
-     * UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any,
-     * 21L, false, false, domainId, 200L, 5L, "", "test", 1L);
-     * vm.setState(VirtualMachine.State.Running);
-     * when(_vmDao.findById(10L)).thenReturn(vm);
-     *
-     * List<Long> affinityGroupIds = new ArrayList<Long>();
-     * affinityGroupIds.add(20L);
-     *
-     * _affinityService.updateVMAffinityGroups(10L, affinityGroupIds); }
-     */
+    @Test(expected = InvalidParameterValueException.class)
+    public void invalidAffinityTypeTest() {
+        AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "invalid",
+                "affinity group one");
+
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void uniqueAffinityNameTest() {
+        when(_groupDao.isNameInUse(anyLong(), anyLong(), eq("group1"))).thenReturn(true);
+        AffinityGroup group2 = _affinityService.createAffinityGroup("user", domainId, "group1", "mock",
+                "affinity group two");
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void deleteAffinityGroupInvalidIdTest() throws ResourceInUseException {
+        when(_groupDao.findById(20L)).thenReturn(null);
+        _affinityService.deleteAffinityGroup(20L, "user", domainId, "group1");
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void deleteAffinityGroupInvalidIdName() throws ResourceInUseException {
+        when(_groupDao.findByAccountAndName(200L, "group1")).thenReturn(null);
+        _affinityService.deleteAffinityGroup(null, "user", domainId, "group1");
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void deleteAffinityGroupNullIdName() throws ResourceInUseException {
+        _affinityService.deleteAffinityGroup(null, "user", domainId, null);
+    }
+
+    @Test(expected = ResourceInUseException.class)
+    public void deleteAffinityGroupInUse() throws ResourceInUseException {
+        List<AffinityGroupVMMapVO> affinityGroupVmMap = new ArrayList<AffinityGroupVMMapVO>();
+        AffinityGroupVMMapVO mapVO = new AffinityGroupVMMapVO(20L, 10L);
+        affinityGroupVmMap.add(mapVO);
+        when(_affinityGroupVMMapDao.listByAffinityGroup(20L)).thenReturn(affinityGroupVmMap);
+
+        AffinityGroupVO groupVO = new AffinityGroupVO();
+        when(_groupDao.findById(20L)).thenReturn(groupVO);
+        when(_groupDao.lockRow(20L, true)).thenReturn(groupVO);
+
+        _affinityService.deleteAffinityGroup(20L, "user", domainId, null);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void updateAffinityGroupVMRunning() throws ResourceInUseException {
+
+        UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, domainId, 200L,
+                5L, "", "test", 1L);
+        vm.setState(VirtualMachine.State.Running);
+        when(_vmDao.findById(10L)).thenReturn(vm);
+
+        List<Long> affinityGroupIds = new ArrayList<Long>();
+        affinityGroupIds.add(20L);
+
+        _affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
+    }
 
 }