Search in sources :

Example 41 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class RemoteAPIController method read.

/**
 * Get an individual remote API's page
 *
 * @param apiId
 *            The ID of the api
 * @param model
 *            Model for the view
 * @param locale
 *            the locale specified by the browser.
 * @return The name of the remote api details page view
 */
@RequestMapping("/{apiId}")
public String read(@PathVariable Long apiId, Model model, Locale locale) {
    RemoteAPI remoteApi = remoteAPIService.read(apiId);
    model.addAttribute("remoteApi", remoteApi);
    try {
        RemoteAPIToken token = tokenService.getToken(remoteApi);
        model.addAttribute("tokenExpiry", dateTimeFormatter.print(token.getExpiryDate(), locale));
    } catch (EntityNotFoundException ex) {
        // Not returning a token here is acceptable. The view will have to
        // handle a state if the token does not exist
        logger.trace("No token for service " + remoteApi);
    }
    return DETAILS_PAGE;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 42 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class OAuthTokenRestTemplateIT method testRequestWithBadToken.

@Test(expected = IridaOAuthException.class)
public void testRequestWithBadToken() throws URISyntaxException {
    RemoteAPI remoteAPI = apiService.read(1L);
    URI serviceURI = new URI(remoteAPI.getServiceURI());
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
    mockServer.expect(requestTo(serviceURI)).andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
    restTemplate.getForEntity(serviceURI, String.class);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) URI(java.net.URI) Test(org.junit.Test)

Example 43 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class OAuthTokenRestTemplateIT method testOAuthRequest.

@Test
public void testOAuthRequest() throws URISyntaxException {
    RemoteAPI remoteAPI = apiService.read(1L);
    URI serviceURI = new URI(remoteAPI.getServiceURI());
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
    String responseMessage = "{ \"message\" : \"all good\" }";
    mockServer.expect(requestTo(serviceURI)).andExpect(method(HttpMethod.GET)).andRespond(withSuccess(responseMessage, MediaType.APPLICATION_JSON));
    ResponseEntity<String> forEntity = restTemplate.getForEntity(serviceURI, String.class);
    assertNotNull(forEntity);
    assertEquals(responseMessage, forEntity.getBody());
    mockServer.verify();
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) URI(java.net.URI) Test(org.junit.Test)

Example 44 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class OAuthTokenRestTemplateIT method testRequestWithNoToken.

@Test(expected = IridaOAuthException.class)
public void testRequestWithNoToken() throws URISyntaxException {
    RemoteAPI remoteAPI = apiService.read(3L);
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    URI serviceURI = new URI(remoteAPI.getServiceURI());
    restTemplate.getForEntity(serviceURI, String.class);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) URI(java.net.URI) Test(org.junit.Test)

Aggregations

RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)44 Test (org.junit.Test)30 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)6 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)6 URI (java.net.URI)5 Date (java.util.Date)5 Link (org.springframework.hateoas.Link)5 IridaOAuthException (ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)3 RemoteStatus (ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)3 Before (org.junit.Before)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 OAuthTokenRestTemplate (ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)2