http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/agent/api/test/SnapshotCommandTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/agent/api/test/SnapshotCommandTest.java b/api/test/src/com/cloud/agent/api/test/SnapshotCommandTest.java deleted file mode 100644 index 98cdee2..0000000 --- a/api/test/src/com/cloud/agent/api/test/SnapshotCommandTest.java +++ /dev/null @@ -1,197 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.agent.api.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import com.cloud.agent.api.SnapshotCommand; -import com.cloud.storage.Storage.StoragePoolType; -import com.cloud.storage.StoragePool; -import com.cloud.storage.StoragePoolStatus; - -public class SnapshotCommandTest { - - public StoragePool pool = new StoragePool() { - public long getId() { - return 1L; - }; - - public String getName() { - return "name"; - }; - - public String getUuid() { - return "bed9f83e-cac3-11e1-ac8a-0050568b007e"; - }; - - public StoragePoolType getPoolType() { - return StoragePoolType.Filesystem; - }; - - public Date getCreated() { - Date date = null; - try { - date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") - .parse("01/01/1970 12:12:12"); - } catch (ParseException e) { - e.printStackTrace(); - } - return date; - } - - public Date getUpdateTime() { - return new Date(); - }; - - public long getDataCenterId() { - return 0L; - }; - - public long getCapacityBytes() { - return 0L; - }; - - public long getAvailableBytes() { - return 0L; - }; - - public Long getClusterId() { - return 0L; - }; - - public String getHostAddress() { - return "hostAddress"; - }; - - public String getPath() { - return "path"; - }; - - public String getUserInfo() { - return "userInfo"; - }; - - public boolean isShared() { - return false; - }; - - public boolean isLocal() { - return false; - }; - - public StoragePoolStatus getStatus() { - return StoragePoolStatus.Up; - }; - - public int getPort() { - return 25; - }; - - public Long getPodId() { - return 0L; - }; - }; - - SnapshotCommand ssc = new SnapshotCommand(pool, - "http://secondary.Storage.Url", - "420fa39c-4ef1-a83c-fd93-46dc1ff515ae", "snapshotName", 101L, 102L, - 103L); - - SnapshotCommand ssc1; - - - @Before - public void setUp() { - ssc1 = new SnapshotCommand(pool, - "secondaryStorageUrl", "snapshotUuid", "snapshotName", 101L, - 102L, 103L); - } - - @Test - public void testGetPrimaryStoragePoolNameLabel() { - String label = ssc.getPrimaryStoragePoolNameLabel(); - assertTrue(label.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e")); - } - - @Test - public void testGetSecondaryStorageUrl() { - String url = ssc.getSecondaryStorageUrl(); - assertTrue(url.equals("http://secondary.Storage.Url")); - } - - @Test - public void testGetSnapshotUuid() { - String uuid = ssc.getSnapshotUuid(); - assertTrue(uuid.equals("420fa39c-4ef1-a83c-fd93-46dc1ff515ae")); - } - - @Test - public void testGetSnapshotName() { - String name = ssc.getSnapshotName(); - assertTrue(name.equals("snapshotName")); - } - - @Test - public void testGetVolumePath() { - ssc.setVolumePath("vPath"); - String path = ssc.getVolumePath(); - assertTrue(path.equals("vPath")); - - ssc1.setVolumePath("vPath1"); - path = ssc1.getVolumePath(); - assertTrue(path.equals("vPath1")); - } - - @Test - public void testExecuteInSequence() { - boolean b = ssc.executeInSequence(); - assertFalse(b); - - b = ssc1.executeInSequence(); - assertFalse(b); - } - - @Test - public void testGetDataCenterId() { - Long dcId = ssc.getDataCenterId(); - Long expected = 101L; - assertEquals(expected, dcId); - } - - @Test - public void testGetAccountId() { - Long aId = ssc.getAccountId(); - Long expected = 102L; - assertEquals(expected, aId); - } - - @Test - public void testGetVolumeId() { - Long vId = ssc.getVolumeId(); - Long expected = 103L; - assertEquals(expected, vId); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/ActivateProjectCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/ActivateProjectCmdTest.java b/api/test/src/com/cloud/api/commands/test/ActivateProjectCmdTest.java deleted file mode 100644 index 073c1aa..0000000 --- a/api/test/src/com/cloud/api/commands/test/ActivateProjectCmdTest.java +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.user.project.ActivateProjectCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.projects.Project; -import com.cloud.projects.ProjectService; -import com.cloud.user.Account; - -public class ActivateProjectCmdTest extends TestCase { - - private ActivateProjectCmd activateProjectCmd; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - - activateProjectCmd = new ActivateProjectCmd() { - - @Override - public Long getId() { - return 2L; - } - - }; - } - - @Test - public void testGetEntityOwnerIdForNullProject() { - ProjectService projectService = Mockito.mock(ProjectService.class); - Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn( - null); - activateProjectCmd._projectService = projectService; - - try { - activateProjectCmd.getEntityOwnerId(); - } catch (InvalidParameterValueException exception) { - Assert.assertEquals("Unable to find project by id 2", - exception.getLocalizedMessage()); - } - } - - @Test - public void testGetEntityOwnerIdForProject() { - Project project = Mockito.mock(Project.class); - Mockito.when(project.getId()).thenReturn(2L); - ProjectService projectService = Mockito.mock(ProjectService.class); - Account account = Mockito.mock(Account.class); - Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn( - project); - - Mockito.when(projectService.getProjectOwner(Mockito.anyLong())) - .thenReturn(account); - activateProjectCmd._projectService = projectService; - - Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId()); - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/AddAccountToProjectCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/AddAccountToProjectCmdTest.java b/api/test/src/com/cloud/api/commands/test/AddAccountToProjectCmdTest.java deleted file mode 100644 index 736656f..0000000 --- a/api/test/src/com/cloud/api/commands/test/AddAccountToProjectCmdTest.java +++ /dev/null @@ -1,175 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.user.account.AddAccountToProjectCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.projects.Project; -import com.cloud.projects.ProjectService; -import com.cloud.user.Account; - -public class AddAccountToProjectCmdTest extends TestCase { - - private AddAccountToProjectCmd addAccountToProjectCmd; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - addAccountToProjectCmd = new AddAccountToProjectCmd() { - - @Override - public Long getProjectId() { - return 2L; - } - - @Override - public String getAccountName() { - - // to run the test testGetEventDescriptionForAccount set the - // accountName - // return "accountName"; - // to run the test the testGetEventDescriptionForNullAccount - // return accountname as null - return null; - } - - @Override - public String getEmail() { - // return "[email protected]"; - return null; - } - - }; - } - - /**** - * Condition not handled in the code - * - *****/ - - /* - * @Test public void testGetEntityOwnerIdForNullProject() { - * - * ProjectService projectService = Mockito.mock(ProjectService.class); - * Mockito - * .when(projectService.getProject(Mockito.anyLong())).thenReturn(null); - * addAccountToProjectCmd._projectService = projectService; - * - * try { addAccountToProjectCmd.getEntityOwnerId(); } - * catch(InvalidParameterValueException exception) { - * Assert.assertEquals("Unable to find project by id 2", - * exception.getLocalizedMessage()); } - * - * } - */ - - @Test - public void testGetEntityOwnerIdForProject() { - - Project project = Mockito.mock(Project.class); - Mockito.when(project.getId()).thenReturn(2L); - - ProjectService projectService = Mockito.mock(ProjectService.class); - Account account = Mockito.mock(Account.class); - - Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn( - project); - - Mockito.when(projectService.getProjectOwner(Mockito.anyLong())) - .thenReturn(account); - addAccountToProjectCmd._projectService = projectService; - - Assert.assertEquals(2L, addAccountToProjectCmd.getEntityOwnerId()); - - } - - /** - * To run the test uncomment the return statement for getAccountName() in - * setup() and return null - * - * **/ - - /* - * @Test public void testGetEventDescriptionForNullAccount() { - * - * String result = addAccountToProjectCmd.getEventDescription(); String - * expected = "Sending invitation to email null to join project: 2"; - * Assert.assertEquals(expected, result); - * - * } - */ - - /*** - * - * - * - * ***/ - - /* - * @Test public void testGetEventDescriptionForAccount() { - * - * String result = addAccountToProjectCmd.getEventDescription(); String - * expected = "Adding account accountName to project: 2"; - * Assert.assertEquals(expected, result); - * - * } - */ - - @Test - public void testExecuteForNullAccountNameEmail() { - - try { - addAccountToProjectCmd.execute(); - } catch (InvalidParameterValueException exception) { - Assert.assertEquals("Either accountName or email is required", - exception.getLocalizedMessage()); - } - - } - - /* - * @Test public void testExecuteForAccountNameEmail() { - * - * try { - * - * ComponentLocator c = Mockito.mock(ComponentLocator.class); UserContext - * userContext = Mockito.mock(UserContext.class); - * - * // Mockito.when(userContext.current()).thenReturn(userContext); - * - * - * addAccountToProjectCmd.execute(); } catch(InvalidParameterValueException - * exception) { - * Assert.assertEquals("Either accountName or email is required", - * exception.getLocalizedMessage()); } - * - * } - */ - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/AddClusterCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/AddClusterCmdTest.java b/api/test/src/com/cloud/api/commands/test/AddClusterCmdTest.java deleted file mode 100644 index 3b546e3..0000000 --- a/api/test/src/com/cloud/api/commands/test/AddClusterCmdTest.java +++ /dev/null @@ -1,120 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.apache.cloudstack.api.ResponseGenerator; -import org.apache.cloudstack.api.ServerApiException; -import com.cloud.exception.DiscoveryException; -import com.cloud.exception.ResourceInUseException; -import com.cloud.org.Cluster; -import com.cloud.resource.ResourceService; - -import edu.emory.mathcs.backport.java.util.Arrays; - -public class AddClusterCmdTest extends TestCase { - - private AddClusterCmd addClusterCmd; - private ResourceService resourceService; - private ResponseGenerator responseGenerator; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - /* - * resourceService = Mockito.mock(ResourceService.class); - * responseGenerator = Mockito.mock(ResponseGenerator.class); - */addClusterCmd = new AddClusterCmd() { - }; - } - - @Test - public void testExecuteForNullResult() { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - - try { - Mockito.when(resourceService.discoverCluster(addClusterCmd)) - .thenReturn(null); - } catch (ResourceInUseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (DiscoveryException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - addClusterCmd._resourceService = resourceService; - - try { - addClusterCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add cluster", - exception.getDescription()); - } - - } - - @Test - public void testExecuteForEmptyResult() { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - addClusterCmd._resourceService = resourceService; - - try { - addClusterCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add cluster", - exception.getDescription()); - } - - } - - @Test - public void testExecuteForResult() throws Exception { - - resourceService = Mockito.mock(ResourceService.class); - responseGenerator = Mockito.mock(ResponseGenerator.class); - - addClusterCmd._resourceService = resourceService; - addClusterCmd._responseGenerator = responseGenerator; - - Cluster cluster = Mockito.mock(Cluster.class); - Cluster[] clusterArray = new Cluster[] { cluster }; - - Mockito.when(resourceService.discoverCluster(addClusterCmd)) - .thenReturn(Arrays.asList(clusterArray)); - - addClusterCmd.execute(); - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/AddHostCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/AddHostCmdTest.java b/api/test/src/com/cloud/api/commands/test/AddHostCmdTest.java deleted file mode 100644 index e4bfcdd..0000000 --- a/api/test/src/com/cloud/api/commands/test/AddHostCmdTest.java +++ /dev/null @@ -1,165 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.admin.host.AddHostCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.apache.cloudstack.api.ResponseGenerator; -import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.response.HostResponse; -import org.apache.cloudstack.api.response.ListResponse; -import com.cloud.exception.DiscoveryException; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.host.Host; -import com.cloud.resource.ResourceService; - -import edu.emory.mathcs.backport.java.util.Arrays; - -public class AddHostCmdTest extends TestCase { - - private AddHostCmd addHostCmd; - private ResourceService resourceService; - private ResponseGenerator responseGenerator; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - resourceService = Mockito.mock(ResourceService.class); - responseGenerator = Mockito.mock(ResponseGenerator.class); - addHostCmd = new AddHostCmd() { - }; - } - - @Test - public void testExecuteForEmptyResult() { - addHostCmd._resourceService = resourceService; - - try { - addHostCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add host", - exception.getDescription()); - } - - } - - @Test - public void testExecuteForNullResult() { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - addHostCmd._resourceService = resourceService; - - try { - Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn( - null); - } catch (InvalidParameterValueException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (DiscoveryException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - try { - addHostCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add host", - exception.getDescription()); - } - - } - - /* - * @Test public void testExecuteForResult() throws Exception { - * - * addHostCmd._resourceService = resourceService; - * addHostCmd._responseGenerator = responseGenerator; MockHost mockInstance - * = new MockHost(); MockHost[] mockArray = new MockHost[]{mockInstance}; - * HostResponse responseHost = new HostResponse(); - * responseHost.setName("Test"); - * Mockito.when(resourceService.discoverHosts(addHostCmd - * )).thenReturn(Arrays.asList(mockArray)); - * Mockito.when(responseGenerator.createHostResponse - * (mockInstance)).thenReturn(responseHost); addHostCmd.execute(); - * Mockito.verify(responseGenerator).createHostResponse(mockInstance); - * ListResponse<HostResponse> actualResponse = - * ((ListResponse<HostResponse>)addHostCmd.getResponseObject()); - * Assert.assertEquals(responseHost, actualResponse.getResponses().get(0)); - * Assert.assertEquals("addhostresponse", actualResponse.getResponseName()); - * } - */ - @Test - public void testExecuteForResult() throws Exception { - - addHostCmd._resourceService = resourceService; - addHostCmd._responseGenerator = responseGenerator; - Host host = Mockito.mock(Host.class); - Host[] mockArray = new Host[] { host }; - - HostResponse responseHost = new HostResponse(); - responseHost.setName("Test"); - Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn( - Arrays.asList(mockArray)); - Mockito.when(responseGenerator.createHostResponse(host)).thenReturn( - responseHost); - addHostCmd.execute(); - Mockito.verify(responseGenerator).createHostResponse(host); - ListResponse<HostResponse> actualResponse = ((ListResponse<HostResponse>) addHostCmd - .getResponseObject()); - Assert.assertEquals(responseHost, actualResponse.getResponses().get(0)); - Assert.assertEquals("addhostresponse", actualResponse.getResponseName()); - - } - - @Test - public void testExecuteForDiscoveryException() { - - addHostCmd._resourceService = resourceService; - - try { - Mockito.when(resourceService.discoverHosts(addHostCmd)).thenThrow( - DiscoveryException.class); - } catch (InvalidParameterValueException e) { - e.printStackTrace(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (DiscoveryException e) { - e.printStackTrace(); - } - - try { - addHostCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertNull(exception.getDescription()); - } - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/AddNetworkServiceProviderCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/AddNetworkServiceProviderCmdTest.java b/api/test/src/com/cloud/api/commands/test/AddNetworkServiceProviderCmdTest.java deleted file mode 100644 index 1a5ee43..0000000 --- a/api/test/src/com/cloud/api/commands/test/AddNetworkServiceProviderCmdTest.java +++ /dev/null @@ -1,122 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.admin.network.AddNetworkServiceProviderCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.apache.cloudstack.api.ServerApiException; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.network.NetworkService; -import com.cloud.network.PhysicalNetworkServiceProvider; - -public class AddNetworkServiceProviderCmdTest extends TestCase { - - private AddNetworkServiceProviderCmd addNetworkServiceProviderCmd; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - addNetworkServiceProviderCmd = new AddNetworkServiceProviderCmd() { - - @Override - public Long getPhysicalNetworkId() { - return 2L; - } - - @Override - public String getProviderName() { - return "ProviderName"; - } - - @Override - public Long getDestinationPhysicalNetworkId() { - return 2L; - } - - @Override - public List<String> getEnabledServices() { - List<String> lOfEnabledServices = new ArrayList<String>(); - lOfEnabledServices.add("Enabled Services"); - return lOfEnabledServices; - } - - public Long getEntityId() { - return 2L; - } - - }; - - } - - @Test - public void testCreateProviderToPhysicalNetworkSuccess() { - - NetworkService networkService = Mockito.mock(NetworkService.class); - addNetworkServiceProviderCmd._networkService = networkService; - - PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito - .mock(PhysicalNetworkServiceProvider.class); - Mockito.when( - networkService.addProviderToPhysicalNetwork(Mockito.anyLong(), - Mockito.anyString(), Mockito.anyLong(), - Mockito.anyList())).thenReturn( - physicalNetworkServiceProvider); - - try { - addNetworkServiceProviderCmd.create(); - } catch (ResourceAllocationException e) { - e.printStackTrace(); - } - - } - - @Test - public void testCreateProviderToPhysicalNetworkFailure() - throws ResourceAllocationException { - - NetworkService networkService = Mockito.mock(NetworkService.class); - addNetworkServiceProviderCmd._networkService = networkService; - - Mockito.when( - networkService.addProviderToPhysicalNetwork(Mockito.anyLong(), - Mockito.anyString(), Mockito.anyLong(), - Mockito.anyList())).thenReturn(null); - - try { - addNetworkServiceProviderCmd.create(); - } catch (ServerApiException exception) { - Assert.assertEquals( - "Failed to add service provider entity to physical network", - exception.getDescription()); - } - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/AddSecondaryStorageCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/AddSecondaryStorageCmdTest.java b/api/test/src/com/cloud/api/commands/test/AddSecondaryStorageCmdTest.java deleted file mode 100644 index 3a61315..0000000 --- a/api/test/src/com/cloud/api/commands/test/AddSecondaryStorageCmdTest.java +++ /dev/null @@ -1,124 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.apache.cloudstack.api.ResponseGenerator; -import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.response.HostResponse; -import com.cloud.host.Host; -import com.cloud.resource.ResourceService; - -import edu.emory.mathcs.backport.java.util.Arrays; - -public class AddSecondaryStorageCmdTest extends TestCase { - - private AddSecondaryStorageCmd addSecondaryStorageCmd; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - addSecondaryStorageCmd = new AddSecondaryStorageCmd() { - }; - - } - - @Test - public void testExecuteForResult() throws Exception { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - addSecondaryStorageCmd._resourceService = resourceService; - - Host host = Mockito.mock(Host.class); - Host[] mockHosts = new Host[] { host }; - - Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd)) - .thenReturn(Arrays.asList(mockHosts)); - - ResponseGenerator responseGenerator = Mockito - .mock(ResponseGenerator.class); - addSecondaryStorageCmd._responseGenerator = responseGenerator; - - HostResponse responseHost = new HostResponse(); - responseHost.setName("Test"); - - Mockito.when(responseGenerator.createHostResponse(host)).thenReturn( - responseHost); - - addSecondaryStorageCmd.execute(); - - Mockito.verify(responseGenerator).createHostResponse(host); - - HostResponse actualResponse = (HostResponse) addSecondaryStorageCmd - .getResponseObject(); - - Assert.assertEquals(responseHost, actualResponse); - Assert.assertEquals("addsecondarystorageresponse", - actualResponse.getResponseName()); - - } - - @Test - public void testExecuteForEmptyResult() throws Exception { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - addSecondaryStorageCmd._resourceService = resourceService; - - Host[] mockHosts = new Host[] {}; - - Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd)) - .thenReturn(Arrays.asList(mockHosts)); - - try { - addSecondaryStorageCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add secondary storage", - exception.getDescription()); - } - - } - - @Test - public void testExecuteForNullResult() throws Exception { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - addSecondaryStorageCmd._resourceService = resourceService; - - Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd)) - .thenReturn(null); - - try { - addSecondaryStorageCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add secondary storage", - exception.getDescription()); - } - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/AddSwiftCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/AddSwiftCmdTest.java b/api/test/src/com/cloud/api/commands/test/AddSwiftCmdTest.java deleted file mode 100644 index b5dfa88..0000000 --- a/api/test/src/com/cloud/api/commands/test/AddSwiftCmdTest.java +++ /dev/null @@ -1,97 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.apache.cloudstack.api.ResponseGenerator; -import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.response.SwiftResponse; -import com.cloud.exception.DiscoveryException; -import com.cloud.resource.ResourceService; -import com.cloud.storage.Swift; - -public class AddSwiftCmdTest extends TestCase { - - private AddSwiftCmd addSwiftCmd; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - addSwiftCmd = new AddSwiftCmd(); - } - - @Test - public void testExecuteSuccess() { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - addSwiftCmd._resourceService = resourceService; - - Swift swift = Mockito.mock(Swift.class); - - try { - Mockito.when(resourceService.discoverSwift(addSwiftCmd)) - .thenReturn(swift); - } catch (DiscoveryException e) { - e.printStackTrace(); - } - - ResponseGenerator responseGenerator = Mockito - .mock(ResponseGenerator.class); - addSwiftCmd._responseGenerator = responseGenerator; - - SwiftResponse swiftResponse = Mockito.mock(SwiftResponse.class); - - Mockito.when(responseGenerator.createSwiftResponse(swift)).thenReturn( - swiftResponse); - - addSwiftCmd.execute(); - - } - - @Test - public void testExecuteFailure() { - - ResourceService resourceService = Mockito.mock(ResourceService.class); - addSwiftCmd._resourceService = resourceService; - try { - Mockito.when(resourceService.discoverSwift(addSwiftCmd)) - .thenReturn(null); - } catch (DiscoveryException e) { - e.printStackTrace(); - } - - try { - addSwiftCmd.execute(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add Swift", - exception.getDescription()); - } - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5abc180/api/test/src/com/cloud/api/commands/test/AddVpnUserCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/src/com/cloud/api/commands/test/AddVpnUserCmdTest.java b/api/test/src/com/cloud/api/commands/test/AddVpnUserCmdTest.java deleted file mode 100644 index 11ef43e..0000000 --- a/api/test/src/com/cloud/api/commands/test/AddVpnUserCmdTest.java +++ /dev/null @@ -1,148 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// 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, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package src.com.cloud.api.commands.test; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.cloudstack.api.command.user.vpn.AddVpnUserCmd; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -import org.apache.cloudstack.api.ServerApiException; -import com.cloud.network.VpnUser; -import com.cloud.network.vpn.RemoteAccessVpnService; -import com.cloud.user.Account; -import com.cloud.user.AccountService; - -public class AddVpnUserCmdTest extends TestCase { - - private AddVpnUserCmd addVpnUserCmd; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() { - - addVpnUserCmd = new AddVpnUserCmd() { - - @Override - public Long getEntityId() { - return 2L; - } - - @Override - public long getEntityOwnerId() { - return 2L; - } - - @Override - public String getUserName() { - return "User Name"; - } - - @Override - public String getPassword() { - return "password"; - } - - }; - } - - /* - * @Test public void testExecuteVpnUserNotFound() { - * - * EntityManager entityManager = Mockito.mock(EntityManager.class); - * - * Mockito.when(entityManager.findById(VpnUser.class, - * Mockito.anyLong())).thenReturn(null); - * - * addVpnUserCmd._entityMgr = entityManager; try { addVpnUserCmd.execute(); - * } catch (Exception e) { } - * - * } - * - * - * @Test public void testExecuteVpnUserFound() { - * - * EntityManager entityManager = Mockito.mock(EntityManager.class); - * addVpnUserCmd._entityMgr = entityManager; - * - * VpnUser vpnUser = Mockito.mock(VpnUser.class); - * Mockito.when(entityManager.findById(VpnUser.class, - * Mockito.anyLong())).thenReturn(vpnUser); addVpnUserCmd.execute(); - * - * } - */ - - @Test - public void testCreateSuccess() { - - AccountService accountService = Mockito.mock(AccountService.class); - - Account account = Mockito.mock(Account.class); - Mockito.when(accountService.getAccount(Mockito.anyLong())).thenReturn( - account); - - addVpnUserCmd._accountService = accountService; - - RemoteAccessVpnService ravService = Mockito - .mock(RemoteAccessVpnService.class); - - VpnUser vpnUser = Mockito.mock(VpnUser.class); - Mockito.when( - ravService.addVpnUser(Mockito.anyLong(), Mockito.anyString(), - Mockito.anyString())).thenReturn(vpnUser); - - addVpnUserCmd._ravService = ravService; - - addVpnUserCmd.create(); - - } - - @Test - public void testCreateFailure() { - - AccountService accountService = Mockito.mock(AccountService.class); - Account account = Mockito.mock(Account.class); - Mockito.when(accountService.getAccount(Mockito.anyLong())).thenReturn( - account); - - addVpnUserCmd._accountService = accountService; - - RemoteAccessVpnService ravService = Mockito - .mock(RemoteAccessVpnService.class); - Mockito.when( - ravService.addVpnUser(Mockito.anyLong(), Mockito.anyString(), - Mockito.anyString())).thenReturn(null); - - addVpnUserCmd._ravService = ravService; - - try { - addVpnUserCmd.create(); - } catch (ServerApiException exception) { - Assert.assertEquals("Failed to add vpn user", - exception.getDescription()); - } - - } - -}
