Search in sources :

Example 11 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class PaginatedRosieRepositoryTest method shouldPopulateCacheDataSourceAfterGetPageFromReadableDataSource.

@Test
public void shouldPopulateCacheDataSourceAfterGetPageFromReadableDataSource() throws Exception {
    Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
    givenCacheDataSourceReturnsNull(page);
    PaginatedCollection<AnyRepositoryValue> readableValues = givenReadableDataSourceReturnsValues(page);
    PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
    repository.getPage(page);
    verify(cacheDataSource).addOrUpdatePage(page, readableValues.getItems(), true);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 12 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class PaginatedRosieRepositoryTest method shouldReturnValuesFromReadableDataSourceIfPolicyForcesOnlyReadable.

@Test
public void shouldReturnValuesFromReadableDataSourceIfPolicyForcesOnlyReadable() throws Exception {
    Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
    givenCacheDataSourceReturnsValidValues(page);
    PaginatedCollection<AnyRepositoryValue> readableValues = givenReadableDataSourceReturnsValues(page);
    PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
    PaginatedCollection<AnyRepositoryValue> values = repository.getPage(page, ReadPolicy.READABLE_ONLY);
    assertEquals(readableValues, values);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 13 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class PaginatedRosieRepositoryTest method getSomeValues.

private PaginatedCollection<AnyRepositoryValue> getSomeValues(Page page) {
    LinkedList<AnyRepositoryValue> values = new LinkedList<>();
    for (int i = 0; i < 10; i++) {
        values.add(new AnyRepositoryValue(new AnyRepositoryKey(i)));
    }
    PaginatedCollection<AnyRepositoryValue> paginatedValues = new PaginatedCollection<>(values);
    paginatedValues.setHasMore(true);
    paginatedValues.setPage(page);
    return paginatedValues;
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) LinkedList(java.util.LinkedList)

Example 14 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class PaginatedRosieRepositoryTest method shouldReturnValuesFromReadableDataSourceIfCacheDataSourceIsNotValid.

@Test
public void shouldReturnValuesFromReadableDataSourceIfCacheDataSourceIsNotValid() throws Exception {
    Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
    givenCacheDataSourceReturnsNonValidValues(page);
    PaginatedCollection<AnyRepositoryValue> readableValues = givenReadableDataSourceReturnsValues(page);
    PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
    PaginatedCollection<AnyRepositoryValue> values = repository.getPage(page);
    assertEquals(readableValues, values);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 15 with AnyRepositoryKey

use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.

the class PaginatedRosieRepositoryTest method shouldDeleteCacheDataIfItemsAreNotValid.

@Test
public void shouldDeleteCacheDataIfItemsAreNotValid() throws Exception {
    Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
    givenCacheDataSourceReturnsNonValidValues(page);
    PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
    repository.getPage(page);
    verify(cacheDataSource).deleteAll();
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Aggregations

AnyRepositoryKey (com.karumi.rosie.doubles.AnyRepositoryKey)21 AnyRepositoryValue (com.karumi.rosie.doubles.AnyRepositoryValue)21 Test (org.junit.Test)18 Page (com.karumi.rosie.repository.datasource.paginated.Page)12 LinkedList (java.util.LinkedList)3