Search in sources :

Example 1 with PublicV3ApiServiceDelegatorImpl

use of org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest method testSearchByQueryLegalStart.

@Test
public void testSearchByQueryLegalStart() {
    Map<String, List<String>> params = new HashMap<>();
    params.put("start", Arrays.asList(Integer.toString(OrcidSearchManager.MAX_SEARCH_START)));
    LocaleManager localeManager = Mockito.mock(LocaleManagerImpl.class);
    Mockito.when(localeManager.resolveMessage(Mockito.anyString())).thenReturn("a message");
    OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class);
    Mockito.when(orcidSearchManager.findOrcidIds(Mockito.anyMap())).thenReturn(new Search());
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null);
    PublicV3ApiServiceDelegatorImpl delegator = new PublicV3ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "localeManager", localeManager);
    ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
    ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
    Response response = delegator.searchByQuery(params);
    assertNotNull(response);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) PublicV3ApiServiceDelegatorImpl(org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl) Search(org.orcid.jaxb.model.v3.dev1.search.Search) OrcidSecurityManager(org.orcid.core.manager.v3.OrcidSecurityManager) ArrayList(java.util.ArrayList) List(java.util.List) LocaleManager(org.orcid.core.locale.LocaleManager) OrcidSearchManager(org.orcid.core.manager.v3.OrcidSearchManager) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with PublicV3ApiServiceDelegatorImpl

use of org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest method testSearchByQueryTooManyRows.

@Test(expected = OrcidBadRequestException.class)
public void testSearchByQueryTooManyRows() {
    Map<String, List<String>> params = new HashMap<>();
    params.put("rows", Arrays.asList(Integer.toString(OrcidSearchManager.MAX_SEARCH_ROWS + 20)));
    LocaleManager localeManager = Mockito.mock(LocaleManagerImpl.class);
    Mockito.when(localeManager.resolveMessage(Mockito.anyString())).thenReturn("a message");
    PublicV3ApiServiceDelegatorImpl delegator = new PublicV3ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "localeManager", localeManager);
    delegator.searchByQuery(params);
}
Also used : HashMap(java.util.HashMap) PublicV3ApiServiceDelegatorImpl(org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl) ArrayList(java.util.ArrayList) List(java.util.List) LocaleManager(org.orcid.core.locale.LocaleManager) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with PublicV3ApiServiceDelegatorImpl

use of org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest method testSearchByQueryIllegalStart.

@Test(expected = SearchStartParameterLimitExceededException.class)
public void testSearchByQueryIllegalStart() {
    Map<String, List<String>> params = new HashMap<>();
    params.put("start", Arrays.asList(Integer.toString(OrcidSearchManager.MAX_SEARCH_START + 20)));
    LocaleManager localeManager = Mockito.mock(LocaleManagerImpl.class);
    Mockito.when(localeManager.resolveMessage(Mockito.anyString())).thenReturn("a message");
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null);
    PublicV3ApiServiceDelegatorImpl delegator = new PublicV3ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "localeManager", localeManager);
    ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
    delegator.searchByQuery(params);
}
Also used : HashMap(java.util.HashMap) PublicV3ApiServiceDelegatorImpl(org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl) OrcidSecurityManager(org.orcid.core.manager.v3.OrcidSecurityManager) ArrayList(java.util.ArrayList) List(java.util.List) LocaleManager(org.orcid.core.locale.LocaleManager) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with PublicV3ApiServiceDelegatorImpl

use of org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest method testSearchByQuery.

@Test
public void testSearchByQuery() {
    Search search = new Search();
    Result result = new Result();
    result.setOrcidIdentifier(new OrcidIdentifier("some-orcid-id"));
    search.getResults().add(result);
    OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class);
    Mockito.when(orcidSearchManager.findOrcidIds(Matchers.<Map<String, List<String>>>any())).thenReturn(search);
    PublicV3ApiServiceDelegatorImpl delegator = new PublicV3ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null);
    ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
    Response response = delegator.searchByQuery(new HashMap<String, List<String>>());
    assertNotNull(response);
    assertNotNull(response.getEntity());
    assertTrue(response.getEntity() instanceof Search);
    assertEquals(1, ((Search) response.getEntity()).getResults().size());
    assertEquals("some-orcid-id", ((Search) response.getEntity()).getResults().get(0).getOrcidIdentifier().getPath());
}
Also used : Response(javax.ws.rs.core.Response) OrcidIdentifier(org.orcid.jaxb.model.v3.dev1.common.OrcidIdentifier) PublicV3ApiServiceDelegatorImpl(org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl) Search(org.orcid.jaxb.model.v3.dev1.search.Search) OrcidSecurityManager(org.orcid.core.manager.v3.OrcidSecurityManager) ArrayList(java.util.ArrayList) List(java.util.List) OrcidSearchManager(org.orcid.core.manager.v3.OrcidSearchManager) Result(org.orcid.jaxb.model.v3.dev1.search.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 List (java.util.List)4 Test (org.junit.Test)4 PublicV3ApiServiceDelegatorImpl (org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl)4 DBUnitTest (org.orcid.test.DBUnitTest)4 HashMap (java.util.HashMap)3 LocaleManager (org.orcid.core.locale.LocaleManager)3 OrcidSecurityManager (org.orcid.core.manager.v3.OrcidSecurityManager)3 Response (javax.ws.rs.core.Response)2 OrcidSearchManager (org.orcid.core.manager.v3.OrcidSearchManager)2 Search (org.orcid.jaxb.model.v3.dev1.search.Search)2 OrcidIdentifier (org.orcid.jaxb.model.v3.dev1.common.OrcidIdentifier)1 Result (org.orcid.jaxb.model.v3.dev1.search.Result)1