WireMock 2.0-beta Android Support #330

Merged
merged 1 commit into from Dec 8, 2015

Conversation

Projects
None yet
3 participants
@handstandsam
Contributor

handstandsam commented Dec 8, 2015

With the following change, WireMock 2.0-beta successfully runs on Android.

I was able to successfully create an ActivityInstrumentationTestCase2 using the @RunWith(AndroidJUnit4.class) class level annotation and the following WireMockRule:

@Rule
public WireMockRule wireMockRule = new WireMockRule();

I did a lot of combinations of dependencies as I tried to figure out how to make this work, but when I simplified it down, the modification to make this work on android was VERY simple. Thanks @tomakehurst for the great work.

How
The only thing that wasn't supported was the StringEntity constructor that was being used in HttpAdminClient. I reverted back to a constructor that was available on the 4.3.5.1 version of Android version of the Apache HttpClient and then manually set ContentType.

Notes

android {
    useLibrary 'org.apache.http.legacy'
}

Usage In Validation
I am only using the .withBody() rule and have not figured out how to implement at .withBodyFile() rule out of the Android Assets directory, but it worked great by sending the body itself instead.

@handstandsam

This comment has been minimized.

Show comment
Hide comment
@handstandsam

handstandsam Dec 8, 2015

Contributor

I'm trying to integrate this with another application I have using the Android ApplicationTestCase and am not getting this working yet. I'm not saying this is a blocker, but it might be good to have a reference to an example project showing this working before the PR is accepted. I will update as/when I can.

Contributor

handstandsam commented Dec 8, 2015

I'm trying to integrate this with another application I have using the Android ApplicationTestCase and am not getting this working yet. I'm not saying this is a blocker, but it might be good to have a reference to an example project showing this working before the PR is accepted. I will update as/when I can.

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Dec 8, 2015

Owner

No worries, let me know when you're ready and I'll merge.

Would you consider raising another PR at some point with an additional Gradle file to build an APK?

Owner

tomakehurst commented Dec 8, 2015

No worries, let me know when you're ready and I'll merge.

Would you consider raising another PR at some point with an additional Gradle file to build an APK?

@yogurtearl

This comment has been minimized.

Show comment
Hide comment
@yogurtearl

yogurtearl Dec 8, 2015

This will support Android API 19+ ( i.e. Android 4.4+ ).
Also, I vote for keeping wiremock 2 on Jetty 9.2 to enable continued use on Android.

Jetty 9.3+ needs Java 8+, which will make Android support difficult.

This will support Android API 19+ ( i.e. Android 4.4+ ).
Also, I vote for keeping wiremock 2 on Jetty 9.2 to enable continued use on Android.

Jetty 9.3+ needs Java 8+, which will make Android support difficult.

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Dec 8, 2015

Owner

We're staying with Jetty 9.2 in order to keep JDK 7 runtime compatibility, so no worries there.

Owner

tomakehurst commented Dec 8, 2015

We're staying with Jetty 9.2 in order to keep JDK 7 runtime compatibility, so no worries there.

@handstandsam

This comment has been minimized.

Show comment
Hide comment
@handstandsam

handstandsam Dec 8, 2015

Contributor

Repo containing 2 Android WireMock tests as well as a test for "MockWebServer" for okhttp.

One WireMock test for ApplicationTestCase and one for ``ActivityInstrumentationTestCase2`.

https://github.com/handstandsam/AndroidHttpMockingExamples

@tomakehurst - I can look into another PR at some point in the future, but don't have the time right now.

Contributor

handstandsam commented Dec 8, 2015

Repo containing 2 Android WireMock tests as well as a test for "MockWebServer" for okhttp.

One WireMock test for ApplicationTestCase and one for ``ActivityInstrumentationTestCase2`.

https://github.com/handstandsam/AndroidHttpMockingExamples

@tomakehurst - I can look into another PR at some point in the future, but don't have the time right now.

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Dec 8, 2015

Owner

So is there more to come on this PR, or are we good to merge?

Owner

tomakehurst commented Dec 8, 2015

So is there more to come on this PR, or are we good to merge?

@handstandsam

This comment has been minimized.

Show comment
Hide comment
@handstandsam

handstandsam Dec 8, 2015

Contributor

We are good to merge this. This is all that is needed :-)

Contributor

handstandsam commented Dec 8, 2015

We are good to merge this. This is all that is needed :-)

tomakehurst added a commit that referenced this pull request Dec 8, 2015

@tomakehurst tomakehurst merged commit 88c55ee into tomakehurst:2.0-beta Dec 8, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment