Search in sources :

Example 6 with RecordCorrection

use of org.orcid.model.record_correction.RecordCorrection in project ORCID-Source by ORCID.

the class RecordCorrectionsManagerReadOnlyTest method getElementsDescendingTest.

@Test
public void getElementsDescendingTest() {
    // Page 1
    RecordCorrectionsPage page1 = manager.getInvalidRecordDataChangesDescending(10L, 4L);
    assertNotNull(page1);
    assertEquals(Long.valueOf(10), page1.getFirstElementId());
    assertEquals(Long.valueOf(7), page1.getLastElementId());
    assertTrue(page1.getHaveNext());
    assertFalse(page1.getHavePrevious());
    assertNotNull(page1.getRecordCorrections());
    assertEquals(4, page1.getRecordCorrections().size());
    Long currentId = null;
    for (RecordCorrection element : page1.getRecordCorrections()) {
        if (currentId == null) {
            assertEquals(page1.getFirstElementId(), element.getSequence());
            currentId = element.getSequence();
        } else {
            assertTrue((currentId - 1) == element.getSequence());
            currentId = element.getSequence();
        }
    }
    assertEquals(page1.getLastElementId(), currentId);
    // Page 2
    RecordCorrectionsPage page2 = manager.getInvalidRecordDataChangesDescending(page1.getLastElementId() - 1, 4L);
    assertNotNull(page2);
    assertEquals(Long.valueOf(6), page2.getFirstElementId());
    assertEquals(Long.valueOf(3), page2.getLastElementId());
    assertTrue(page2.getHaveNext());
    assertTrue(page2.getHavePrevious());
    assertNotNull(page2.getRecordCorrections());
    assertEquals(4, page2.getRecordCorrections().size());
    currentId = null;
    for (RecordCorrection element : page2.getRecordCorrections()) {
        if (currentId == null) {
            assertEquals(page2.getFirstElementId(), element.getSequence());
            currentId = element.getSequence();
        } else {
            assertTrue((currentId - 1) == element.getSequence());
            currentId = element.getSequence();
        }
    }
    assertEquals(page2.getLastElementId(), currentId);
    //Page 3
    RecordCorrectionsPage page3 = manager.getInvalidRecordDataChangesDescending(page2.getLastElementId() - 1, 4L);
    assertNotNull(page3);
    assertEquals(Long.valueOf(2), page3.getFirstElementId());
    assertEquals(Long.valueOf(1), page3.getLastElementId());
    assertFalse(page3.getHaveNext());
    assertTrue(page3.getHavePrevious());
    assertEquals(2, page3.getRecordCorrections().size());
    currentId = null;
    for (RecordCorrection element : page3.getRecordCorrections()) {
        if (currentId == null) {
            assertEquals(page3.getFirstElementId(), element.getSequence());
            currentId = element.getSequence();
        } else {
            assertTrue((currentId - 1) == element.getSequence());
            currentId = element.getSequence();
        }
    }
    assertEquals(page3.getLastElementId(), currentId);
}
Also used : RecordCorrectionsPage(org.orcid.model.record_correction.RecordCorrectionsPage) RecordCorrection(org.orcid.model.record_correction.RecordCorrection) Test(org.junit.Test)

Aggregations

RecordCorrection (org.orcid.model.record_correction.RecordCorrection)6 RecordCorrectionsPage (org.orcid.model.record_correction.RecordCorrectionsPage)4 InvalidRecordDataChangeEntity (org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity)4 Test (org.junit.Test)3 Cacheable (org.springframework.cache.annotation.Cacheable)2 MapperFactory (ma.glasnost.orika.MapperFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1