@Test public void shouldReturnIdentityFault405() throws IOException, IdentityFault { Mockito.when(responseMock.getStatus()).thenReturn(IdentityConstants.NOT_PERMITTED); Assert.assertEquals(IdentityConstants.NOT_PERMITTED, IdentityResponseWrapper.buildFaultMessage(responseMock).getCode()); }
public static IdentityFault buildFaultMessage(Response response) throws IdentityFault { if (response != null) { logger.info("ResponseWrapper, response status code is: " + response.getStatus()); try { if (response.getStatus() == IdentityConstants.BAD_REQUEST) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.UNAUTHORIZED) { UnauthorizedFault e = response.readEntity(UnauthorizedFault.class); return new IdentityFault(e.getMessage(), e.getDetails(), e.getCode()); } if (response.getStatus() == IdentityConstants.FORBIDDEN) { UserDisabledFault udf = response.readEntity(UserDisabledFault.class); if (udf != null) { return processIdentityFault(udf); } else { ForbiddenFault e = response.readEntity(ForbiddenFault.class); return processIdentityFault(e); } } if (response.getStatus() == IdentityConstants.NOT_FOUND) { ItemNotFoundFault e = response.readEntity(ItemNotFoundFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_PERMITTED) { return new IdentityFault("Operation not allowed", "The requested resource or operation could not be found", IdentityConstants.NOT_PERMITTED); } if (response.getStatus() == IdentityConstants.NAME_CONFLICT) { TenantConflictFault e = response.readEntity(TenantConflictFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.SERVICE_UNAVAILABLE) { ServiceUnavailableFault e = response.readEntity(ServiceUnavailableFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_IMPLMENTED) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.AUTH_FAULT) { org.openstack.identity.client.faults.IdentityFault e = response.readEntity(org.openstack.identity.client.faults.IdentityFault.class); return processIdentityFault(e); } } catch (Exception ex) { logger.error("Exception was thrown for response with status: " + response.getStatus()); if (ex instanceof UnsupportedOperationException) { throw new IdentityFault("There was an error communicating with the auth service...", ex.getLocalizedMessage(), response.getStatus()); } logger.error("Exception was thrown and could not be handled by the client. Response status code: " + response.getStatus()); throw new IdentityFault(ex.getMessage(), ex.getLocalizedMessage(), response.getStatus()); } } return new IdentityFault("Unable to process request.", "There was an unexpected error communicating with the auth service.", IdentityConstants.AUTH_FAULT); }
IdentityResponseWrapper { public static IdentityFault buildFaultMessage(Response response) throws IdentityFault { if (response != null) { logger.info("ResponseWrapper, response status code is: " + response.getStatus()); try { if (response.getStatus() == IdentityConstants.BAD_REQUEST) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.UNAUTHORIZED) { UnauthorizedFault e = response.readEntity(UnauthorizedFault.class); return new IdentityFault(e.getMessage(), e.getDetails(), e.getCode()); } if (response.getStatus() == IdentityConstants.FORBIDDEN) { UserDisabledFault udf = response.readEntity(UserDisabledFault.class); if (udf != null) { return processIdentityFault(udf); } else { ForbiddenFault e = response.readEntity(ForbiddenFault.class); return processIdentityFault(e); } } if (response.getStatus() == IdentityConstants.NOT_FOUND) { ItemNotFoundFault e = response.readEntity(ItemNotFoundFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_PERMITTED) { return new IdentityFault("Operation not allowed", "The requested resource or operation could not be found", IdentityConstants.NOT_PERMITTED); } if (response.getStatus() == IdentityConstants.NAME_CONFLICT) { TenantConflictFault e = response.readEntity(TenantConflictFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.SERVICE_UNAVAILABLE) { ServiceUnavailableFault e = response.readEntity(ServiceUnavailableFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_IMPLMENTED) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.AUTH_FAULT) { org.openstack.identity.client.faults.IdentityFault e = response.readEntity(org.openstack.identity.client.faults.IdentityFault.class); return processIdentityFault(e); } } catch (Exception ex) { logger.error("Exception was thrown for response with status: " + response.getStatus()); if (ex instanceof UnsupportedOperationException) { throw new IdentityFault("There was an error communicating with the auth service...", ex.getLocalizedMessage(), response.getStatus()); } logger.error("Exception was thrown and could not be handled by the client. Response status code: " + response.getStatus()); throw new IdentityFault(ex.getMessage(), ex.getLocalizedMessage(), response.getStatus()); } } return new IdentityFault("Unable to process request.", "There was an unexpected error communicating with the auth service.", IdentityConstants.AUTH_FAULT); } }
IdentityResponseWrapper { public static IdentityFault buildFaultMessage(Response response) throws IdentityFault { if (response != null) { logger.info("ResponseWrapper, response status code is: " + response.getStatus()); try { if (response.getStatus() == IdentityConstants.BAD_REQUEST) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.UNAUTHORIZED) { UnauthorizedFault e = response.readEntity(UnauthorizedFault.class); return new IdentityFault(e.getMessage(), e.getDetails(), e.getCode()); } if (response.getStatus() == IdentityConstants.FORBIDDEN) { UserDisabledFault udf = response.readEntity(UserDisabledFault.class); if (udf != null) { return processIdentityFault(udf); } else { ForbiddenFault e = response.readEntity(ForbiddenFault.class); return processIdentityFault(e); } } if (response.getStatus() == IdentityConstants.NOT_FOUND) { ItemNotFoundFault e = response.readEntity(ItemNotFoundFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_PERMITTED) { return new IdentityFault("Operation not allowed", "The requested resource or operation could not be found", IdentityConstants.NOT_PERMITTED); } if (response.getStatus() == IdentityConstants.NAME_CONFLICT) { TenantConflictFault e = response.readEntity(TenantConflictFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.SERVICE_UNAVAILABLE) { ServiceUnavailableFault e = response.readEntity(ServiceUnavailableFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_IMPLMENTED) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.AUTH_FAULT) { org.openstack.identity.client.faults.IdentityFault e = response.readEntity(org.openstack.identity.client.faults.IdentityFault.class); return processIdentityFault(e); } } catch (Exception ex) { logger.error("Exception was thrown for response with status: " + response.getStatus()); if (ex instanceof UnsupportedOperationException) { throw new IdentityFault("There was an error communicating with the auth service...", ex.getLocalizedMessage(), response.getStatus()); } logger.error("Exception was thrown and could not be handled by the client. Response status code: " + response.getStatus()); throw new IdentityFault(ex.getMessage(), ex.getLocalizedMessage(), response.getStatus()); } } return new IdentityFault("Unable to process request.", "There was an unexpected error communicating with the auth service.", IdentityConstants.AUTH_FAULT); }  }
IdentityResponseWrapper { public static IdentityFault buildFaultMessage(Response response) throws IdentityFault { if (response != null) { logger.info("ResponseWrapper, response status code is: " + response.getStatus()); try { if (response.getStatus() == IdentityConstants.BAD_REQUEST) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.UNAUTHORIZED) { UnauthorizedFault e = response.readEntity(UnauthorizedFault.class); return new IdentityFault(e.getMessage(), e.getDetails(), e.getCode()); } if (response.getStatus() == IdentityConstants.FORBIDDEN) { UserDisabledFault udf = response.readEntity(UserDisabledFault.class); if (udf != null) { return processIdentityFault(udf); } else { ForbiddenFault e = response.readEntity(ForbiddenFault.class); return processIdentityFault(e); } } if (response.getStatus() == IdentityConstants.NOT_FOUND) { ItemNotFoundFault e = response.readEntity(ItemNotFoundFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_PERMITTED) { return new IdentityFault("Operation not allowed", "The requested resource or operation could not be found", IdentityConstants.NOT_PERMITTED); } if (response.getStatus() == IdentityConstants.NAME_CONFLICT) { TenantConflictFault e = response.readEntity(TenantConflictFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.SERVICE_UNAVAILABLE) { ServiceUnavailableFault e = response.readEntity(ServiceUnavailableFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_IMPLMENTED) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.AUTH_FAULT) { org.openstack.identity.client.faults.IdentityFault e = response.readEntity(org.openstack.identity.client.faults.IdentityFault.class); return processIdentityFault(e); } } catch (Exception ex) { logger.error("Exception was thrown for response with status: " + response.getStatus()); if (ex instanceof UnsupportedOperationException) { throw new IdentityFault("There was an error communicating with the auth service...", ex.getLocalizedMessage(), response.getStatus()); } logger.error("Exception was thrown and could not be handled by the client. Response status code: " + response.getStatus()); throw new IdentityFault(ex.getMessage(), ex.getLocalizedMessage(), response.getStatus()); } } return new IdentityFault("Unable to process request.", "There was an unexpected error communicating with the auth service.", IdentityConstants.AUTH_FAULT); }  static IdentityFault buildFaultMessage(Response response); }
IdentityResponseWrapper { public static IdentityFault buildFaultMessage(Response response) throws IdentityFault { if (response != null) { logger.info("ResponseWrapper, response status code is: " + response.getStatus()); try { if (response.getStatus() == IdentityConstants.BAD_REQUEST) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.UNAUTHORIZED) { UnauthorizedFault e = response.readEntity(UnauthorizedFault.class); return new IdentityFault(e.getMessage(), e.getDetails(), e.getCode()); } if (response.getStatus() == IdentityConstants.FORBIDDEN) { UserDisabledFault udf = response.readEntity(UserDisabledFault.class); if (udf != null) { return processIdentityFault(udf); } else { ForbiddenFault e = response.readEntity(ForbiddenFault.class); return processIdentityFault(e); } } if (response.getStatus() == IdentityConstants.NOT_FOUND) { ItemNotFoundFault e = response.readEntity(ItemNotFoundFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_PERMITTED) { return new IdentityFault("Operation not allowed", "The requested resource or operation could not be found", IdentityConstants.NOT_PERMITTED); } if (response.getStatus() == IdentityConstants.NAME_CONFLICT) { TenantConflictFault e = response.readEntity(TenantConflictFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.SERVICE_UNAVAILABLE) { ServiceUnavailableFault e = response.readEntity(ServiceUnavailableFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.NOT_IMPLMENTED) { BadRequestFault e = response.readEntity(BadRequestFault.class); return processIdentityFault(e); } if (response.getStatus() == IdentityConstants.AUTH_FAULT) { org.openstack.identity.client.faults.IdentityFault e = response.readEntity(org.openstack.identity.client.faults.IdentityFault.class); return processIdentityFault(e); } } catch (Exception ex) { logger.error("Exception was thrown for response with status: " + response.getStatus()); if (ex instanceof UnsupportedOperationException) { throw new IdentityFault("There was an error communicating with the auth service...", ex.getLocalizedMessage(), response.getStatus()); } logger.error("Exception was thrown and could not be handled by the client. Response status code: " + response.getStatus()); throw new IdentityFault(ex.getMessage(), ex.getLocalizedMessage(), response.getStatus()); } } return new IdentityFault("Unable to process request.", "There was an unexpected error communicating with the auth service.", IdentityConstants.AUTH_FAULT); }  static IdentityFault buildFaultMessage(Response response);  }