incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chipchild...@apache.org
Subject [2/5] Reworked the formatting and structure of the api project's unit tests. Signed-off-by: Chip Childers <chip.childers@gmail.com>
Date Wed, 21 Nov 2012 14:57:47 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b1c06329/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
index 1b08a6e..fb8bfeb 100644
--- a/api/test/src/com/cloud/api/commands/test/ActivateProjectCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/ActivateProjectCmdTest.java
@@ -25,62 +25,63 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
-import com.cloud.api.ResponseGenerator;
-import com.cloud.api.response.ProjectResponse;
+import com.cloud.api.commands.ActivateProjectCmd;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.projects.Project;
 import com.cloud.projects.ProjectService;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 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());
-		
-	}
-	
+
+    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/b1c06329/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
index 9b28327..9b1606e 100644
--- a/api/test/src/com/cloud/api/commands/test/AddAccountToProjectCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/AddAccountToProjectCmdTest.java
@@ -29,147 +29,147 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.projects.Project;
 import com.cloud.projects.ProjectService;
 import com.cloud.user.Account;
+import com.cloud.api.commands.AddAccountToProjectCmd;
 
 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 "customer@abc.com";
-			        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);
-		
-	}*/
-	
-	/***
+    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 "customer@abc.com";
+                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());
-		}
-		
-	}*/
-
-	
-	
+
+    /*
+     * @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/b1c06329/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
index a5afbd5..933eef5 100644
--- a/api/test/src/com/cloud/api/commands/test/AddClusterCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/AddClusterCmdTest.java
@@ -27,7 +27,7 @@ import org.mockito.Mockito;
 
 import com.cloud.api.ResponseGenerator;
 import com.cloud.api.ServerApiException;
-import com.cloud.api.response.ClusterResponse;
+import com.cloud.api.commands.AddClusterCmd;
 import com.cloud.exception.DiscoveryException;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.org.Cluster;
@@ -36,88 +36,85 @@ 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();
-		
-		
-	}
-		
-}
 
- 
+    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/b1c06329/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
index cd8056c..476d1be 100644
--- a/api/test/src/com/cloud/api/commands/test/AddHostCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/AddHostCmdTest.java
@@ -16,11 +16,6 @@
 // under the License.
 package src.com.cloud.api.commands.test;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
@@ -32,138 +27,139 @@ import org.mockito.Mockito;
 
 import com.cloud.api.ResponseGenerator;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.commands.AddHostCmd;
 import com.cloud.api.response.HostResponse;
 import com.cloud.api.response.ListResponse;
 import com.cloud.exception.DiscoveryException;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.host.Host;
-import com.cloud.host.Status;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.resource.ResourceService;
-import com.cloud.resource.ResourceState;
 
 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;
+
+    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());
-		}
-		
-	}
-	
-	
+        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/b1c06329/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
index ab8e848..d4c5e61 100644
--- a/api/test/src/com/cloud/api/commands/test/AddNetworkServiceProviderCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/AddNetworkServiceProviderCmdTest.java
@@ -29,90 +29,94 @@ import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
 import com.cloud.api.ServerApiException;
+import com.cloud.api.commands.AddNetworkServiceProviderCmd;
 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());	
-		}
-		
-		
-	}
-	
-	
+    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/b1c06329/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
index 59f8367..fb5ec4b 100644
--- a/api/test/src/com/cloud/api/commands/test/AddSecondaryStorageCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/AddSecondaryStorageCmdTest.java
@@ -27,10 +27,8 @@ import org.mockito.Mockito;
 
 import com.cloud.api.ResponseGenerator;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.commands.AddSecondaryStorageCmd;
 import com.cloud.api.response.HostResponse;
-import com.cloud.api.response.ListResponse;
-import com.cloud.exception.DiscoveryException;
-import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.host.Host;
 import com.cloud.resource.ResourceService;
 
@@ -38,83 +36,89 @@ 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());
-			}
-		
-		
-	}
-	
+    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/b1c06329/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
index 3624c4b..b5376b3 100644
--- a/api/test/src/com/cloud/api/commands/test/AddSwiftCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/AddSwiftCmdTest.java
@@ -16,6 +16,9 @@
 // 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;
@@ -24,69 +27,71 @@ import org.mockito.Mockito;
 
 import com.cloud.api.ResponseGenerator;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.commands.AddSwiftCmd;
 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());
-		}
-		
-	}
-	
+    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/b1c06329/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
index e8f2b01..63d1e2b 100644
--- a/api/test/src/com/cloud/api/commands/test/AddVpnUserCmdTest.java
+++ b/api/test/src/com/cloud/api/commands/test/AddVpnUserCmdTest.java
@@ -26,6 +26,7 @@ import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
 import com.cloud.api.ServerApiException;
+import com.cloud.api.commands.AddVpnUserCmd;
 import com.cloud.network.VpnUser;
 import com.cloud.network.vpn.RemoteAccessVpnService;
 import com.cloud.user.Account;
@@ -33,111 +34,115 @@ 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());
-		}		
-		
-	}
-	
+    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());
+        }
+
+    }
+
 }


Mime
View raw message