Migrate tests to webhook-e2e
Since Runscope has shut down this product, migrate to our own webhook-e2e replacement.
Start testing on Nexus 6 too, but don't test on multiple locales/orientations.
MODIFY
.circleci/config.yml
.circleci/config.yml
@@ -18,7 +18,7 @@ jobs:
name: Copy E2E Test Credentials
command: |
if [ "${RUN_E2E_TESTS}" == "true" ]; then
- echo "RUNSCOPE_TOKEN=${RUNSCOPE_TOKEN}" >> "analytics-samples/analytics-sample/e2e_test.properties"
+ echo "WEBHOOK_AUTH_USERNAME=${WEBHOOK_AUTH_USERNAME}" >> "analytics-samples/analytics-sample/e2e_test.properties"
fi
- run:
name: Build
@@ -32,7 +32,7 @@ jobs:
unzip -qq google-cloud-sdk.zip
./google-cloud-sdk/bin/gcloud config set project analytics-android-e2e-test
./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file secret.json
- ./google-cloud-sdk/bin/gcloud firebase test android run --app analytics-samples/analytics-sample/build/outputs/apk/debug/analytics-sample-debug.apk --test analytics-samples/analytics-sample/build/outputs/apk/androidTest/debug/analytics-sample-debug-androidTest.apk --device-ids sailfish,hammerhead --os-version-ids 19,21,22,23,24,25,26,27 --locales en,fr --orientations portrait
+ ./google-cloud-sdk/bin/gcloud firebase test android run --app analytics-samples/analytics-sample/build/outputs/apk/debug/analytics-sample-debug.apk --test analytics-samples/analytics-sample/build/outputs/apk/androidTest/debug/analytics-sample-debug-androidTest.apk --device-ids Nexus6,hammerhead,sailfish --os-version-ids 19,21,22,23,24,25,26,27
fi
- save_cache:
paths:

MODIFY
analytics-samples/analytics-sample/build.gradle
analytics-samples/analytics-sample/build.gradle
@@ -3,15 +3,15 @@ apply plugin: 'com.f2prateek.javafmt'
apply from: rootProject.file('gradle/android.gradle')
-def RUNSCOPE_TOKEN = ""
+def WEBHOOK_AUTH_USERNAME = ""
def RUN_E2E_TESTS = false
-// e2e_test.properties is a file with a single line: RUNSCOPE_TOKEN=<token>
+// e2e_test.properties is a file with a single line: WEBHOOK_AUTH_USERNAME=<token>
def e2eTestPropertiesFile = file('e2e_test.properties')
if (e2eTestPropertiesFile.exists()) {
def props = new Properties()
file(e2eTestPropertiesFile).withInputStream { stream -> props.load(stream) }
- RUNSCOPE_TOKEN = props.getProperty("RUNSCOPE_TOKEN")
+ WEBHOOK_AUTH_USERNAME = props.getProperty("WEBHOOK_AUTH_USERNAME")
RUN_E2E_TESTS = true
}
@@ -24,7 +24,7 @@ android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- buildConfigField 'String', 'RUNSCOPE_TOKEN', "\"$RUNSCOPE_TOKEN\""
+ buildConfigField 'String', 'WEBHOOK_AUTH_USERNAME', "\"$WEBHOOK_AUTH_USERNAME\""
buildConfigField 'boolean', 'RUN_E2E_TESTS', "$RUN_E2E_TESTS"
}
}
@@ -44,4 +44,6 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.segment.backo:backo:1.0.0'
+
+ androidTestImplementation 'org.assertj:assertj-core:1.7.1'
}

