You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2012/11/21 15:57:47 UTC
[5/5] Moving api tests into a similar package structure as other tests
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e953b774/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
new file mode 100644
index 0000000..3624c4b
--- /dev/null
+++ b/api/test/src/com/cloud/api/commands/test/AddSwiftCmdTest.java
@@ -0,0 +1,92 @@
+// 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 org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+
+import com.cloud.api.ResponseGenerator;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.SwiftResponse;
+import com.cloud.exception.DiscoveryException;
+import com.cloud.resource.ResourceService;
+import com.cloud.storage.Swift;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+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/e953b774/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
new file mode 100644
index 0000000..e8f2b01
--- /dev/null
+++ b/api/test/src/com/cloud/api/commands/test/AddVpnUserCmdTest.java
@@ -0,0 +1,143 @@
+// 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.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+
+import com.cloud.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());
+ }
+
+ }
+
+}