GithubHelp home page GithubHelp logo

Comments (6)

tomakehurst avatar tomakehurst commented on August 19, 2024

You can new up WireMock in addition to calling static methods on it e.g.
WireMock wireMock = new WireMock("localhost", "8082");
then create stubs like this:
wireMock.register(get(urlEqualTo("/test")).willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello world!")));

Does that help?

from wiremock.

tobyweston avatar tobyweston commented on August 19, 2024

Yep, thanks. I suspect they'll be more problems with the mismatch of static vs my instance. Do you recommend a particular way?

I'd still need the WireMockServer though right; if I'm new'ing up a WireMock as you suggest?

from wiremock.

tomakehurst avatar tomakehurst commented on August 19, 2024

I tend to use the instance approach if I'm wrapping wiremock inside another
class e.g. MyServiceStub. That way a number of these can co-habit provided
the ports don't clash.

Yes, you still need to run the server in this setup. The WireMock class is
just client code.
On 14 Mar 2013 20:15, "Toby" [email protected] wrote:

Yep, thanks. I suspect they'll be more problems with the mismatch of
static vs my instance. Do you recommend a particular way?

I'd still need the WireMockServer though right; if I'm new'ing up a
WireMock as you suggest?


Reply to this email directly or view it on GitHubhttps://github.com//issues/18#issuecomment-14926428
.

from wiremock.

mangotang avatar mangotang commented on August 19, 2024

That is some nice code.

 


Steven Barkdull
[email protected]


From: tomakehurst [email protected]
To: tomakehurst/wiremock [email protected]
Sent: Thursday, March 14, 2013 3:13 PM
Subject: Re: [wiremock] Question: Avoiding the static defaultInstance of WireMock (#18)

You can new up WireMock in addition to calling static methods on it e.g.
WireMock wireMock = new WireMock("localhost", "8082");
then create stubs like this:
wireMock.register(get(urlEqualTo("/test")).willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello world!")));
Does that help?

Reply to this email directly or view it on GitHub.

from wiremock.

tukaaa avatar tukaaa commented on August 19, 2024

Hi there, I'm trying to achieve a similar thing, but I don't seem to find the right code for it; if I try something like this:

public MockedService(int port) {
    wireMock = new WireMock("localhost", port);
    wireMock.register(get(urlMatching("/process/?param1=.*&param2=.*"))
            .willReturn(aResponse()
                    .withBody(GenericMediaResponse.RESPONSE_OK.toJSONString()))
            );

     }

I get a ConnectionRefused issue.I would basically like to use WireMock to have a standalone embedded server that I can use as a test service for external tests, but I'm not sure how to hook handlers to WireMockServer and the relationship between WireMock and WireMockServer?

from wiremock.

tomakehurst avatar tomakehurst commented on August 19, 2024

WireMock is just the client part, so for this to work you'd need to run the server up from the command line, new up an instance of WireMockServer and start it or usr the @rule

from wiremock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.