use of org.orcid.utils.listener.BaseMessage in project ORCID-Source by ORCID.
the class v2ClientPerMessageCacheTest method testActivityCache.
@Test
public void testActivityCache() throws LockedRecordException, DeprecatedRecordException {
// get it once
Date date = new Date();
date.setYear(1900);
BaseMessage message1 = new LastModifiedMessage("0000-0000-0000-0000", date);
ActivitiesSummary s = orcid20ApiClient.fetchPublicActivities(message1);
assertEquals(s.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTitle().getContent(), "blah");
// get it twice, if no error, then it's the cached version
when(mock_response.getEntity(Record.class)).thenThrow(new RuntimeException("called twice!"));
s = orcid20ApiClient.fetchPublicActivities(message1);
assertEquals(s.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTitle().getContent(), "blah");
// get it with a different message, should return fresh
BaseMessage message2 = new LastModifiedMessage("0000-0000-0000-0000", new Date());
try {
s = orcid20ApiClient.fetchPublicActivities(message2);
fail("returned cached when it should get fresh");
} catch (RuntimeException e) {
if (e.getMessage() != "called twice!")
fail("something weird");
}
}
use of org.orcid.utils.listener.BaseMessage in project ORCID-Source by ORCID.
the class v2ClientPerMessageCacheTest method testRecordCache.
@Test
public void testRecordCache() throws LockedRecordException, DeprecatedRecordException {
Date date = new Date();
date.setYear(1900);
BaseMessage message1 = new LastModifiedMessage("0000-0000-0000-0000", date);
Record r = orcid20ApiClient.fetchPublicRecord(message1);
assertEquals("http://orcid.org/0000-0000-0000-0000", r.getOrcidIdentifier().getPath());
// get it twice, if no error, then it's the cached version
when(mock_response.getEntity(Record.class)).thenThrow(new RuntimeException("called twice!"));
r = orcid20ApiClient.fetchPublicRecord(message1);
assertEquals("http://orcid.org/0000-0000-0000-0000", r.getOrcidIdentifier().getPath());
// get it with a different message, should return fresh
BaseMessage message2 = new LastModifiedMessage("0000-0000-0000-0000", new Date());
try {
r = orcid20ApiClient.fetchPublicRecord(message2);
fail("returned cached when it should get fresh");
} catch (RuntimeException e) {
if (e.getMessage() != "called twice!")
fail("something weird");
}
}
use of org.orcid.utils.listener.BaseMessage in project ORCID-Source by ORCID.
the class v2ClientPerMessageCacheTest method testRecordThenActivityCache.
@Test
public void testRecordThenActivityCache() throws LockedRecordException, DeprecatedRecordException {
// get it once
Date date = new Date();
date.setYear(1900);
BaseMessage message1 = new LastModifiedMessage("0000-0000-0000-0000", date);
Record r = orcid20ApiClient.fetchPublicRecord(message1);
assertEquals("http://orcid.org/0000-0000-0000-0000", r.getOrcidIdentifier().getPath());
// get it twice, if no error, then it's the cached version
when(mock_response.getEntity(Record.class)).thenThrow(new RuntimeException("called twice!"));
ActivitiesSummary s = orcid20ApiClient.fetchPublicActivities(message1);
assertEquals(s.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTitle().getContent(), "blah");
// get it with a different message, should return fresh
BaseMessage message2 = new LastModifiedMessage("0000-0000-0000-0000", new Date());
try {
s = orcid20ApiClient.fetchPublicActivities(message2);
fail("returned cached when it should get fresh");
} catch (RuntimeException e) {
if (e.getMessage() != "called twice!")
fail("something weird");
}
}
Aggregations