Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mappings from class path not working #65

Open
ZIRAKrezovic opened this issue Nov 20, 2024 · 1 comment
Open

Mappings from class path not working #65

ZIRAKrezovic opened this issue Nov 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ZIRAKrezovic
Copy link

ZIRAKrezovic commented Nov 20, 2024

Proposal

I am migrating from wiremock-spring-boot 2.x to 3.x.

Our mappings are located as specified by previous wiremock-spring-boot

src/main/resources/wiremock/wiremock-server-name/mappings

Content of the mapping file

{
  "mappings": [
    {
      "request": {
        "method": "GET",
        "url": "/test"
      },

      "response": {
        "status": 200,
        "jsonBody": {
          "payload": []
        },
        "headers": {
          "Content-Type": "application/json"
        }
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "/test2"
      },

      "response": {
        "status": 200,
        "jsonBody": {
          "payload": []
        },
        "headers": {
          "Content-Type": "application/json"
        }
      }
    }
  ]
}

According to changelog, I should use filesUnderClasspath as a replacement for 2.x stubLocation

Used annotations for for 2.x (implicitly sets stubLocation to wiremock/myapp/mappings)

@EnableWireMock(@ConfigureWireMock(name = "myapp", properties = "wiremock.server.baseUrl"))

Used annotations for 3.x

@EnableWireMock(@ConfigureWireMock(name = "myapp", filesUnderClasspath = "wiremock/myapp/mappings"))

Log output when starting wiremock with 3.x

2024-11-20T08:43:26.193+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Looking for mocks in classpath /wiremock/myapp/mappings/myapp... 
2024-11-20T08:43:26.194+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Looking for mocks in classpath /wiremock/myapp/mappings... found
2024-11-20T08:43:26.195+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Serving WireMock mappings from classpath resource: wiremock/myapp/mappings
2024-11-20T08:43:26.198+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Configuring WireMockServer with name 'myapp' on HTTP port: 0 and HTTPS port: -1
2024-11-20T08:43:26.918+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Started WireMockServer with name 'myapp':http://localhost:57265
2024-11-20T08:43:26.919+01:00  INFO 21004 --- [demo] [           main] org.wiremock.spring.internal.Store       : Resolving store from context: demo
2024-11-20T08:43:26.919+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Adding property 'wiremock.server.baseUrl=http://localhost:57265' with HTTP base URL to Spring application context
2024-11-20T08:43:26.921+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Adding property 'wiremock.server.port=57265' with HTTP port to Spring application context

However, call to wiremock-url/test results in

2024-11-20T08:43:29.039+01:00  INFO 21004 --- [demo] [qtp971404566-58] WireMock myapp                           : Request received:
127.0.0.1 - GET /test

Accept-Encoding: [gzip]
User-Agent: [ReactorNetty/1.1.23]
Host: [localhost:57265]
Accept: [*/*]
WebTestClient-Request-Id: [1]



Matched response definition:
(no response definition configured)

Response:
HTTP/1.1 404
(no headers)

2024-11-20T08:43:29.041+01:00 ERROR 21004 --- [demo] [qtp971404566-58] WireMock myapp                           : No response could be served as there are no stub mappings in this WireMock instance.

With previous version, it results in

2024-11-20T08:50:48.199+01:00  INFO 17568 --- [demo] [tp1964514128-58] WireMock                                 : Request received:
127.0.0.1 - GET /test

Accept-Encoding: [gzip]
User-Agent: [ReactorNetty/1.1.23]
Host: [localhost:57532]
Accept: [*/*]
WebTestClient-Request-Id: [1]



Matched response definition:
{
  "status" : 200,
  "jsonBody" : {
    "payload" : [ ]
  },
  "headers" : {
    "Content-Type" : "application/json"
  }
}

Response:
HTTP/1.1 200
Content-Type: [application/json]
Matched-Stub-Id: [babcb672-1a42-47fe-b93d-e5fa2d02580c]

Reproduction steps

I have set up a reproducer at https://github.com/ZIRAKrezovic/wiremock-spring-reproducer

There are two tests, one for 2.x and one for 3.x.

References

No response

@ZIRAKrezovic ZIRAKrezovic added the bug Something isn't working label Nov 20, 2024
@tomasbjerre
Copy link
Collaborator

This works:

@EnableWireMock(@ConfigureWireMock(name = "myapp", filesUnderClasspath = "wiremock/myapp"))
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

But I totally agree that the behavior here is strange. With the logging:

2024-11-20T08:43:26.194+01:00  INFO 21004 --- [demo] [           main] c.w.s.i.WireMockServerCreator myapp      : Looking for mocks in classpath /wiremock/myapp/mappings... found

Now it just checks to see if the resource exsits, not if it is a WireMock mappings root folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants