Search in sources :

Example 41 with RecordNameEntity

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

the class JpaJaxbNameAdapterTest method fromNameToRecordNameEntityTest.

@Test
public void fromNameToRecordNameEntityTest() throws JAXBException {
    Name name = new Name();
    name.setCreditName(new CreditName("Credit Name"));
    name.setFamilyName(new FamilyName("Family Name"));
    name.setGivenNames(new GivenNames("Given Names"));
    name.setPath("0000-0000-0000-0000");
    name.setVisibility(Visibility.PUBLIC);
    name.setSource(new Source("0000-0000-0000-0000"));
    RecordNameEntity entity = adapter.toRecordNameEntity(name);
    assertNotNull(entity);
    assertEquals("Credit Name", entity.getCreditName());
    assertEquals("Family Name", entity.getFamilyName());
    assertEquals("Given Names", entity.getGivenNames());
    assertEquals(Visibility.PUBLIC, entity.getVisibility());
    assertNotNull(entity.getProfile());
    assertEquals("0000-0000-0000-0000", entity.getProfile().getId());
}
Also used : FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) CreditName(org.orcid.jaxb.model.common_v2.CreditName) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Source(org.orcid.jaxb.model.common_v2.Source) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) Test(org.junit.Test)

Example 42 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))).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))).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))).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))).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)42 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)20 Test (org.junit.Test)15 DBUnitTest (org.orcid.test.DBUnitTest)8 Date (java.util.Date)7 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)6 HashSet (java.util.HashSet)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)4 Email (org.orcid.jaxb.model.record_v2.Email)4 Before (org.junit.Before)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Name (org.orcid.jaxb.model.record_v2.Name)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 List (java.util.List)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 CreditName (org.orcid.jaxb.model.common_v2.CreditName)2 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)2 Transactional (org.springframework.transaction.annotation.Transactional)2