### Question:
ImageExploratoryResource { @GET @Path("{name}") public Response getImage(@Auth UserInfo ui, @PathParam("name") String name, @QueryParam("project") String project, @QueryParam("endpoint") String endpoint) { log.debug("Getting image with name {} for user {}", name, ui.getName()); return Response.ok(imageExploratoryService.getImage(ui.getName(), name, project, endpoint)).build(); } @Inject  ImageExploratoryResource(ImageExploratoryService imageExploratoryService, RequestId requestId); @POST Response createImage(@Auth UserInfo ui,
								@Valid @NotNull ExploratoryImageCreateFormDTO formDTO,
								@Context UriInfo uriInfo); @GET Response getImages(@Auth UserInfo ui,
							  @QueryParam("docker_image") String dockerImage,
							  @QueryParam("project") String project,
							  @QueryParam("endpoint") String endpoint); @GET @Path("all") Response getAllImagesForProject(@Auth UserInfo ui, @NotNull @QueryParam("project") String project); @GET @Path("{name}") Response getImage(@Auth UserInfo ui,
							 @PathParam("name") String name,
							 @QueryParam("project") String project,
							 @QueryParam("endpoint") String endpoint);  }### Answer:
@Test public void getImage() { when(imageExploratoryService.getImage(anyString(), anyString(), anyString(), anyString())) .thenReturn(getImageList().get(0)); final Response response = resources.getJerseyTest() .target("/infrastructure_provision/exploratory_environment/image/someName") .queryParam("project", "someProject") .queryParam("endpoint", "someEndpoint") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_OK, response.getStatus()); assertEquals(getImageList().get(0), response.readEntity(ImageInfoRecord.class)); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(imageExploratoryService).getImage(USER.toLowerCase(), "someName", "someProject", "someEndpoint"); verifyNoMoreInteractions(imageExploratoryService); }
@Test public void getImageWithFailedAuth() throws AuthenticationException { authFailSetup(); when(imageExploratoryService.getImage(anyString(), anyString(), anyString(), anyString())) .thenReturn(getImageList().get(0)); final Response response = resources.getJerseyTest() .target("/infrastructure_provision/exploratory_environment/image/someName") .queryParam("project", "someProject") .queryParam("endpoint", "someEndpoint") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_OK, response.getStatus()); assertEquals(getImageList().get(0), response.readEntity(ImageInfoRecord.class)); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(imageExploratoryService).getImage(USER.toLowerCase(), "someName", "someProject", "someEndpoint"); verifyNoMoreInteractions(imageExploratoryService); }
@Test public void getImageWithException() { doThrow(new ResourceNotFoundException("Image with name was not found for user")) .when(imageExploratoryService).getImage(anyString(), anyString(), anyString(), anyString()); final Response response = resources.getJerseyTest() .target("/infrastructure_provision/exploratory_environment/image/someName") .queryParam("project", "someProject") .queryParam("endpoint", "someEndpoint") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(imageExploratoryService).getImage(USER.toLowerCase(), "someName", "someProject", "someEndpoint"); verifyNoMoreInteractions(imageExploratoryService); }