|
1 | 1 | package com.segment.analytics;
|
2 | 2 |
|
3 | 3 |
|
| 4 | +import static org.assertj.core.api.Assertions.assertThat; |
4 | 5 | import static org.junit.Assert.fail;
|
5 | 6 |
|
6 | 7 | import android.support.test.rule.ActivityTestRule;
|
7 | 8 | import android.support.test.runner.AndroidJUnit4;
|
8 |
| -import com.segment.analytics.runscope.MessageResponse; |
9 |
| -import com.segment.analytics.runscope.MessagesResponse; |
10 |
| -import com.segment.analytics.runscope.RunscopeService; |
| 9 | +import com.segment.analytics.webhook.WebhookService; |
11 | 10 | import com.segment.analytics.sample.MainActivity;
|
12 | 11 | import com.segment.analytics.sample.test.BuildConfig;
|
13 | 12 | import com.segment.backo.Backo;
|
14 | 13 | import java.io.IOException;
|
| 14 | +import java.util.List; |
15 | 15 | import java.util.UUID;
|
16 | 16 | import java.util.concurrent.TimeUnit;
|
| 17 | +import okhttp3.Credentials; |
17 | 18 | import okhttp3.Interceptor;
|
18 | 19 | import okhttp3.OkHttpClient;
|
19 | 20 | import org.junit.After;
|
@@ -50,43 +51,40 @@ public class E2ETest {
|
50 | 51 | * https://app.segment.com/segment-libraries/sources/analytics_android_e2e_test/overview
|
51 | 52 | */
|
52 | 53 | private static final String SEGMENT_WRITE_KEY = "OAtgAHjkAD5MP31srDe9wiBjpvcXC8De";
|
53 |
| - /** |
54 |
| - * Runscope bucket that is connect to the Segment project. |
55 |
| - * https://www.runscope.com/radar/uy22axz4sdb8 |
56 |
| - */ |
57 |
| - private static final String RUNSCOPE_BUCKET = "uy22axz4sdb8"; |
58 |
| - // Token to read data from the Runscope bucket. |
59 |
| - private static final String RUNSCOPE_TOKEN = BuildConfig.RUNSCOPE_TOKEN; |
| 54 | + /** Webhook bucket that is connected to the Segment project. */ |
| 55 | + private static final String WEBHOOK_BUCKET = "android"; |
| 56 | + /** Credentials to retrieve data from the webhook. */ |
| 57 | + private static final String WEBHOOK_AUTH_USERNAME = BuildConfig.WEBHOOK_AUTH_USERNAME; |
60 | 58 |
|
61 | 59 | private static final Backo BACKO = Backo.builder()
|
62 | 60 | .base(TimeUnit.SECONDS, 1)
|
63 | 61 | .cap(TimeUnit.SECONDS, 5)
|
64 | 62 | .build();
|
65 | 63 |
|
66 | 64 | private Analytics analytics;
|
67 |
| - private RunscopeService runscopeService; |
| 65 | + private WebhookService webhookService; |
68 | 66 |
|
69 | 67 | @Before
|
70 | 68 | public void setup() {
|
71 | 69 | analytics = new Analytics.Builder(activityActivityTestRule.getActivity(), SEGMENT_WRITE_KEY)
|
72 | 70 | .build();
|
73 | 71 |
|
74 |
| - runscopeService = new Retrofit.Builder() |
75 |
| - .baseUrl("https://api.runscope.com") |
| 72 | + webhookService = new Retrofit.Builder() |
| 73 | + .baseUrl("https://webhook-e2e.segment.com") |
76 | 74 | .addConverterFactory(MoshiConverterFactory.create())
|
77 | 75 | .client(new OkHttpClient.Builder()
|
78 | 76 | .addNetworkInterceptor(new Interceptor() {
|
79 | 77 | @Override
|
80 | 78 | public okhttp3.Response intercept(Chain chain) throws IOException {
|
81 | 79 | return chain.proceed(chain.request()
|
82 | 80 | .newBuilder()
|
83 |
| - .addHeader("Authorization", "Bearer " + RUNSCOPE_TOKEN) |
| 81 | + .addHeader("Authorization", Credentials.basic(WEBHOOK_AUTH_USERNAME, "")) |
84 | 82 | .build());
|
85 | 83 | }
|
86 | 84 | })
|
87 | 85 | .build())
|
88 | 86 | .build()
|
89 |
| - .create(RunscopeService.class); |
| 87 | + .create(WebhookService.class); |
90 | 88 | }
|
91 | 89 |
|
92 | 90 | @After
|
@@ -146,21 +144,19 @@ private void assertMessageReceivedByWebhook(String id) {
|
146 | 144 | }
|
147 | 145 |
|
148 | 146 | /**
|
149 |
| - * Returns {@code true} if a message with the provided ID is found in Runscope. |
| 147 | + * Returns {@code true} if a message with the provided ID is found in the webhook. |
150 | 148 | */
|
151 | 149 | @SuppressWarnings("ConstantConditions")
|
152 | 150 | private boolean hasMatchingRequest(String id) throws IOException {
|
153 |
| - Response<MessagesResponse> messagesResponse = runscopeService |
154 |
| - .messages(RUNSCOPE_BUCKET) |
| 151 | + Response<List<String>> messagesResponse = webhookService |
| 152 | + .messages(WEBHOOK_BUCKET, 500) |
155 | 153 | .execute();
|
156 | 154 |
|
157 |
| - for (MessagesResponse.Message message : messagesResponse.body().data) { |
158 |
| - Response<MessageResponse> messageResponse = runscopeService |
159 |
| - .message(RUNSCOPE_BUCKET, message.uuid) |
160 |
| - .execute(); |
| 155 | + assertThat(messagesResponse.code()).isEqualTo(200); |
161 | 156 |
|
| 157 | + for (String message : messagesResponse.body()) { |
162 | 158 | // TODO: Deserialize into Segment message and check against properties.
|
163 |
| - if (messageResponse.body().data.request.body.contains(id)) { |
| 159 | + if (message.contains(id)) { |
164 | 160 | return true;
|
165 | 161 | }
|
166 | 162 | }
|
|
0 commit comments