Search in sources :

Example 1 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class ProvidersDynamicsKeysRxCacheTest method Pagination.

@Test
public void Pagination() {
    TestObserver<List<io.rx_cache2.internal.Mock>> testObserver;
    List<io.rx_cache2.internal.Mock> mocksPage1 = createMocks(SIZE);
    String mockPage1Value = mocksPage1.get(0).getMessage();
    testObserver = providersRxCache.getMocksPaginate(Observable.just(mocksPage1), new DynamicKey(1)).test();
    testObserver.awaitTerminalEvent();
    List<io.rx_cache2.internal.Mock> mocksPage2 = createMocks(SIZE);
    String mockPage2Value = mocksPage2.get(0).getMessage();
    testObserver = providersRxCache.getMocksPaginate(Observable.just(mocksPage2), new DynamicKey(2)).test();
    testObserver.awaitTerminalEvent();
    List<io.rx_cache2.internal.Mock> mocksPage3 = createMocks(SIZE);
    String mockPage3Value = mocksPage3.get(0).getMessage();
    testObserver = providersRxCache.getMocksPaginate(Observable.just(mocksPage3), new DynamicKey(3)).test();
    testObserver.awaitTerminalEvent();
    testObserver = providersRxCache.getMocksPaginate(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(1)).test();
    testObserver.awaitTerminalEvent();
    assertThat(testObserver.values().get(0).get(0).getMessage(), is(mockPage1Value));
    testObserver = providersRxCache.getMocksPaginate(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(2)).test();
    testObserver.awaitTerminalEvent();
    assertThat(testObserver.values().get(0).get(0).getMessage(), is(mockPage2Value));
    testObserver = providersRxCache.getMocksPaginate(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(3)).test();
    testObserver.awaitTerminalEvent();
    assertThat(testObserver.values().get(0).get(0).getMessage(), is(mockPage3Value));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 2 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class ProxyTranslatorTest method When_Get_Page_Get_Pages.

@Test
public void When_Get_Page_Get_Pages() throws NoSuchMethodException {
    Object[] dataMethodPaginate = { Observable.just(new Object[] {}), new DynamicKey(1) };
    Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMocksPaginate", Observable.class, DynamicKey.class);
    ConfigProvider configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodPaginate);
    assertThat(configProvider.getDynamicKey(), is("1"));
}
Also used : ConfigProvider(io.rx_cache2.ConfigProvider) Method(java.lang.reflect.Method) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 3 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class ProxyTranslatorTest method When_Evict_Cache_Dynamic_Key_Evict.

@Test
public void When_Evict_Cache_Dynamic_Key_Evict() throws NoSuchMethodException {
    final String dynamicKey = "aDynamicKey";
    Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMocksDynamicKeyEvictPage", Observable.class, DynamicKey.class, EvictDynamicKey.class);
    Object[] dataMethodEvict = { Observable.just(new Object[] {}), new DynamicKey(dynamicKey), new EvictDynamicKey(true) };
    ConfigProvider configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodEvict);
    EvictDynamicKey evictDynamicKey = (EvictDynamicKey) configProvider.evictProvider();
    assertThat(configProvider.getDynamicKey(), is(dynamicKey));
    assertThat(evictDynamicKey.evict(), is(true));
    Object[] dataMethodNoEvict = { Observable.just(new Object[] {}), new DynamicKey(dynamicKey), new EvictDynamicKey(false) };
    configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodNoEvict);
    evictDynamicKey = (EvictDynamicKey) configProvider.evictProvider();
    assertThat(configProvider.getDynamicKey(), is(dynamicKey));
    assertThat(evictDynamicKey.evict(), is(false));
}
Also used : ConfigProvider(io.rx_cache2.ConfigProvider) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Method(java.lang.reflect.Method) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 4 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class ProxyTranslatorTest method When_Use_Evict_Dynamic_Key_Providing_Dynamic_Key_Not_Throw_Exception.

@Test
public void When_Use_Evict_Dynamic_Key_Providing_Dynamic_Key_Not_Throw_Exception() throws NoSuchMethodException {
    Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMockEvictDynamicKeyProvidingDynamicKey", Observable.class, DynamicKey.class, EvictDynamicKey.class);
    Object[] data = { Observable.just(new Object[] {}), new DynamicKey("1"), new EvictDynamicKey(true) };
    proxyTranslatorUT.processMethod(mockMethod, data);
}
Also used : EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Method(java.lang.reflect.Method) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 5 with DynamicKey

use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.

the class ProxyTranslator method getDynamicKey.

private String getDynamicKey(Method method, Object[] objectsMethod) {
    DynamicKey dynamicKey = getObjectFromMethodParam(method, DynamicKey.class, objectsMethod);
    if (dynamicKey != null)
        return dynamicKey.getDynamicKey().toString();
    DynamicKeyGroup dynamicKeyGroup = getObjectFromMethodParam(method, DynamicKeyGroup.class, objectsMethod);
    if (dynamicKeyGroup != null)
        return dynamicKeyGroup.getDynamicKey().toString();
    return "";
}
Also used : DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) DynamicKey(io.rx_cache2.DynamicKey)

Aggregations

DynamicKey (io.rx_cache2.DynamicKey)8 EvictDynamicKey (io.rx_cache2.EvictDynamicKey)7 Test (org.junit.Test)6 Method (java.lang.reflect.Method)4 ConfigProvider (io.rx_cache2.ConfigProvider)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TestObserver (io.reactivex.observers.TestObserver)1 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)1 EvictProvider (io.rx_cache2.EvictProvider)1 Reply (io.rx_cache2.Reply)1 Record (io.rx_cache2.internal.Record)1