### Question:
InfrastructureTemplateResource implements DockerAPI { @GET @Path("/{project}/{endpoint}/computational_templates") public Iterable<FullComputationalTemplate> getComputationalTemplates(@Auth UserInfo userInfo, @PathParam("project") String project, @PathParam("endpoint") String endpoint) { return infrastructureTemplateService.getComputationalTemplates(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 getComputationalTemplates() { FullComputationalTemplate fullComputationalTemplate = new FullComputationalTemplate(new ComputationalMetadataDTO()); when(infrastructureTemplateService.getComputationalTemplates(any(UserInfo.class), anyString(), anyString())) .thenReturn(Collections.singletonList(fullComputationalTemplate)); final Response response = resources.getJerseyTest() .target("/infrastructure_templates/test/endpoint/computational_templates") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_OK, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(infrastructureTemplateService).getComputationalTemplates(getUserInfo(), "test", "endpoint"); verifyNoMoreInteractions(infrastructureTemplateService); }
@Test public void getComputationalTemplatesWithFailedAuth() throws AuthenticationException { authFailSetup(); FullComputationalTemplate fullComputationalTemplate = new FullComputationalTemplate(new ComputationalMetadataDTO()); when(infrastructureTemplateService.getComputationalTemplates(any(UserInfo.class), anyString(), anyString())) .thenReturn(Collections.singletonList(fullComputationalTemplate)); final Response response = resources.getJerseyTest() .target("/infrastructure_templates/test/endpoint/computational_templates") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_OK, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(infrastructureTemplateService).getComputationalTemplates(getUserInfo(), "test", "endpoint"); verifyNoMoreInteractions(infrastructureTemplateService); }
@Test public void getComputationalTemplatesWithException() { doThrow(new DlabException("Could not load list of computational templates for user")) .when(infrastructureTemplateService).getComputationalTemplates(any(UserInfo.class), anyString(), anyString()); final Response response = resources.getJerseyTest() .target("/infrastructure_templates/test/endpoint/computational_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).getComputationalTemplates(getUserInfo(), "test", "endpoint"); verifyNoMoreInteractions(infrastructureTemplateService); }