``` "queryParameters": { "fq": { "inclu...
# help
m
Copy code
"queryParameters": {
    "fq": {
      "includes": [
        {
          "equalTo": "(type:\"news\")"
        },
        {
          "doesNotContain": "newsStartYear"
        }
      ]
    },
From the docs I expect that one of the
fq
parameters must be equal to
type:"news")
, but none of them must contain
newsStartYear
. In my tests neither
doesNotContain
nor
doesNotMatch
work like that. For all "positive" matchers
includes
works like a logical AND, but all negative have no effect for me. What am I doing wrong?
a
What version of WireMock?
m
3.0.3
I am mocking Solr which can take many filter query (fq) arguments
a
Is there a reason you couldn’t use
and
instead of
includes
?
I’m on 2.35.0 and the following works:
Copy code
{
  "request": {
    "urlPath": "/things",
    "method": "GET",
    "queryParameters": {
      "id": {
        "and": [
          {
            "contains": "2"
          },
          {
            "doesNotContain": "3"
          }
        ]
      }
    }
  },
  "response": {
    "status": 200
  }
}
but the following won’t even build:
Copy code
{
  "request": {
    "urlPath": "/things",
    "method": "GET",
    "queryParameters": {
      "id": {
        "includes": [
          {
            "contains": "2"
          },
          {
            "doesNotContain": "3"
          }
        ]
      }
    }
  },
  "response": {
    "status": 200
  }
}
m
I'n fairly new to Wiremock. I understand your example with and that there is only one parameter id that must contain 2 but not 3. The other should mean that there is one id parameter that contains 2, but none of the other id parameters contains 3. At least that is what I want Wiremock to do.
a
Ah! So your request could be something like
<http://www.foo.com/things?fq=1&fq=2&fq=3>
?
m
that's the real deal 😉
Copy code
facet.field={!ex%3DfaqCategory}faqCategory&facet.field={!ex%3DnewsCategory}newsCategory&facet.field={!ex%3DpublicationCategory}publicationCategory&<http://json.nl|json.nl>=flat&f.newsCategory.facet.sort=index&fl=*,score&start=0&f.faqCategory.facet.sort=index&sort=newsStarttimeStamp+asc&fq=siteHash:"f849f0f9bbe6858353def4124139e591f8be4591"&fq={!typo3access}-1,0&fq=(type:"tx_news_domain_model_news")&fq=(newsIsEvent:"false")&fq=(newsStartYear:"2023")&rows=10&facet.limit=100&json.facet={"type":{"type":"terms","field":"type","limit":100,"mincount":1},"newsStartYear":{"type":"terms","field":"newsStartYear","limit":100,"mincount":1},"newsIsEvent":{"type":"terms","field":"newsIsEvent","limit":100,"mincount":1},"programChannel":{"type":"terms","field":"programChannel","limit":100,"mincount":1},"programType":{"type":"terms","field":"programType","limit":100,"mincount":1},"programs":{"type":"terms","field":"programPrograms","limit":100,"mincount":1,"domain":{"excludeTags":"programPrograms"}},"category":{"type":"terms","field":"category","limit":100,"mincount":1},"doktype":{"type":"terms","field":"doktype","limit":100,"mincount":1},"jobType":{"type":"terms","field":"jobType","limit":100,"mincount":1},"publicationYear":{"type":"terms","field":"publicationYear","limit":100,"mincount":1},"departments":{"type":"terms","field":"employeeDepartments","limit":100,"mincount":1,"domain":{"excludeTags":"employeeDepartments"}}}&q=*&defType=edismax&omitHeader=false&f.publicationCategory.facet.sort=index&qf=content^40.0+title^5.0+keywords^2.0+tagsH1^5.0+tagsH2H3^3.0+tagsH4H5H6^2.0+tagsInline+description^4.0+abstract+subtitle+navtitle+author&facet.mincount=1&facet=true&wt=json&facet.sort=count
The point is that
fq
can appear multiple times.
a
ok hmmmmmm, not super familiar with uses cases where the same qp is repeated
m
Me neither. Solr is the only API I know with repeated argeuments. Except of course the goold old PHP magic foobar[] where an array is built fro the repeated foobar[] 🙂
a
my guess is that out of the box, WireMock doesn’t handle this well, because it will try to match on any of the qps provided. So if I have something that’s like…
Copy code
"id": {
        "and": [
          {
            "contains": "2"
          },
          {
            "doesNotContain": "3"
          }
        ]
      }
and a request that is like:
<http://foo.com/?id=3&id=2>
I’ll get a match on the case where
id=2
, because
id
contains 2 and doesNotContain 3, even though there is that other
id=3
.
m
could very well be like that
a
If that is true (and I’m not sure how big of an
if
that is 😭 ), the best solution would be to write a custom matcher that parses the query parameters yourself. https://wiremock.org/docs/extensibility/custom-matching/
m
I'll leave that to a colleague He's the very man to extend Java servers 😉
a
😭 some days I curse the fact that I work on a heavy Kotlin/Swift team and I’m one of the few with Java experience
I’ll also ping @Tom (apologies! hope you don’t respond to this until after your weekend 😛 ) to make sure my above assumptions are correct.
m
I haven't written any line of Java for years (decades?) But in the end the languages resemble so much that I'm confident I could write the matcher myself. If I fail it will probably because I don't understand the documentation. 🙂
a
I try to tell my team members that if they know Kotlin they know Java but they’re adamant they can’t do it 😛
m
Poor man. With that attitude they will even have trouble with TypeScript ;)
Found a workaround! The query I want to protect from unwanted paraemeters has only for
fq
. So I can list them all in en
hasExactly
matcher.
🙌🏻 1
Thank you.
a
🤦🏻‍♂️ it was right there the whole time
glad you were able to solve it, apologies I suggested a way more difficult workaround
m
Don't worry. I have fiddled around for too long already before asking. Talking to you got me thinking.
Guess I should stop now it's Friday and already past 9pm here.
Have a nice weekend!
😀 1