Search in sources :

Example 31 with RemoteAPI

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

the class RemoteAPIControllerTest method testPostCreateRemoteAPIError.

@Test
public void testPostCreateRemoteAPIError() {
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    client.setId(1L);
    ExtendedModelMap model = new ExtendedModelMap();
    Locale locale = LocaleContextHolder.getLocale();
    DataIntegrityViolationException ex = new DataIntegrityViolationException("Error: " + RemoteAPI.SERVICE_URI_CONSTRAINT_NAME);
    when(remoteAPIService.create(client)).thenThrow(ex);
    String postCreateClient = remoteAPIController.postCreateRemoteAPI(client, model, locale);
    assertEquals(RemoteAPIController.ADD_API_PAGE, postCreateClient);
    assertTrue(model.containsAttribute("errors"));
    @SuppressWarnings("unchecked") Map<String, String> errors = (Map<String, String>) model.get("errors");
    assertTrue(errors.containsKey("serviceURI"));
    verify(remoteAPIService).create(client);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Locale(java.util.Locale) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 32 with RemoteAPI

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

the class RemoteAPIControllerTest method testPostCreateRemoteAPI.

@Test
public void testPostCreateRemoteAPI() {
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    client.setId(1L);
    ExtendedModelMap model = new ExtendedModelMap();
    when(remoteAPIService.create(client)).thenReturn(client);
    String postCreateClient = remoteAPIController.postCreateRemoteAPI(client, model, locale);
    assertEquals("redirect:/remote_api/1", postCreateClient);
    verify(remoteAPIService).create(client);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Test(org.junit.Test)

Example 33 with RemoteAPI

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

the class RemoteAPIServiceImplIT method testGetApiByURL.

@Test
@WithMockUser(username = "tom", roles = "USER")
public void testGetApiByURL() {
    String resourceURL = "http://irida.ca/api/projects/2";
    RemoteAPI apiForUrl = remoteAPIService.getRemoteAPIForUrl(resourceURL);
    assertNotNull(apiForUrl);
    assertTrue(resourceURL.contains(apiForUrl.getServiceURI()));
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 34 with RemoteAPI

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

the class RemoteAPITokenServiceImplIT method testDeleteToken.

@Test(expected = EntityNotFoundException.class)
public void testDeleteToken() {
    RemoteAPI api = null;
    try {
        api = apiService.read(1L);
        tokenService.delete(api);
    } catch (EntityNotFoundException ex) {
        fail("Token should be able to be deleted");
    }
    tokenService.getToken(api);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 35 with RemoteAPI

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

the class RemoteAPITokenServiceImplIT method testGetToken.

@Test
public void testGetToken() {
    RemoteAPI api = apiService.read(1L);
    RemoteAPIToken token = tokenService.getToken(api);
    assertNotNull(token);
    assertEquals("123456789", token.getTokenString());
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) 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