Search in sources :

Example 6 with OrcidSecurityManager

use of org.orcid.core.manager.OrcidSecurityManager in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_GeneralTest 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);
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.doNothing().when(orcidSecurityManager).checkScopes(Mockito.any(ScopePathType.class));
    MemberV2ApiServiceDelegatorImpl delegator = new MemberV2ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
    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) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Search(org.orcid.jaxb.model.search_v2.Search) MemberV2ApiServiceDelegatorImpl(org.orcid.api.memberV2.server.delegator.impl.MemberV2ApiServiceDelegatorImpl) OrcidSecurityManager(org.orcid.core.manager.OrcidSecurityManager) List(java.util.List) OrcidSearchManager(org.orcid.core.manager.OrcidSearchManager) Result(org.orcid.jaxb.model.search_v2.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 7 with OrcidSecurityManager

use of org.orcid.core.manager.OrcidSecurityManager in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_GeneralTest method testSearchByQueryBadScope.

@Test(expected = AccessControlException.class)
public void testSearchByQueryBadScope() {
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.doThrow(new AccessControlException("some problem with scope")).when(orcidSecurityManager).checkScopes(Mockito.any(ScopePathType.class));
    MemberV2ApiServiceDelegatorImpl delegator = new MemberV2ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
    delegator.searchByQuery(new HashMap<>());
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) MemberV2ApiServiceDelegatorImpl(org.orcid.api.memberV2.server.delegator.impl.MemberV2ApiServiceDelegatorImpl) OrcidSecurityManager(org.orcid.core.manager.OrcidSecurityManager) AccessControlException(java.security.AccessControlException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 OrcidSecurityManager (org.orcid.core.manager.OrcidSecurityManager)7 List (java.util.List)6 DBUnitTest (org.orcid.test.DBUnitTest)6 LocaleManager (org.orcid.core.locale.LocaleManager)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Response (javax.ws.rs.core.Response)3 MemberV2ApiServiceDelegatorImpl (org.orcid.api.memberV2.server.delegator.impl.MemberV2ApiServiceDelegatorImpl)3 PublicV2ApiServiceDelegatorImpl (org.orcid.api.publicV2.server.delegator.impl.PublicV2ApiServiceDelegatorImpl)3 OrcidSearchManager (org.orcid.core.manager.OrcidSearchManager)3 Search (org.orcid.jaxb.model.search_v2.Search)3 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2 AccessControlException (java.security.AccessControlException)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 StringUtils (org.apache.commons.lang3.StringUtils)1