Search in sources :

Example 16 with RemoteAPI

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

the class RemoteAPIControllerTest method testReadNoToken.

@Test
public void testReadNoToken() {
    Long apiId = 1L;
    ExtendedModelMap model = new ExtendedModelMap();
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    when(remoteAPIService.read(apiId)).thenReturn(client);
    when(tokenService.getToken(client)).thenThrow(new EntityNotFoundException("no token"));
    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) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 17 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI 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)

Example 18 with RemoteAPI

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

the class RemoteAPIControllerTest method testGetAjaxList.

@SuppressWarnings("unchecked")
@Test
public void testGetAjaxList() {
    int page = 0;
    int size = 10;
    int draw = 1;
    int sortColumn = 0;
    String direction = "asc";
    String searchValue = "";
    Principal principal = () -> USER_NAME;
    RemoteAPI api1 = new RemoteAPI("api name", "http://somewhere", "an api", "client1", "secret1");
    api1.setId(1L);
    RemoteAPI api2 = new RemoteAPI("api name 2", "http://nowhere", "another api", "client2", "secret2");
    api2.setId(2L);
    Page<RemoteAPI> apiPage = new PageImpl<>(Lists.newArrayList(api1, api2));
    when(remoteAPIService.search(any(Specification.class), eq(page), eq(size), any(Direction.class), any(String.class))).thenReturn(apiPage);
    Map<String, Object> ajaxAPIList = remoteAPIController.getAjaxAPIList(page, size, draw, sortColumn, direction, searchValue, principal, locale);
    verify(remoteAPIService).search(any(Specification.class), eq(page), eq(size), any(Direction.class), any(String.class));
    assertNotNull(ajaxAPIList);
    assertFalse(ajaxAPIList.isEmpty());
    List<List<String>> apiList = (List<List<String>>) ajaxAPIList.get(DataTable.RESPONSE_PARAM_DATA);
    assertEquals(2, apiList.size());
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) PageImpl(org.springframework.data.domain.PageImpl) Specification(org.springframework.data.jpa.domain.Specification) List(java.util.List) Direction(org.springframework.data.domain.Sort.Direction) Principal(java.security.Principal) Test(org.junit.Test)

Example 19 with RemoteAPI

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

the class RemoteAPIControllerTest method testCheckApiStatusInactive.

@Test
public void testCheckApiStatusInactive() {
    Long apiId = 1L;
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    when(remoteAPIService.read(apiId)).thenReturn(client);
    when(projectRemoteService.getServiceStatus(client)).thenThrow(new IridaOAuthException("invalid token", client));
    String checkApiStatus = remoteAPIController.checkApiStatus(apiId);
    assertEquals(RemoteAPIController.INVALID_OAUTH_TOKEN, checkApiStatus);
    verify(remoteAPIService).read(apiId);
    verify(projectRemoteService).getServiceStatus(client);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) Test(org.junit.Test)

Example 20 with RemoteAPI

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

the class RemoteAPIControllerTest method testConnectToAPIActiveToken.

@Test
public void testConnectToAPIActiveToken() {
    Long apiId = 1L;
    ExtendedModelMap model = new ExtendedModelMap();
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    when(remoteAPIService.read(apiId)).thenReturn(client);
    when(projectRemoteService.getServiceStatus(client)).thenReturn(true);
    String connectToAPI = remoteAPIController.connectToAPI(apiId, model);
    assertEquals(RemoteAPIController.PARENT_FRAME_RELOAD_PAGE, connectToAPI);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) 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