MODIFY
analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/E2ETest.java
analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/E2ETest.java
package com.segment.analytics;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
-import com.segment.analytics.runscope.MessageResponse;
-import com.segment.analytics.runscope.MessagesResponse;
-import com.segment.analytics.runscope.RunscopeService;
+import com.segment.analytics.webhook.WebhookService;
import com.segment.analytics.sample.MainActivity;
import com.segment.analytics.sample.test.BuildConfig;
import com.segment.backo.Backo;
import java.io.IOException;
+import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import okhttp3.Credentials;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import org.junit.After;
@@ -50,13 +51,10 @@ public class E2ETest {
* https://app.segment.com/segment-libraries/sources/analytics_android_e2e_test/overview
*/
private static final String SEGMENT_WRITE_KEY = "OAtgAHjkAD5MP31srDe9wiBjpvcXC8De";
- /**
- * Runscope bucket that is connect to the Segment project.
- * https://www.runscope.com/radar/uy22axz4sdb8
- */
- private static final String RUNSCOPE_BUCKET = "uy22axz4sdb8";
- // Token to read data from the Runscope bucket.
- private static final String RUNSCOPE_TOKEN = BuildConfig.RUNSCOPE_TOKEN;
+ /** Webhook bucket that is connected to the Segment project. */
+ private static final String WEBHOOK_BUCKET = "android";
+ /** Credentials to retrieve data from the webhook. */
+ private static final String WEBHOOK_AUTH_USERNAME = BuildConfig.WEBHOOK_AUTH_USERNAME;
private static final Backo BACKO = Backo.builder()
.base(TimeUnit.SECONDS, 1)
@@ -64,15 +62,15 @@ public class E2ETest {
.build();
private Analytics analytics;
- private RunscopeService runscopeService;
+ private WebhookService webhookService;
@Before
public void setup() {
analytics = new Analytics.Builder(activityActivityTestRule.getActivity(), SEGMENT_WRITE_KEY)
.build();
- runscopeService = new Retrofit.Builder()
- .baseUrl("https://api.runscope.com")
+ webhookService = new Retrofit.Builder()
+ .baseUrl("https://webhook-e2e.segment.com")
.addConverterFactory(MoshiConverterFactory.create())
.client(new OkHttpClient.Builder()
.addNetworkInterceptor(new Interceptor() {
@@ -80,13 +78,13 @@ public class E2ETest {
public okhttp3.Response intercept(Chain chain) throws IOException {
return chain.proceed(chain.request()
.newBuilder()
- .addHeader("Authorization", "Bearer " + RUNSCOPE_TOKEN)
+ .addHeader("Authorization", Credentials.basic(WEBHOOK_AUTH_USERNAME, ""))
.build());
}
})
.build())
.build()
- .create(RunscopeService.class);
+ .create(WebhookService.class);
}
@After
@@ -146,21 +144,19 @@ public class E2ETest {
}
/**
- * Returns {@code true} if a message with the provided ID is found in Runscope.
+ * Returns {@code true} if a message with the provided ID is found in the webhook.
*/
@SuppressWarnings("ConstantConditions")
private boolean hasMatchingRequest(String id) throws IOException {
- Response<MessagesResponse> messagesResponse = runscopeService
- .messages(RUNSCOPE_BUCKET)
+ Response<List<String>> messagesResponse = webhookService
+ .messages(WEBHOOK_BUCKET, 500)
.execute();
- for (MessagesResponse.Message message : messagesResponse.body().data) {
- Response<MessageResponse> messageResponse = runscopeService
- .message(RUNSCOPE_BUCKET, message.uuid)
- .execute();
+ assertThat(messagesResponse.code()).isEqualTo(200);
+ for (String message : messagesResponse.body()) {
// TODO: Deserialize into Segment message and check against properties.
- if (messageResponse.body().data.request.body.contains(id)) {
+ if (message.contains(id)) {
return true;
}
}

DELETE
analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/runscope/MessageResponse.java
-package com.segment.analytics.runscope;
-
-public class MessageResponse {
- public static class Message {
- public static class Request {
- public String body;
- }
-
- public Request request;
- }
-
- public Message data;
-}

DELETE
analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/runscope/MessagesResponse.java
-package com.segment.analytics.runscope;
-
-import java.util.List;
-
-public class MessagesResponse {
- public static class Message {
- public String uuid;
- }
-
- public List<Message> data;
-}

DELETE
analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/runscope/RunscopeService.java
-package com.segment.analytics.runscope;
-
-import retrofit2.Call;
-import retrofit2.http.GET;
-import retrofit2.http.Path;
-
-public interface RunscopeService {
- @GET("buckets/{bucket}/messages")
- Call<MessagesResponse> messages(@Path("bucket") String bucket);
-
- @GET("buckets/{bucket}/messages/{message}")
- Call<MessageResponse> message(@Path("bucket") String bucket,
- @Path("message") String message);
-}

ADD
analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/webhook/WebhookService.java
+package com.segment.analytics.webhook;
+
+import java.util.List;
+import retrofit2.Call;
+import retrofit2.http.GET;
+import retrofit2.http.Path;
+import retrofit2.http.Query;
+
+public interface WebhookService {
+ @GET("buckets/{bucket}")
+ Call<List<String>> messages(@Path("bucket") String bucket, @Query("limit") int limit);
+}

Migrate tests to webhook-e2e

Since Runscope has shut down this product, migrate to our own webhook-e2e replacement.

Start testing on Nexus 6 too, but don't test on multiple locales/orientations.