} 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 testZoneidListMoreThanMinusOne() throws ResourceAllocationException { try { registerTemplateCmdByAdmin = new RegisterTemplateCmdByAdmin(); registerTemplateCmdByAdmin.zoneIds = new ArrayList<>(); registerTemplateCmdByAdmin.zoneIds.add(-1L); registerTemplateCmdByAdmin.zoneIds.add(1L); registerTemplateCmdByAdmin.execute(); } catch (ServerApiException e) { if (e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Parameter zoneids cannot combine all zones (-1) option with other zones"); } } } @Test
@Test public void testZoneidListMoreThanMinusOne() throws ResourceAllocationException { try { registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.zoneIds = new ArrayList<>(); registerTemplateCmd.zoneIds.add(-1L); registerTemplateCmd.zoneIds.add(1L); registerTemplateCmd.execute(); } catch (ServerApiException e) { if (e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Parameter zoneids cannot combine all zones (-1) option with other zones"); } } } @Test
@Test public void testZoneidAndZoneIdListBothPresent() throws ResourceAllocationException { try { registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.zoneId = -1L; registerTemplateCmd.zoneIds = new ArrayList<>(); registerTemplateCmd.zoneIds.add(-1L); registerTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both zoneid and zoneids are passed"); } } }
@Test public void testDestZoneidAndDestZoneIdListBothPresent() throws ResourceAllocationException { try { copyTemplateCmdByAdmin = new CopyTemplateCmdByAdmin(); copyTemplateCmdByAdmin.destZoneId = -1L; copyTemplateCmdByAdmin.destZoneIds = new ArrayList<>(); copyTemplateCmdByAdmin.destZoneIds.add(-1L); copyTemplateCmdByAdmin.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both destzoneid and destzoneids are passed"); } } }
@Test public void testZoneidAndZoneIdListBothPresent() throws ResourceAllocationException { try { registerTemplateCmdByAdmin = new RegisterTemplateCmdByAdmin(); registerTemplateCmdByAdmin.zoneId = -1L; registerTemplateCmdByAdmin.zoneIds = new ArrayList<>(); registerTemplateCmdByAdmin.zoneIds.add(-1L); registerTemplateCmdByAdmin.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both zoneid and zoneids are passed"); } } }
@Test public void testDestZoneidAndDestZoneIdListBothPresent() throws ResourceAllocationException { try { copyTemplateCmd = new CopyTemplateCmd(); copyTemplateCmd.destZoneId = -1L; copyTemplateCmd.destZoneIds = new ArrayList<>(); copyTemplateCmd.destZoneIds.add(-1L); copyTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both destzoneid and destzoneids are passed"); } } }
httpResponseCode = e.getErrorCode().getHttpCode(); responseString = e.getMessage(); s_logger.debug("Authentication failure: " + e.getMessage()); final String serializedResponseText = apiServer.getSerializedApiError(se, params, responseType); resp.setHeader("X-Description", se.getDescription()); HttpUtils.writeHttpResponse(resp, serializedResponseText, se.getErrorCode().getHttpCode(), responseType, ApiServer.JSONcontentType.value()); auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription()); } catch (final Exception ex) { s_logger.error("unknown exception writing api response", ex);
if (ex.getErrorCode() == ApiErrorCode.UNSUPPORTED_ACTION_ERROR || apiCommandParams == null || apiCommandParams.isEmpty()) { responseName = "errorresponse"; } else { apiResponse.setErrorCode(ex.getErrorCode().getHttpCode()); apiResponse.setErrorText(ex.getDescription()); apiResponse.setResponseName(responseName);
@Test public void testZoneidAndZoneIdListEmpty() throws ResourceAllocationException { try { copyTemplateCmd = new CopyTemplateCmd(); copyTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("API should fail when no parameters are passed."); } } }
@Test public void testZoneidAndZoneIdListEmpty() throws ResourceAllocationException { try { registerTemplateCmdByAdmin = new RegisterTemplateCmdByAdmin(); registerTemplateCmdByAdmin.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both zoneid and zoneids aren't passed"); } } }
@Test public void testZoneidAndZoneIdListEmpty() throws ResourceAllocationException { try { registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both zoneid and zoneids aren't passed"); } } }
@Test public void testZoneidAndZoneIdListEmpty() throws ResourceAllocationException { try { copyTemplateCmdByAdmin = new CopyTemplateCmdByAdmin(); copyTemplateCmdByAdmin.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("API should fail when no parameters are passed."); } } }
ServerApiException sApiEx = (ServerApiException)e; errorMsg = sApiEx.getDescription(); errorCode = sApiEx.getErrorCode().getHttpCode();
@Test public void testExecuteWithEmptyPassword() { ReflectionTestUtils.setField(createAccountCmd, "password", ""); try { createAccountCmd.execute(); Assert.fail("should throw exception for a empty password"); } catch (ServerApiException e) { Assert.assertEquals(ApiErrorCode.PARAM_ERROR, e.getErrorCode()); Assert.assertEquals("Empty passwords are not allowed", e.getMessage()); } Mockito.verify(accountService, Mockito.never()).createUserAccount(null, null, null, null, null, null, null, accountType, roleId, domainId, null, null, null, null); } }
@Test public void testExecuteWithNullPassword() { ReflectionTestUtils.setField(createAccountCmd, "password", null); try { createAccountCmd.execute(); Assert.fail("should throw exception for a null password"); } catch (ServerApiException e) { Assert.assertEquals(ApiErrorCode.PARAM_ERROR, e.getErrorCode()); Assert.assertEquals("Empty passwords are not allowed", e.getMessage()); } Mockito.verify(accountService, Mockito.never()).createUserAccount(null, null, null, null, null, null, null, accountType, roleId, domainId, null, null, null, null); }
@Test public void testExecuteWithNullPassword() { ReflectionTestUtils.setField(createUserCmd, "password", null); try { createUserCmd.execute(); Assert.fail("should throw exception for a null password"); } catch (ServerApiException e) { Assert.assertEquals(ApiErrorCode.PARAM_ERROR,e.getErrorCode()); Assert.assertEquals("Empty passwords are not allowed", e.getMessage()); } Mockito.verify(accountService, Mockito.never()).createUser(null, null, null, null, null, null, null, null, null); }
@Test public void testExecuteWithEmptyPassword() { ReflectionTestUtils.setField(createUserCmd, "password", ""); try { createUserCmd.execute(); Assert.fail("should throw exception for a empty password"); } catch (ServerApiException e) { Assert.assertEquals(ApiErrorCode.PARAM_ERROR,e.getErrorCode()); Assert.assertEquals("Empty passwords are not allowed", e.getMessage()); } Mockito.verify(accountService, Mockito.never()).createUser(null, null, null, null, null, null, null, null, null); } }