Skip to content

Commit

Permalink
Rollout cache integration tests (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Dec 5, 2024
1 parent 61c484a commit 71c81dd
Show file tree
Hide file tree
Showing 19 changed files with 346 additions and 51 deletions.
61 changes: 34 additions & 27 deletions src/androidTest/java/helper/IntegrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import fake.HttpClientMock;
import fake.HttpResponseMock;
Expand Down Expand Up @@ -390,40 +391,45 @@ public static <T> Set<T> asSet(T... elements) {
return result;
}

/**
* A simple interface to allow us to define the response for a given path
*/
public interface ResponseClosure {
HttpResponseMock onResponse(URI uri,
HttpMethod httpMethod,
String body);
public static long getTimestampDaysAgo(int days) {
return System.currentTimeMillis() - TimeUnit.DAYS.toMillis(days);
}

static String getSinceFromUri(URI uri) {
try {
return parse(uri.getQuery()).get("since");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

public static String getSinceFromUri(URI uri) {
try {
return parse(uri.getQuery()).get("since");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

static Map<String, String> parse(String query) throws UnsupportedEncodingException {
Map<String, String> queryPairs = new HashMap<>();
String[] pairs = query.split("&");
static Map<String, String> parse(String query) throws UnsupportedEncodingException {
Map<String, String> queryPairs = new HashMap<>();
String[] pairs = query.split("&");

for (String pair : pairs) {
int idx = pair.indexOf("=");
try {
String key = URLDecoder.decode(pair.substring(0, idx), "UTF-8");
String value = URLDecoder.decode(pair.substring(idx + 1), "UTF-8");
for (String pair : pairs) {
int idx = pair.indexOf("=");
try {
String key = URLDecoder.decode(pair.substring(0, idx), "UTF-8");
String value = URLDecoder.decode(pair.substring(idx + 1), "UTF-8");

queryPairs.put(key, value);
} catch (Exception e) {
e.printStackTrace();
}
queryPairs.put(key, value);
} catch (Exception e) {
e.printStackTrace();
}

return queryPairs;
}

return queryPairs;
}

/**
* A simple interface to allow us to define the response for a given path
*/
public interface ResponseClosure {
HttpResponseMock onResponse(URI uri,
HttpMethod httpMethod,
String body);
}

/**
Expand All @@ -435,5 +441,6 @@ public interface StreamingResponseClosure {

public static class ServicePath {
public static final String MEMBERSHIPS = "memberships";
public static final String SPLIT_CHANGES = "splitChanges";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static helper.IntegrationHelper.ResponseClosure.getSinceFromUri;

import static helper.IntegrationHelper.getSinceFromUri;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static helper.IntegrationHelper.ResponseClosure.getSinceFromUri;
import static helper.IntegrationHelper.getSinceFromUri;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tests.integration;

import static helper.IntegrationHelper.ResponseClosure.getSinceFromUri;
import static helper.IntegrationHelper.getSinceFromUri;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.lang.Thread.sleep;

import static helper.IntegrationHelper.ResponseClosure.getSinceFromUri;
import static helper.IntegrationHelper.getSinceFromUri;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static helper.IntegrationHelper.ResponseClosure.getSinceFromUri;
import static helper.IntegrationHelper.getSinceFromUri;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static helper.IntegrationHelper.ResponseClosure.getSinceFromUri;
import static helper.IntegrationHelper.getSinceFromUri;

import android.content.Context;

Expand Down
Loading

0 comments on commit 71c81dd

Please sign in to comment.