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"));
}
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"));
}
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());
}
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);
}
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);
}
Aggregations