Skip to content

Commit 95397fe

Browse files
authored
Remove Wiremock (#22305)
* Bump wiremock to 2.35.0 * Entirely remove wiremock for now * Remove wiremock references
1 parent 82092c6 commit 95397fe

File tree

10 files changed

+6
-315
lines changed

10 files changed

+6
-315
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ updates:
2020
# Gutenberg. As such, and as agreed, any update is paused. For more details, see
2121
# https://github.com/wordpress-mobile/WordPress-Android/pull/17936#issuecomment-1553227875
2222
- dependency-name: "com.google.android.exoplayer:exoplayer"
23-
# Bumping 2.26.3 to 2.27.2 will break the mocks. For more details, see
24-
# https://github.com/wiremock/wiremock/issues/1345#issuecomment-656060968
25-
- dependency-name: "com.github.tomakehurst:wiremock"
2623
# List of React Native related dependencies that should be explicitly updated alongside a
2724
# React Native upgrade. For more details, see
2825
# https://github.com/wordpress-mobile/WordPress-Android/pull/18494#issuecomment-1566922244

WordPress/src/androidTest/java/org/wordpress/android/e2e/StatsTests.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import org.wordpress.android.e2e.pages.MySitesPage
1313
import org.wordpress.android.support.BaseTest
1414
import org.wordpress.android.support.ComposeEspressoLink
1515
import org.wordpress.android.support.WPSupportUtils
16-
import org.wordpress.android.wiremock.WireMockStub
17-
import org.wordpress.android.wiremock.WireMockUrlPath
1816

1917
@HiltAndroidTest
20-
class StatsTests : BaseTest(listOf(WireMockStub(urlPath = WireMockUrlPath.FEATURE_RESPONSE, fileName = "new-stats-feature-response.json"))) {
18+
class StatsTests : BaseTest() {
2119
@Before
2220
fun setUp() {
2321
Assume.assumeTrue(BuildConfig.IS_JETPACK_APP)

WordPress/src/androidTest/java/org/wordpress/android/support/BaseTest.java

Lines changed: 4 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
package org.wordpress.android.support;
22

3-
import android.app.Instrumentation;
4-
import android.util.Log;
53

6-
import androidx.annotation.Nullable;
4+
import androidx.annotation.NonNull;
75
import androidx.compose.ui.test.junit4.ComposeTestRule;
86
import androidx.test.espresso.accessibility.AccessibilityChecks;
97
import androidx.test.ext.junit.rules.ActivityScenarioRule;
10-
import androidx.test.platform.app.InstrumentationRegistry;
11-
12-
import com.fasterxml.jackson.databind.util.ISO8601Utils;
13-
import com.github.jknack.handlebars.Helper;
14-
import com.github.jknack.handlebars.Options;
15-
import com.github.tomakehurst.wiremock.client.WireMock;
16-
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
17-
import com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.DateOffset;
18-
import com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.HandlebarsHelper;
19-
import com.github.tomakehurst.wiremock.junit.WireMockRule;
8+
209
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult;
2110
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult.AccessibilityCheckResultType;
11+
import com.google.gson.internal.bind.util.ISO8601Utils;
2212

23-
import org.apache.commons.lang3.LocaleUtils;
2413
import org.hamcrest.Matcher;
2514
import org.hamcrest.Matchers;
2615
import org.junit.Before;
@@ -31,25 +20,17 @@
3120
import org.wordpress.android.e2e.flows.LoginFlow;
3221
import org.wordpress.android.e2e.pages.MePage;
3322
import org.wordpress.android.e2e.pages.MySitesPage;
34-
import org.wordpress.android.editor.Utils;
35-
import org.wordpress.android.mocks.AndroidNotifier;
36-
import org.wordpress.android.mocks.AssetFileSource;
3723
import org.wordpress.android.rules.RetryTestRule;
3824
import org.wordpress.android.ui.WPLaunchActivity;
39-
import org.wordpress.android.wiremock.WireMockStub;
4025

41-
import java.io.IOException;
4226
import java.text.SimpleDateFormat;
4327
import java.util.Date;
44-
import java.util.HashMap;
45-
import java.util.List;
4628
import java.util.Locale;
4729
import java.util.TimeZone;
4830

4931
import dagger.hilt.android.testing.HiltAndroidRule;
5032

5133
import static androidx.compose.ui.test.junit4.AndroidComposeTestRule_androidKt.createComposeRule;
52-
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
5334
import static com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesTypes;
5435
import static org.hamcrest.Matchers.anyOf;
5536
import static org.hamcrest.Matchers.is;
@@ -60,7 +41,6 @@
6041

6142
public class BaseTest {
6243
static final String TAG = BaseTest.class.getSimpleName();
63-
public static final int WIREMOCK_PORT = 8080;
6444

6545
@Rule(order = 0)
6646
public HiltAndroidRule mHiltRule = new HiltAndroidRule(this);
@@ -76,52 +56,8 @@ public class BaseTest {
7656
= new ActivityScenarioRule<>(WPLaunchActivity.class);
7757

7858
@Rule(order = 4)
79-
public WireMockRule wireMockRule;
80-
81-
@Rule(order = 5)
8259
public RetryTestRule retryTestRule = new RetryTestRule();
8360

84-
public BaseTest() {
85-
this(null);
86-
}
87-
88-
/**
89-
* Constructor
90-
*
91-
* @param wireMockStubs the wiremock stubs to use for this specific test.
92-
*/
93-
public BaseTest(@Nullable final List<WireMockStub> wireMockStubs) {
94-
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
95-
wireMockRule = new WireMockRule(
96-
options().port(WIREMOCK_PORT)
97-
.fileSource(
98-
new AssetFileSource(instrumentation.getContext().getAssets())
99-
)
100-
101-
.extensions(new ResponseTemplateTransformer(true, new HashMap<String, Helper>() {
102-
{
103-
put("fnow", new UnlocalizedDateHelper());
104-
}
105-
}))
106-
.notifier(new AndroidNotifier()));
107-
if (wireMockStubs != null && !wireMockStubs.isEmpty()) {
108-
for (WireMockStub wireMockStub : wireMockStubs) {
109-
try {
110-
final String result = Utils.getStringFromInputStream(
111-
instrumentation.getContext().getClassLoader().getResourceAsStream(
112-
wireMockStub.getFileName()
113-
)
114-
);
115-
// This is where we can stub out
116-
wireMockRule.stubFor(WireMock.get(WireMock.urlPathMatching(wireMockStub.getUrlPath().getPath()))
117-
.willReturn(WireMock.aResponse().withBody(result)));
118-
} catch (final Exception exception) {
119-
Log.e(TAG, "Problem stubbing endpoint", exception);
120-
}
121-
}
122-
}
123-
}
124-
12561
@Before
12662
public void setup() {
12763
Matcher<? super AccessibilityCheckResult> nonErrorLevelMatcher =
@@ -172,27 +108,6 @@ private void wpLogout() {
172108
}
173109
}
174110

175-
class UnlocalizedDateHelper extends HandlebarsHelper<Object> {
176-
@Override public Object apply(Object context, Options options) throws IOException {
177-
String format = options.hash("format", null);
178-
String offset = options.hash("offset", null);
179-
String timezone = options.hash("timezone", null);
180-
String localeCode = options.hash("locale", "en_US_POSIX");
181-
182-
Date date = new Date();
183-
if (offset != null) {
184-
date = new DateOffset(offset).shift(date);
185-
}
186-
187-
Locale locale = Locale.getDefault();
188-
if (localeCode != null) {
189-
locale = LocaleUtils.toLocale(localeCode);
190-
}
191-
192-
return new LocaleAwareRenderableDate(date, format, timezone, locale);
193-
}
194-
}
195-
196111
class LocaleAwareRenderableDate {
197112
private static final long DIVIDE_MILLISECONDS_TO_SECONDS = 1000L;
198113

@@ -208,7 +123,7 @@ class LocaleAwareRenderableDate {
208123
this.mLocale = locale;
209124
}
210125

211-
@Override
126+
@NonNull @Override
212127
public String toString() {
213128
if (mFormat != null) {
214129
if (mFormat.equals("epoch")) {

WordPress/src/androidTest/java/org/wordpress/android/support/MockingInterceptor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class MockingInterceptor : Interceptor {
1616
val newUrl = request.url.newBuilder()
1717
.scheme("http")
1818
.host("localhost")
19-
.port(BaseTest.WIREMOCK_PORT)
2019
.build()
2120
val newRequest = request.newBuilder()
2221
.url(newUrl)

WordPress/src/androidTest/java/org/wordpress/android/util/StatsMocksReader.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ class StatsMocksReader {
88
MutableList<StatsKeyValueData> {
99
val todayMarker = "{{now format='yyyy-MM-dd'}}"
1010
val readString = this.readAssetsFile("mocks/mappings/wpcom/stats/$fileName.json")
11-
val wireMockJSON = JSONObject(readString)
12-
val arrayRaw = wireMockJSON
11+
val arrayRaw = JSONObject(readString)
1312
.getJSONObject("response")
1413
.getJSONObject("jsonBody")
1514
.getJSONObject("days")

WordPress/src/androidTest/java/org/wordpress/android/wiremock/WireMockStub.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ squareup-kotlin-poet = '1.18.1'
9898
squareup-okhttp3 = '5.2.1'
9999
squareup-retrofit = '3.0.0'
100100
wellsql = '2.0.0'
101-
wiremock = '2.26.3'
102101
wordpress-aztec = 'v2.1.4'
103102
wordpress-lint = '2.2.0'
104103
wordpress-persistent-edittext = '1.0.2'
@@ -257,7 +256,6 @@ squareup-okhttp3-urlconnection = { module = "com.squareup.okhttp3:okhttp-urlconn
257256
squareup-retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "squareup-retrofit" }
258257
wellsql = { module = "org.wordpress:wellsql", version.ref = "wellsql" }
259258
wellsql-processor = { module = "org.wordpress.wellsql:wellsql-processor", version.ref = "wellsql" }
260-
wiremock = { group = "com.github.tomakehurst", name = "wiremock", version.ref = "wiremock" }
261259
wordpress-lint = { group = "org.wordpress", name = "lint", version.ref = "wordpress-lint" }
262260
wordpress-persistent-edittext = { group = "org.wordpress", name = "persistentedittext", version.ref = "wordpress-persistent-edittext" }
263261
wordpress-rs-android = { group = "rs.wordpress.api", name = "android", version.ref = "wordpress-rs" }

libs/mocks/build.gradle

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,3 @@ android {
1212
compileSdk rootProject.compileSdkVersion
1313
}
1414
}
15-
16-
dependencies {
17-
api(libs.wiremock.get().module.toString()) {
18-
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
19-
exclude group: 'org.apache.commons', module: 'commons-lang3'
20-
exclude group: 'asm', module: 'asm'
21-
exclude group: 'org.json', module: 'json'
22-
}
23-
runtimeOnly(libs.apache.http.client.android)
24-
25-
constraints {
26-
implementation(libs.wiremock) {
27-
because("newer versions of WireMock use Java APIs not available on Android")
28-
}
29-
30-
def wireMockSecurity = "version shipped with WireMock 2.26.3 contains security vulnerabilities"
31-
32-
implementation(libs.jetty.webapp) {
33-
because(wireMockSecurity)
34-
}
35-
implementation(libs.jackson.databind) {
36-
because(wireMockSecurity)
37-
}
38-
implementation(libs.json.path) {
39-
because(wireMockSecurity)
40-
}
41-
implementation(libs.commons.fileupload) {
42-
because(wireMockSecurity)
43-
}
44-
}
45-
}

libs/mocks/src/main/java/org/wordpress/android/mocks/AndroidNotifier.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)