https://linen.dev logo
#help
Title
# help
m

Masi

09/08/2023, 6:09 PM
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

Aaron

09/08/2023, 6:41 PM
What version of WireMock?
m

Masi

09/08/2023, 6:41 PM
3.0.3
I am mocking Solr which can take many filter query (fq) arguments
a

Aaron

09/08/2023, 6:42 PM
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

Masi

09/08/2023, 6:46 PM
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

Aaron

09/08/2023, 6:47 PM
Ah! So your request could be something like
<http://www.foo.com/things?fq=1&fq=2&fq=3>
?
m

Masi

09/08/2023, 6:49 PM
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

Aaron

09/08/2023, 6:51 PM
ok hmmmmmm, not super familiar with uses cases where the same qp is repeated
m

Masi

09/08/2023, 6:53 PM
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

Aaron

09/08/2023, 6:55 PM
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

Masi

09/08/2023, 6:56 PM
could very well be like that
a

Aaron

09/08/2023, 6:59 PM
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

Masi

09/08/2023, 7:00 PM
I'll leave that to a colleague He's the very man to extend Java servers 😉
a

Aaron

09/08/2023, 7:02 PM
😭 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

Masi

09/08/2023, 7:04 PM
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

Aaron

09/08/2023, 7:05 PM
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

Masi

09/08/2023, 7:06 PM
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

Aaron

09/08/2023, 7:11 PM
🤦🏻‍♂️ it was right there the whole time
glad you were able to solve it, apologies I suggested a way more difficult workaround
m

Masi

09/08/2023, 7:14 PM
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