Search in sources :

Example 1 with Logger

use of com.apollographql.apollo.Logger in project apollo-android by apollographql.

the class ApolloServerInterceptorTest method testDefaultHttpCall.

@Test
public void testDefaultHttpCall() throws Exception {
    Predicate<Request> requestAssertPredicate = new Predicate<Request>() {

        @Override
        public boolean apply(@Nullable Request request) {
            assertThat(request).isNotNull();
            assertDefaultRequestHeaders(request);
            assertThat(request.header(HttpCache.CACHE_KEY_HEADER)).isNull();
            assertThat(request.header(HttpCache.CACHE_FETCH_STRATEGY_HEADER)).isNull();
            assertThat(request.header(HttpCache.CACHE_EXPIRE_TIMEOUT_HEADER)).isNull();
            assertThat(request.header(HttpCache.CACHE_EXPIRE_AFTER_READ_HEADER)).isNull();
            assertThat(request.header(HttpCache.CACHE_PREFETCH_HEADER)).isNull();
            assertRequestBody(request);
            return true;
        }
    };
    ApolloServerInterceptor interceptor = new ApolloServerInterceptor(serverUrl, new AssertHttpCallFactory(requestAssertPredicate), null, false, new ScalarTypeAdapters(Collections.<ScalarType, CustomTypeAdapter>emptyMap()), new ApolloLogger(Optional.<Logger>absent()), false);
    interceptor.httpCall(query);
}
Also used : ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) ScalarTypeAdapters(com.apollographql.apollo.response.ScalarTypeAdapters) CustomTypeAdapter(com.apollographql.apollo.response.CustomTypeAdapter) Request(okhttp3.Request) ScalarType(com.apollographql.apollo.api.ScalarType) ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) Logger(com.apollographql.apollo.Logger) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 2 with Logger

use of com.apollographql.apollo.Logger in project apollo-android by apollographql.

the class ApolloServerInterceptorTest method testCachedHttpCall.

@Test
public void testCachedHttpCall() throws Exception {
    Predicate<Request> requestAssertPredicate = new Predicate<Request>() {

        @Override
        public boolean apply(@Nullable Request request) {
            assertThat(request).isNotNull();
            assertDefaultRequestHeaders(request);
            assertThat(request.header(HttpCache.CACHE_KEY_HEADER)).isEqualTo("1f2f23bb27630f5795166091713e18a1");
            assertThat(request.header(HttpCache.CACHE_FETCH_STRATEGY_HEADER)).isEqualTo("NETWORK_FIRST");
            assertThat(request.header(HttpCache.CACHE_EXPIRE_TIMEOUT_HEADER)).isEqualTo("10000");
            assertThat(request.header(HttpCache.CACHE_EXPIRE_AFTER_READ_HEADER)).isEqualTo("false");
            assertThat(request.header(HttpCache.CACHE_PREFETCH_HEADER)).isEqualTo("false");
            assertRequestBody(request);
            return true;
        }
    };
    ApolloServerInterceptor interceptor = new ApolloServerInterceptor(serverUrl, new AssertHttpCallFactory(requestAssertPredicate), HttpCachePolicy.NETWORK_FIRST.expireAfter(10, TimeUnit.SECONDS), false, new ScalarTypeAdapters(Collections.<ScalarType, CustomTypeAdapter>emptyMap()), new ApolloLogger(Optional.<Logger>absent()), false);
    interceptor.httpCall(query);
}
Also used : ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) ScalarTypeAdapters(com.apollographql.apollo.response.ScalarTypeAdapters) CustomTypeAdapter(com.apollographql.apollo.response.CustomTypeAdapter) Request(okhttp3.Request) ScalarType(com.apollographql.apollo.api.ScalarType) ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) Logger(com.apollographql.apollo.Logger) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 3 with Logger

use of com.apollographql.apollo.Logger in project apollo-android by apollographql.

the class ApolloStoreTest method storeClearAllCallsNormalizedCacheClearAll.

@Test
public void storeClearAllCallsNormalizedCacheClearAll() throws Exception {
    final NamedCountDownLatch latch = new NamedCountDownLatch("storeClearAllCallsNormalizedCacheClearAll", 1);
    final RealApolloStore realApolloStore = new RealApolloStore(new NormalizedCache() {

        @Nullable
        @Override
        public Record loadRecord(@Nonnull String key, @Nonnull CacheHeaders cacheHeaders) {
            return null;
        }

        @Nonnull
        @Override
        public Set<String> merge(@Nonnull Record record, @Nonnull CacheHeaders cacheHeaders) {
            return emptySet();
        }

        @Override
        public void clearAll() {
            latch.countDown();
        }

        @Override
        public boolean remove(@Nonnull CacheKey cacheKey) {
            return false;
        }

        @Nonnull
        @Override
        protected Set<String> performMerge(@Nonnull Record apolloRecord, @Nonnull CacheHeaders cacheHeaders) {
            return emptySet();
        }
    }, CacheKeyResolver.DEFAULT, new ScalarTypeAdapters(Collections.EMPTY_MAP), Executors.newSingleThreadExecutor(), new ApolloLogger(Optional.<Logger>absent()));
    realApolloStore.clearAll().execute();
    latch.awaitOrThrowWithTimeout(3, TimeUnit.SECONDS);
}
Also used : Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) Nonnull(javax.annotation.Nonnull) NamedCountDownLatch(com.apollographql.apollo.NamedCountDownLatch) ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) Logger(com.apollographql.apollo.Logger) ApolloLogger(com.apollographql.apollo.internal.ApolloLogger) ScalarTypeAdapters(com.apollographql.apollo.response.ScalarTypeAdapters) CacheHeaders(com.apollographql.apollo.cache.CacheHeaders) NormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCache) Record(com.apollographql.apollo.cache.normalized.Record) Nullable(javax.annotation.Nullable) CacheKey(com.apollographql.apollo.cache.normalized.CacheKey) Test(org.junit.Test)

Aggregations

Logger (com.apollographql.apollo.Logger)3 ApolloLogger (com.apollographql.apollo.internal.ApolloLogger)3 ScalarTypeAdapters (com.apollographql.apollo.response.ScalarTypeAdapters)3 Nullable (javax.annotation.Nullable)3 Test (org.junit.Test)3 ScalarType (com.apollographql.apollo.api.ScalarType)2 CustomTypeAdapter (com.apollographql.apollo.response.CustomTypeAdapter)2 Predicate (com.google.common.base.Predicate)2 Request (okhttp3.Request)2 NamedCountDownLatch (com.apollographql.apollo.NamedCountDownLatch)1 CacheHeaders (com.apollographql.apollo.cache.CacheHeaders)1 CacheKey (com.apollographql.apollo.cache.normalized.CacheKey)1 NormalizedCache (com.apollographql.apollo.cache.normalized.NormalizedCache)1 Record (com.apollographql.apollo.cache.normalized.Record)1 Collections.emptySet (java.util.Collections.emptySet)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1