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

BUG: DateTime Matcher with custom format throws error #1882

Closed
3 tasks
vbearn opened this issue May 23, 2022 · 0 comments
Closed
3 tasks

BUG: DateTime Matcher with custom format throws error #1882

vbearn opened this issue May 23, 2022 · 0 comments
Labels

Comments

@vbearn
Copy link

vbearn commented May 23, 2022

  • Which version of WireMock you're using:
    Latest Docker Version (2.33.2 as of now, digest 4fa551f46a...)

  • How you're starting and configuring WireMock, including configuration or CLI the command line:
    By running docker run -it --rm -p 8080:8080 -v C:\DataC\Temp\mappings:/home/wiremock --name wiremock wiremock/wiremock:2.33.2

  • A failing test case that demonstrates the problem:
    Add these two mappings (either through the __admin api or through the mapped folder in hard drive):

Mapping A

{
    "priority": 1,
    "request": {
        "urlPath": "/api/TestA",
        "method": "GET",
        "queryParameters": {
            "caseNumber": {
                "actualFormat": "yyyyMMdd-HHmm-ss'xx-mock-guidxxxxxxxx'",
                "before": "now -30 seconds"
            }
        }
    },
    "response": {
        "status": 200,
        "jsonBody": {
            "ResultCode": "Approved"
        }
    }
}

Mapping B

{
    "priority": 1,
    "request": {
        "urlPath": "/api/TestB",
        "method": "GET"
    },
    "response": {
        "status": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "jsonBody": {
            "ResultCode": "Approved"
        }
    }
}

Test it with query 1 (which will work as expected):
GET http://localhost:8080/api/TestA?caseNumber=20220523-0800-25xx-mock-guidxxxxxxxx

THE BUG: If test with query 2:
GET /api/TestB

the Wiremock will throw the error:

java.lang.NullPointerException: text
	at java.base/java.util.Objects.requireNonNull(Unknown Source)
	at java.base/java.time.format.DateTimeFormatter.parse(Unknown Source)
	at java.base/java.time.ZonedDateTime.parse(Unknown Source)
	at com.github.tomakehurst.wiremock.common.DateTimeParser.parseZonedDateTime(DateTimeParser.java:77)
	at com.github.tomakehurst.wiremock.matching.AbstractDateTimePattern.parseZonedOrNull(AbstractDateTimePattern.java:248)
	at com.github.tomakehurst.wiremock.matching.AbstractDateTimePattern.parseZonedOrNull(AbstractDateTimePattern.java:238)
	at com.github.tomakehurst.wiremock.matching.AbstractDateTimePattern.match(AbstractDateTimePattern.java:205)
	at com.github.tomakehurst.wiremock.matching.AbstractDateTimePattern.match(AbstractDateTimePattern.java:31)
	at com.github.tomakehurst.wiremock.matching.MultiValuePattern$1.apply(MultiValuePattern.java:76)
	at com.github.tomakehurst.wiremock.matching.MultiValuePattern$1.apply(MultiValuePattern.java:74)
	at wiremock.com.google.common.collect.Lists$TransformingRandomAccessList$1.transform(Lists.java:625)
	at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52)
	at java.base/java.util.Collections.min(Unknown Source)
	at com.github.tomakehurst.wiremock.matching.MultiValuePattern.getBestMatch(MultiValuePattern.java:80)
	at com.github.tomakehurst.wiremock.matching.MultiValuePattern.match(MultiValuePattern.java:51)
	at com.github.tomakehurst.wiremock.matching.RequestPattern$4.apply(RequestPattern.java:325)
	at com.github.tomakehurst.wiremock.matching.RequestPattern$4.apply(RequestPattern.java:320)
	at wiremock.com.google.common.collect.Iterators$6.transform(Iterators.java:829)
	at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52)
	at wiremock.com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:278)
	at wiremock.com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:239)
	at wiremock.com.google.common.collect.FluentIterable.toList(FluentIterable.java:631)
	at com.github.tomakehurst.wiremock.matching.RequestPattern.allQueryParamsMatch(RequestPattern.java:328)
	at com.github.tomakehurst.wiremock.matching.RequestPattern.access$600(RequestPattern.java:43)
	at com.github.tomakehurst.wiremock.matching.RequestPattern$1.match(RequestPattern.java:102)
	at com.github.tomakehurst.wiremock.matching.RequestPattern$1.match(RequestPattern.java:90)
	at com.github.tomakehurst.wiremock.matching.RequestPattern.match(RequestPattern.java:226)
	at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings$3.apply(InMemoryStubMappings.java:231)
	at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings$3.apply(InMemoryStubMappings.java:229)
	at wiremock.com.google.common.collect.Iterators.find(Iterators.java:758)
	at wiremock.com.google.common.collect.Iterables.find(Iterables.java:693)
	at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings.serveFor(InMemoryStubMappings.java:76)
	at com.github.tomakehurst.wiremock.core.WireMockApp.serveStubFor(WireMockApp.java:226)
	at com.github.tomakehurst.wiremock.http.StubRequestHandler.handleRequest(StubRequestHandler.java:57)
	at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:69)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:142)
	at wiremock.javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at wiremock.org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)
	at wiremock.org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1631)
	at wiremock.org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at wiremock.org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at wiremock.org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355)
	at wiremock.org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at wiremock.org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:763)
	at wiremock.org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
	at wiremock.org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at wiremock.org.eclipse.jetty.server.Server.handle(Server.java:516)
	at wiremock.org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487)
	at wiremock.org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732)
	at wiremock.org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479)
	at wiremock.org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
	at wiremock.org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at wiremock.org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
	at wiremock.org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
	at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338)
	at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315)
	at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173)
	at wiremock.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
	at wiremock.org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409)
	at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)
	at wiremock.org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)
	at java.base/java.lang.Thread.run(Unknown Source)

Observations:

  • Interestingly, executing query 1 against Mapping A which includes the custom date matcher "actualFormat": "yyyyMMdd-HHmm-ss'xx-mock-guidxxxxxxxx'" does work as expected without any bug, but the other unrelated endpoint breaks, persumably because it is wrongly searching for a (non-existing) query parameter

  • Playing around with the priority field doesn't make a difference in the resulting error, unfortunately

klaasdellschaft added a commit to klaasdellschaft/wiremock that referenced this issue Jul 12, 2022
- Adding failing test cases
- Apply a fix for the failing test cases
klaasdellschaft added a commit to klaasdellschaft/wiremock that referenced this issue Jul 13, 2022
- Use "1.0" as match distance where realistically no distance can be calculated
- Apply Spotless checks
klaasdellschaft added a commit to klaasdellschaft/wiremock that referenced this issue Jul 14, 2022
- Use "1.0" as match distance where realistically no distance can be calculated
- Apply Spotless checks
klaasdellschaft added a commit to klaasdellschaft/wiremock that referenced this issue Jul 14, 2022
- Use "1.0" as match distance where realistically no distance can be calculated
- Apply Spotless checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants