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