ClientElbResource { @POST @Path("/create") @Timed @Produces(MediaType.APPLICATION_JSON) public Response createClientElb(@QueryParam("clientId") String clientId, @QueryParam("clientElbUrl") String clientElbUrl) { if(clientElbUrl == null || clientId == null) return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).entity( "ClientElbUrl or ClientId cannot be null").build(); else { try { URL verifyingURL = new URL(clientElbUrl); verifyingURL.toURI(); if(verifyingURL.getHost().length() < 1 || verifyingURL.getPath().length() > 0) { throw new MalformedURLException(); } ClientElbDefinition clientElbDefinition = new ClientElbDefinition(clientId, clientElbUrl); ClientElb clientElb = clientElbPersistenceService.persistClientElb( clientElbDefinition.getId(), clientElbDefinition); return Response.status(Response.Status.CREATED.getStatusCode()).entity(clientElb.getId()).build(); } catch(MalformedURLException ex) { logger.error("Malformed URL exception(no path allowed because Elb Url doesn't contain path) {} {} ", ex.getMessage(), ex.getStackTrace()); return Response.status(Response.Status.BAD_REQUEST).entity("MalformedURLException").build(); } catch(URISyntaxException ex) { logger.error("URI Syntax Exception {} {} ", ex.getMessage(), ex.getStackTrace()); return Response.status(Response.Status.BAD_REQUEST).entity("URISyntaxException").build(); } catch(Exception ex) { logger.error("Exception occured in ClientElb create {} {} ", ex.getMessage(), ex.getStackTrace()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } } @Inject  ClientElbResource(ClientElbPersistenceService clientElbPersistenceService
    ); @POST @Path("/create") @Timed @Produces(MediaType.APPLICATION_JSON) Response createClientElb(@QueryParam("clientId") String clientId,
                                @QueryParam("clientElbUrl") String clientElbUrl); @GET @Path("/findById") @Timed @Produces(MediaType.APPLICATION_JSON) Response findByIdClientElb(@QueryParam("clientId") String clientId); @POST @Path("/update") @Timed Response updateClientElb(@QueryParam("clientId") String clientId,
                                    @QueryParam("clientElbUrl") String clientElbUrl); @POST @Path("/delete") @Timed Response deleteClientElb(@QueryParam("clientId") String clientId);  }
@Test public void testCreateClientElb() { ClientElbDefinition clientElbDefinition = new ClientElbDefinition( "id1", "http: ClientElb clientElb = new ClientElb("id1", "http: when(clientElbPersistenceService.persistClientElb("id1", clientElbDefinition)) .thenReturn(clientElb); Response response_1 = clientElbResource.createClientElb( "id1", "http: Assertions.assertThat(response_1.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode()); Response response_2 = clientElbResource.createClientElb("id1", null); Assertions.assertThat(response_2.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode()); Response response_3 = clientElbResource.createClientElb("id1", "http: Assertions.assertThat(response_3.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode()); Response response_4 = clientElbResource.createClientElb(null, "http: Assertions.assertThat(response_4.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode()); Response response_5 = clientElbResource.createClientElb("id1", "http: Assertions.assertThat(response_5.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode()); verify(clientElbPersistenceService, times(1)).persistClientElb( "id1", clientElbDefinition); verifyNoMoreInteractions(clientElbPersistenceService); }