Search in sources :

Example 1 with RemoteAPIToken

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

the class OAuthTokenRestTemplateTest method testCreateRequestExpiredToken.

@Test(expected = IridaOAuthException.class)
public void testCreateRequestExpiredToken() throws URISyntaxException, IOException {
    String tokenString = "token111111";
    RemoteAPIToken token = new RemoteAPIToken(tokenString, remoteAPI, new Date(System.currentTimeMillis() - 10000));
    when(tokenService.getToken(remoteAPI)).thenReturn(token);
    restTemplate.createRequest(serviceURI, HttpMethod.GET);
}
Also used : RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) Date(java.util.Date) Test(org.junit.Test)

Example 2 with RemoteAPIToken

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

the class OAuthTokenRestTemplateTest method testCreateRequest.

@Test
public void testCreateRequest() throws URISyntaxException, IOException {
    String tokenString = "token111111";
    RemoteAPIToken token = new RemoteAPIToken(tokenString, remoteAPI, new Date(System.currentTimeMillis() + 10000));
    when(tokenService.getToken(remoteAPI)).thenReturn(token);
    ClientHttpRequest createRequest = restTemplate.createRequest(serviceURI, HttpMethod.GET);
    verify(tokenService).getToken(remoteAPI);
    assertNotNull(createRequest);
    assertTrue(createRequest.getHeaders().containsKey("Authorization"));
    List<String> list = createRequest.getHeaders().get("Authorization");
    assertTrue(list.contains("Bearer " + tokenString));
}
Also used : RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) Date(java.util.Date) Test(org.junit.Test)

Example 3 with RemoteAPIToken

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

the class RemoteAPITokenServiceImplIT method addTokenExisting.

@Test
public void addTokenExisting() {
    RemoteAPI api = apiService.read(1L);
    RemoteAPIToken originalToken = tokenService.getToken(api);
    RemoteAPIToken token = new RemoteAPIToken("111111111", api, new Date());
    tokenService.create(token);
    RemoteAPIToken readToken = tokenService.getToken(api);
    assertNotEquals(token, originalToken);
    assertEquals(token, readToken);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) Date(java.util.Date) Test(org.junit.Test)

Example 4 with RemoteAPIToken

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

the class RemoteAPITokenServiceImplIT method testAddToken.

@Test
public void testAddToken() {
    RemoteAPI api = apiService.read(2L);
    RemoteAPIToken token = new RemoteAPIToken("111111111", api, new Date());
    tokenService.create(token);
    RemoteAPIToken readToken = tokenService.getToken(api);
    assertEquals(token, readToken);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) Date(java.util.Date) Test(org.junit.Test)

Example 5 with RemoteAPIToken

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

the class RemoteAPIControllerTest method testRead.

@Test
public void testRead() {
    Long apiId = 1L;
    ExtendedModelMap model = new ExtendedModelMap();
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    RemoteAPIToken remoteAPIToken = new RemoteAPIToken("xyz", client, new Date());
    when(remoteAPIService.read(apiId)).thenReturn(client);
    when(tokenService.getToken(client)).thenReturn(remoteAPIToken);
    remoteAPIController.read(apiId, model, locale);
    verify(remoteAPIService).read(apiId);
    verify(tokenService).getToken(client);
    assertTrue(model.containsAttribute("remoteApi"));
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)16 Date (java.util.Date)8 Test (org.junit.Test)7 RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)6 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)5 Transactional (org.springframework.transaction.annotation.Transactional)3 User (ca.corefacility.bioinformatics.irida.model.user.User)2 URI (java.net.URI)2 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)2 OAuthJSONAccessTokenResponse (org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse)2 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)2 IridaOAuthException (ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException)1 RemoteApiTokenRepository (ca.corefacility.bioinformatics.irida.repositories.RemoteApiTokenRepository)1 UserRepository (ca.corefacility.bioinformatics.irida.repositories.user.UserRepository)1 RemoteAPITokenServiceImpl (ca.corefacility.bioinformatics.irida.service.impl.RemoteAPITokenServiceImpl)1 OAuthClient (org.apache.oltu.oauth2.client.OAuthClient)1 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1 Before (org.junit.Before)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1