Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ApolloExceptions #379

Merged
merged 4 commits into from
Apr 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.apollographql.android.impl.normalizer.EpisodeHeroName;
import com.apollographql.android.impl.normalizer.HeroAndFriendsNamesWithIDs;
import com.apollographql.android.impl.normalizer.type.Episode;
import com.apollographql.apollo.exception.ApolloException;

import junit.framework.Assert;

Expand Down Expand Up @@ -57,7 +58,7 @@ public class ApolloWatcherTest {

@Test
public void testQueryWatcherUpdated_SameQuery_DifferentResults() throws IOException, InterruptedException,
TimeoutException {
TimeoutException, ApolloException {
final NamedCountDownLatch firstResponseLatch = new NamedCountDownLatch("firstResponseLatch", 1);
final NamedCountDownLatch secondResponseLatch = new NamedCountDownLatch("secondResponseLatch", 2);

Expand All @@ -77,7 +78,7 @@ public void testQueryWatcherUpdated_SameQuery_DifferentResults() throws IOExcept
secondResponseLatch.countDown();
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
firstResponseLatch.countDown();
secondResponseLatch.countDown();
Expand Down Expand Up @@ -113,7 +114,7 @@ public void testQueryWatcherNotUpdated_SameQuery_SameResults() throws IOExceptio
}
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
firstResponseLatch.countDown();
secondResponseLatch.countDown();
Expand All @@ -131,7 +132,7 @@ public void testQueryWatcherNotUpdated_SameQuery_SameResults() throws IOExceptio

@Test
public void testQueryWatcherUpdated_DifferentQuery_DifferentResults() throws IOException, InterruptedException,
TimeoutException {
TimeoutException, ApolloException {
final NamedCountDownLatch firstResponseLatch = new NamedCountDownLatch("firstResponseLatch", 1);
final NamedCountDownLatch secondResponseLatch = new NamedCountDownLatch("secondResponseLatch", 2);

Expand All @@ -151,7 +152,7 @@ public void testQueryWatcherUpdated_DifferentQuery_DifferentResults() throws IOE
secondResponseLatch.countDown();
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
firstResponseLatch.countDown();
secondResponseLatch.countDown();
Expand Down Expand Up @@ -187,7 +188,7 @@ public void testQueryWatcherNotUpdated_DifferentQueries() throws IOException, In
}
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
firstResponseLatch.countDown();
secondResponseLatch.countDown();
Expand Down Expand Up @@ -226,7 +227,7 @@ public void rewatchCacheControl() throws IOException, InterruptedException, Time
secondResponseLatch.countDown();
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
firstResponseLatch.countDown();
secondResponseLatch.countDown();
Expand Down Expand Up @@ -254,7 +255,7 @@ public void testQueryWatcherUpdated_SameQuery_DifferentResults_cacheOnly() throw
cacheWarmUpLatch.countDown();
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
cacheWarmUpLatch.countDown();
}
Expand All @@ -281,7 +282,7 @@ public void testQueryWatcherUpdated_SameQuery_DifferentResults_cacheOnly() throw
secondResponseLatch.countDown();
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
Assert.fail(e.getMessage());
firstResponseLatch.countDown();
secondResponseLatch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.apollographql.apollo.cache.normalized.CacheKeyResolver;
import com.apollographql.android.impl.normalizer.EpisodeHeroName;
import com.apollographql.android.impl.normalizer.type.Episode;
import com.apollographql.apollo.exception.ApolloException;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -54,11 +55,11 @@ public class AsyncNormalizedCacheTestCase {
.build();
}

private MockResponse mockResponse(String fileName) throws IOException {
private MockResponse mockResponse(String fileName) throws IOException, ApolloException {
return new MockResponse().setChunkedBody(Utils.readFileToString(getClass(), "/" + fileName), 32);
}

@Test public void testAsync() throws IOException, InterruptedException {
@Test public void testAsync() throws IOException, InterruptedException, ApolloException {
EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();

server.enqueue(mockResponse("HeroNameResponse.json"));
Expand All @@ -78,7 +79,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
latch.countDown();
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
fail("unexpected error: " + e);
latch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.apollographql.apollo;

import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.cache.http.DiskLruCacheStore;
import com.apollographql.apollo.internal.cache.http.HttpCache;
import com.apollographql.apollo.cache.http.HttpCacheControl;
import com.apollographql.apollo.cache.http.TimeoutEvictionStrategy;
import com.apollographql.android.impl.httpcache.AllFilms;
import com.apollographql.android.impl.httpcache.AllPlanets;
import com.apollographql.android.impl.httpcache.DroidDetails;
import com.apollographql.android.impl.httpcache.type.CustomType;
import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.cache.http.DiskLruCacheStore;
import com.apollographql.apollo.cache.http.HttpCacheControl;
import com.apollographql.apollo.cache.http.TimeoutEvictionStrategy;
import com.apollographql.apollo.exception.ApolloException;
import com.apollographql.apollo.exception.ApolloHttpException;
import com.apollographql.apollo.internal.cache.http.HttpCache;
import com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor;

import junit.framework.Assert;
Expand Down Expand Up @@ -102,8 +104,8 @@ public class CacheTest {
Response<AllPlanets.Data> body = apolloClient.newCall(new AllPlanets())
.httpCacheControl(HttpCacheControl.NETWORK_ONLY).execute();
assertThat(body.isSuccessful()).isTrue();
fail("expected IOException");
} catch (IOException expected) {
fail("expected ApolloException");
} catch (ApolloException expected) {
}

checkNoCachedResponse();
Expand Down Expand Up @@ -180,7 +182,7 @@ public class CacheTest {
try {
apolloClient.newCall(new AllPlanets()).httpCacheControl(HttpCacheControl.CACHE_ONLY).execute();
Assert.fail("expected to fail with HttpException");
} catch (HttpException expected) {
} catch (ApolloHttpException expected) {
} catch (Exception e) {
fail("expected to fail with HttpException");
}
Expand Down Expand Up @@ -267,14 +269,14 @@ public class CacheTest {
checkCachedResponse("/HttpCacheTestAllPlanets2.json");
}

@Test public void fileSystemUnavailable() throws IOException {
@Test public void fileSystemUnavailable() throws IOException, ApolloException {
cacheStore.delegate = new DiskLruCacheStore(new NoFileSystem(), new File("/cache/"), Integer.MAX_VALUE);
enqueueResponse("/HttpCacheTestAllPlanets.json");
assertThat(apolloClient.newCall(new AllPlanets()).execute().isSuccessful()).isTrue();
checkNoCachedResponse();
}

@Test public void fileSystemWriteFailure() throws IOException {
@Test public void fileSystemWriteFailure() throws IOException, ApolloException {
FaultyCacheStore faultyCacheStore = new FaultyCacheStore(FileSystem.SYSTEM);
cacheStore.delegate = faultyCacheStore;

Expand All @@ -289,7 +291,7 @@ public class CacheTest {
checkNoCachedResponse();
}

@Test public void fileSystemReadFailure() throws IOException {
@Test public void fileSystemReadFailure() throws IOException, ApolloException {
FaultyCacheStore faultyCacheStore = new FaultyCacheStore(inMemoryFileSystem);
cacheStore.delegate = faultyCacheStore;

Expand All @@ -312,7 +314,7 @@ public class CacheTest {
assertThat(server.getRequestCount()).isEqualTo(2);
}

@Test public void prefetchDefault() throws IOException {
@Test public void prefetchDefault() throws IOException, ApolloException {
enqueueResponse("/HttpCacheTestAllPlanets.json");
apolloClient.prefetch(new AllPlanets()).execute();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
Expand All @@ -321,8 +323,8 @@ public class CacheTest {
assertThat(apolloClient.newCall(new AllPlanets()).httpCacheControl(HttpCacheControl.CACHE_ONLY).execute().isSuccessful()).isTrue();
}

@Test public void prefetchNoCacheStore() throws IOException {
ApolloClient apolloClient = ApolloClient.builder()
@Test public void prefetchNoCacheStore() throws IOException, ApolloException {
ApolloClient apolloClient = ApolloClient.builder()
.serverUrl(server.url("/"))
.okHttpClient(okHttpClient)
.build();
Expand Down Expand Up @@ -356,7 +358,7 @@ public class CacheTest {
checkNoCachedResponse();
}

@Test public void expireAfterRead() throws IOException {
@Test public void expireAfterRead() throws IOException, ApolloException {
enqueueResponse("/HttpCacheTestAllPlanets.json");
assertThat(apolloClient.newCall(new AllPlanets()).execute().isSuccessful()).isTrue();
checkCachedResponse("/HttpCacheTestAllPlanets.json");
Expand All @@ -375,7 +377,7 @@ public class CacheTest {
checkCachedResponse("/HttpCacheTestAllPlanets.json");
}

@Test public void cacheNetworkError() throws IOException {
@Test public void cacheNetworkError() throws IOException, ApolloException {
server.enqueue(new MockResponse().setResponseCode(504).setBody(""));
try {
apolloClient.newCall(new AllPlanets()).execute();
Expand Down Expand Up @@ -417,7 +419,7 @@ private void checkCachedResponse(String fileName) throws IOException {
String cacheKey = ApolloServerInterceptor.cacheKey(lastHttRequest.body());
okhttp3.Response response = apolloClient.cachedHttpResponse(cacheKey);
assertThat(response).isNotNull();
assertThat(response.body().source().readUtf8()).isEqualTo(Utils.readFileToString(getClass(),fileName));
assertThat(response.body().source().readUtf8()).isEqualTo(Utils.readFileToString(getClass(), fileName));
response.body().source().close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.apollographql.android.impl.httpcache.type.CustomType;
import com.apollographql.apollo.api.Error;
import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.exception.ApolloException;

import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -174,7 +175,7 @@ public class IntegrationTest {
latch.countDown();
}

@Override public void onFailure(@Nonnull Throwable e) {
@Override public void onFailure(@Nonnull ApolloException e) {
latch.countDown();
Assert.fail("expected success");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import android.support.annotation.NonNull;

import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.cache.normalized.CacheControl;
import com.apollographql.apollo.cache.normalized.CacheKey;
import com.apollographql.apollo.cache.normalized.CacheKeyResolver;
import com.apollographql.android.impl.normalizer.EpisodeHeroName;
import com.apollographql.android.impl.normalizer.HeroAndFriendsNames;
import com.apollographql.android.impl.normalizer.HeroAndFriendsNamesWithIDForParentOnly;
Expand All @@ -15,6 +11,11 @@
import com.apollographql.android.impl.normalizer.HeroTypeDependentAliasedField;
import com.apollographql.android.impl.normalizer.SameHeroTwice;
import com.apollographql.android.impl.normalizer.type.Episode;
import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.cache.normalized.CacheControl;
import com.apollographql.apollo.cache.normalized.CacheKey;
import com.apollographql.apollo.cache.normalized.CacheKeyResolver;
import com.apollographql.apollo.exception.ApolloException;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -61,7 +62,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
return new MockResponse().setChunkedBody(Utils.readFileToString(getClass(), "/" + fileName), 32);
}

@Test public void episodeHeroName() throws IOException {
@Test public void episodeHeroName() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroNameResponse.json"));

EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();
Expand All @@ -74,7 +75,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().name()).isEqualTo("R2-D2");
}

@Test public void heroAndFriendsNameResponse() throws IOException {
@Test public void heroAndFriendsNameResponse() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroAndFriendsNameResponse.json"));

HeroAndFriendsNames query = HeroAndFriendsNames.builder().episode(Episode.JEDI).build();
Expand All @@ -91,7 +92,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().friends().get(2).name()).isEqualTo("Leia Organa");
}

@Test public void heroAndFriendsNamesWithIDs() throws IOException {
@Test public void heroAndFriendsNamesWithIDs() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroAndFriendsNameWithIdsResponse.json"));

HeroAndFriendsNamesWithIDs query = HeroAndFriendsNamesWithIDs.builder().episode(Episode.NEWHOPE).build();
Expand All @@ -112,7 +113,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().friends().get(2).name()).isEqualTo("Leia Organa");
}

@Test public void heroAndFriendsNameWithIdsForParentOnly() throws IOException {
@Test public void heroAndFriendsNameWithIdsForParentOnly() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroAndFriendsNameWithIdsParentOnlyResponse.json"));

HeroAndFriendsNamesWithIDForParentOnly query = HeroAndFriendsNamesWithIDForParentOnly.builder()
Expand All @@ -131,7 +132,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().friends().get(2).name()).isEqualTo("Leia Organa");
}

@Test public void heroAppearsInResponse() throws IOException {
@Test public void heroAppearsInResponse() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroAppearsInResponse.json"));

HeroAppearsIn query = new HeroAppearsIn();
Expand All @@ -147,7 +148,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().appearsIn().get(2).name()).isEqualTo("JEDI");
}

@Test public void heroParentTypeDependentField() throws IOException {
@Test public void heroParentTypeDependentField() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroParentTypeDependentFieldDroidResponse.json"));

HeroParentTypeDependentField query = HeroParentTypeDependentField.builder().episode(Episode.NEWHOPE).build();
Expand All @@ -165,7 +166,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().asDroid().friends().get(0).asHuman().height()).isWithin(1.72);
}

@Test public void heroTypeDependentAliasedField() throws IOException {
@Test public void heroTypeDependentAliasedField() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroTypeDependentAliasedFieldResponse.json"));

HeroTypeDependentAliasedField query = HeroTypeDependentAliasedField.builder().episode(Episode.NEWHOPE).build();
Expand All @@ -189,7 +190,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().asHuman().property()).isEqualTo("Tatooine");
}

@Test public void sameHeroTwice() throws IOException {
@Test public void sameHeroTwice() throws IOException, ApolloException {
server.enqueue(mockResponse("SameHeroTwiceResponse.json"));

SameHeroTwice query = new SameHeroTwice();
Expand All @@ -206,7 +207,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().r2().appearsIn().get(2).name()).isEqualTo("JEDI");
}

@Test public void cacheFirst() throws IOException {
@Test public void cacheFirst() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroNameResponse.json"));

EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();
Expand All @@ -219,7 +220,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().name()).isEqualTo("R2-D2");
}

@Test public void cacheOnly() throws IOException {
@Test public void cacheOnly() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroNameResponse.json"));

EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();
Expand All @@ -232,7 +233,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().name()).isEqualTo("R2-D2");
}

@Test public void networkFirst() throws IOException {
@Test public void networkFirst() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroNameResponse.json"));

EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();
Expand All @@ -253,7 +254,7 @@ private MockResponse mockResponse(String fileName) throws IOException {
assertThat(body.data().hero().name()).isEqualTo("R2-D2");
}

@Test public void networkOnly() throws IOException {
@Test public void networkOnly() throws IOException, ApolloException {
server.enqueue(mockResponse("HeroNameResponse.json"));

EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();
Expand Down
Loading