### Question:
InfrastructureTemplateResource implements DockerAPI { @GET @Path("/{project}/{endpoint}/exploratory_templates") public Iterable<ExploratoryMetadataDTO> getExploratoryTemplates(@Auth UserInfo userInfo, @PathParam("project") String project, @PathParam("endpoint") String endpoint) { return infrastructureTemplateService.getExploratoryTemplates(userInfo, project, endpoint); } @Inject  InfrastructureTemplateResource(InfrastructureTemplateService infrastructureTemplateService); @GET @Path("/{project}/{endpoint}/computational_templates") Iterable<FullComputationalTemplate> getComputationalTemplates(@Auth UserInfo userInfo,
																		 @PathParam("project") String project,
																		 @PathParam("endpoint") String endpoint); @GET @Path("/{project}/{endpoint}/exploratory_templates") Iterable<ExploratoryMetadataDTO> getExploratoryTemplates(@Auth UserInfo userInfo,
																	@PathParam("project") String project,
																	@PathParam("endpoint") String endpoint);  }### Answer:
@Test public void getExploratoryTemplates() { ExploratoryMetadataDTO exploratoryMetadataDTO = new ExploratoryMetadataDTO("someImageName"); when(infrastructureTemplateService.getExploratoryTemplates(any(UserInfo.class), anyString(), anyString())) .thenReturn(Collections.singletonList(exploratoryMetadataDTO)); final Response response = resources.getJerseyTest() .target("/infrastructure_templates/test/endpoint/exploratory_templates") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_OK, response.getStatus()); assertEquals(Collections.singletonList(exploratoryMetadataDTO), response.readEntity(new GenericType<List<ExploratoryMetadataDTO>>() { })); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(infrastructureTemplateService).getExploratoryTemplates(getUserInfo(), "test", "endpoint"); verifyNoMoreInteractions(infrastructureTemplateService); }
@Test public void getExploratoryTemplatesWithFailedAuth() throws AuthenticationException { authFailSetup(); ExploratoryMetadataDTO exploratoryMetadataDTO = new ExploratoryMetadataDTO("someImageName"); when(infrastructureTemplateService.getExploratoryTemplates(any(UserInfo.class), anyString(), anyString())) .thenReturn(Collections.singletonList(exploratoryMetadataDTO)); final Response response = resources.getJerseyTest() .target("/infrastructure_templates/test/endpoint/exploratory_templates") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_OK, response.getStatus()); assertEquals(Collections.singletonList(exploratoryMetadataDTO), response.readEntity(new GenericType<List<ExploratoryMetadataDTO>>() { })); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(infrastructureTemplateService).getExploratoryTemplates(getUserInfo(), "test", "endpoint"); verifyNoMoreInteractions(infrastructureTemplateService); }
@Test public void getExploratoryTemplatesWithException() { doThrow(new DlabException("Could not load list of exploratory templates for user")) .when(infrastructureTemplateService).getExploratoryTemplates(any(UserInfo.class), anyString(), anyString()); final Response response = resources.getJerseyTest() .target("/infrastructure_templates/test/endpoint/exploratory_templates") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(infrastructureTemplateService).getExploratoryTemplates(getUserInfo(), "test", "endpoint"); verifyNoMoreInteractions(infrastructureTemplateService); }