@Test public void testFailure() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { UserVmService userVmService = Mockito.mock(UserVmService.class); updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class); Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(null); updateVmNicIpCmd._userVmService = userVmService; updateVmNicIpCmd._responseGenerator = responseGenerator; try { updateVmNicIpCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to update ip address on vm NIC. Refer to server logs for details.", exception.getDescription()); } }
@Test public void testCreateFailure() { RegionService regionService = Mockito.mock(RegionService.class); Region region = Mockito.mock(Region.class); Mockito.when(regionService.addRegion(Matchers.anyInt(), Matchers.anyString(), Matchers.anyString())).thenReturn(null); addRegionCmd._regionService = regionService; try { addRegionCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add Region", 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 testExecuteForEmptyCfgName() { updateCfgCmd._configService = configService; try { updateCfgCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Empty configuration name provided", exception.getDescription()); } }
@Test public void testExecuteForEmptyResult() { addHostCmd._resourceService = resourceService; try { addHostCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add host", exception.getDescription()); } }
} catch (final ServerApiException se) { final String responseText = getSerializedApiError(se, parameterMap, responseType); writeResponse(response, responseText, se.getErrorCode().getHttpCode(), responseType, se.getDescription()); sb.append(" " + se.getErrorCode() + " " + se.getDescription()); } catch (final RuntimeException e) {
@Test public void testCreateFailure() { UserVmService userVmService = Mockito.mock(UserVmService.class); try { Mockito.when(userVmService.upgradeVirtualMachine(scaleVMCmd)).thenReturn(null); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } scaleVMCmd._userVmService = userVmService; try { scaleVMCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to scale vm", exception.getDescription()); } } }
@Test public void testExecuteForNullResult() throws Exception { StorageService resourceService = Mockito.mock(StorageService.class); addImageStoreCmd._storageService = resourceService; Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)anyObject())) .thenReturn(null); try { addImageStoreCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add secondary storage", exception.getDescription()); } }
@Test public void testCreateFailure() { AccountService accountService = Mockito.mock(AccountService.class); Account account = Mockito.mock(Account.class); Mockito.when(accountService.getAccount(Matchers.anyLong())).thenReturn(account); addVpnUserCmd._accountService = accountService; RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class); Mockito.when(ravService.addVpnUser(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(null); addVpnUserCmd._ravService = ravService; try { addVpnUserCmd.create(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add vpn user", exception.getDescription()); } }
@Test public void testExecuteForEmptyResult() { updateCfgCmd._configService = configService; updateCfgCmd.setCfgName("some.cfg"); try { updateCfgCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to update config", exception.getDescription()); } }
@Test public void testCreateProviderToPhysicalNetworkFailure() throws ResourceAllocationException { NetworkService networkService = Mockito.mock(NetworkService.class); addNetworkServiceProviderCmd._networkService = networkService; Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(null); try { addNetworkServiceProviderCmd.create(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add service provider entity to physical network", exception.getDescription()); } }
@Test public void testExecuteForRestrictedCfg() { updateCfgCmd._configService = configService; updateCfgCmd.setCfgName(RoleService.EnableDynamicApiChecker.key()); try { updateCfgCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Restricted configuration update not allowed", exception.getDescription()); } }
@Test public void testExecuteForNullResult() { updateCfgCmd._configService = configService; updateCfgCmd.setCfgName("some.cfg"); try { Mockito.when(configService.updateConfiguration(updateCfgCmd)).thenReturn(null); } catch (InvalidParameterValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { updateCfgCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to update config", exception.getDescription()); } }
@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()); } }
@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 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()); } }
apiResponse.setErrorText(ex.getDescription()); apiResponse.setResponseName(responseName); final ArrayList<ExceptionProxyObject> idList = ex.getIdProxyList();
@Test public void testCreateSuccess() { updateHostPasswordCmd._mgr = managementServer; updateHostPasswordCmd._resourceService = resourceService; updateHostPasswordCmd._responseGenerator = responseGenerator; try { Mockito.when(managementServer.updateHostPassword(updateHostPasswordCmd)).thenReturn(true); } catch (final Exception e) { fail("Received exception when success expected " + e.getMessage()); } try { updateHostPasswordCmd.execute(); } catch (final ServerApiException exception) { assertEquals("Failed to update config", exception.getDescription()); } assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost()); verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd); } }
@Test public void testCreateFailure() { AccountService accountService = Mockito.mock(AccountService.class); Account account = Mockito.mock(Account.class); Mockito.when(accountService.getAccount(anyLong())).thenReturn(account); VolumeApiService volumeApiService = Mockito.mock(VolumeApiService.class); try { Mockito.when(volumeApiService.takeSnapshot(anyLong(), anyLong(), anyLong(), any(Account.class), anyBoolean(), isNull(Snapshot.LocationType.class), anyBoolean())).thenReturn(null); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } createSnapshotCmd._accountService = accountService; createSnapshotCmd._volumeService = volumeApiService; try { createSnapshotCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to create snapshot due to an internal error creating snapshot for volume 1", exception.getDescription()); } } }
@Test public void testExecuteForNullResult() { updateHostPasswordCmd._mgr = managementServer; updateHostPasswordCmd._resourceService = resourceService; try { Mockito.when(managementServer.updateHostPassword(updateHostPasswordCmd)).thenReturn(false); } catch (final InvalidParameterValueException e) { fail(e.getMessage()); } catch (final IllegalArgumentException e) { fail(e.getMessage()); } try { updateHostPasswordCmd.execute(); } catch (final ServerApiException exception) { Assert.assertEquals("Failed to update config", exception.getDescription()); } assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost()); verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd); }