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