Search in sources :

Example 1 with BaseMessage

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");
    }
}
Also used : BaseMessage(org.orcid.utils.listener.BaseMessage) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) Date(java.util.Date) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) Test(org.junit.Test)

Example 2 with BaseMessage

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");
    }
}
Also used : BaseMessage(org.orcid.utils.listener.BaseMessage) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) Record(org.orcid.jaxb.model.record_v2.Record) Date(java.util.Date) Test(org.junit.Test)

Example 3 with BaseMessage

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");
    }
}
Also used : BaseMessage(org.orcid.utils.listener.BaseMessage) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) Record(org.orcid.jaxb.model.record_v2.Record) Date(java.util.Date) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) Test(org.junit.Test)

Aggregations

Date (java.util.Date)3 Test (org.junit.Test)3 BaseMessage (org.orcid.utils.listener.BaseMessage)3 LastModifiedMessage (org.orcid.utils.listener.LastModifiedMessage)3 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)2 Record (org.orcid.jaxb.model.record_v2.Record)2