Search in sources :

Example 66 with RecordNameEntity

use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.

the class SourceNameCacheManagerTest method before.

@Before
public void before() {
    when(mock_clientDetailsDao.existsAndIsNotPublicClient(OLD_FORMAT_CLIENT_ID)).thenReturn(true);
    when(mock_clientDetailsDao.existsAndIsNotPublicClient(AdditionalMatchers.not(Matchers.eq(OLD_FORMAT_CLIENT_ID)))).thenReturn(false);
    when(mock_recordNameDao.getRecordName(Matchers.eq(USER_PUBLIC_NAME), Mockito.anyLong())).thenAnswer(new Answer<RecordNameEntity>() {

        @Override
        public RecordNameEntity answer(InvocationOnMock invocation) throws Throwable {
            String id = (String) invocation.getArguments()[0];
            RecordNameEntity recordName = new RecordNameEntity();
            recordName.setLastModified(new Date());
            recordName.setCreditName("Credit name for " + id);
            recordName.setProfile(new ProfileEntity(id));
            recordName.setVisibility(Visibility.PUBLIC);
            return recordName;
        }
    });
    when(mock_recordNameDao.getRecordName(Matchers.eq(USER_LIMITED_NAME), Mockito.anyLong())).thenAnswer(new Answer<RecordNameEntity>() {

        @Override
        public RecordNameEntity answer(InvocationOnMock invocation) throws Throwable {
            String id = (String) invocation.getArguments()[0];
            RecordNameEntity recordName = new RecordNameEntity();
            recordName.setLastModified(new Date());
            recordName.setCreditName("Credit name for " + id);
            recordName.setProfile(new ProfileEntity(id));
            recordName.setVisibility(Visibility.LIMITED);
            return recordName;
        }
    });
    when(mock_recordNameDao.getRecordName(Matchers.eq(USER_PRIVATE_NAME), Mockito.anyLong())).thenAnswer(new Answer<RecordNameEntity>() {

        @Override
        public RecordNameEntity answer(InvocationOnMock invocation) throws Throwable {
            String id = (String) invocation.getArguments()[0];
            RecordNameEntity recordName = new RecordNameEntity();
            recordName.setLastModified(new Date());
            recordName.setCreditName("Credit name for " + id);
            recordName.setProfile(new ProfileEntity(id));
            recordName.setVisibility(Visibility.PRIVATE);
            return recordName;
        }
    });
    // Set up a client with the old id format and a user in the profile table, to be sure that the name is picked from the client details table
    when(mock_recordNameDao.getRecordName(Matchers.eq(OLD_FORMAT_CLIENT_ID), Mockito.anyLong())).thenAnswer(new Answer<RecordNameEntity>() {

        @Override
        public RecordNameEntity answer(InvocationOnMock invocation) throws Throwable {
            String id = (String) invocation.getArguments()[0];
            RecordNameEntity recordName = new RecordNameEntity();
            recordName.setLastModified(new Date());
            recordName.setCreditName("Am a USER!!!!");
            recordName.setProfile(new ProfileEntity(id));
            recordName.setVisibility(Visibility.PUBLIC);
            return recordName;
        }
    });
    when(mock_clientDetailsDao.find(Matchers.eq(OLD_FORMAT_CLIENT_ID))).thenAnswer(new Answer<ClientDetailsEntity>() {

        @Override
        public ClientDetailsEntity answer(InvocationOnMock invocation) throws Throwable {
            String id = (String) invocation.getArguments()[0];
            ClientDetailsEntity clientDetails = new ClientDetailsEntity();
            clientDetails.setId(id);
            clientDetails.setClientName("Am a CLIENT!!!!");
            return clientDetails;
        }
    });
    assertNotNull(sourceNameCacheManager);
    TargetProxyHelper.injectIntoProxy(sourceNameCacheManager, "recordNameDao", mock_recordNameDao);
    TargetProxyHelper.injectIntoProxy(sourceNameCacheManager, "clientDetailsDao", mock_clientDetailsDao);
    MockHttpServletRequest request = new MockHttpServletRequest();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Before(org.junit.Before)

Aggregations

RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)66 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)35 Test (org.junit.Test)26 DBUnitTest (org.orcid.test.DBUnitTest)13 Date (java.util.Date)11 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)10 HashSet (java.util.HashSet)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Before (org.junit.Before)4 Name (org.orcid.jaxb.model.v3.dev1.record.Name)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 Locale (org.orcid.jaxb.model.common_v2.Locale)3 Visibility (org.orcid.jaxb.model.common_v2.Visibility)3 Email (org.orcid.jaxb.model.record_v2.Email)3 Name (org.orcid.jaxb.model.record_v2.Name)3 Email (org.orcid.jaxb.model.v3.dev1.record.Email)3