Wiremock- Verifying unique JSON matches expected? - java

I'm trying to test my REST application which generates some JSON and uses it to contact another API. I want to ensure the correct JSON is being generated, but the problem is that two of the fields are unique for each run, specifically an ID and a timestamp.
How can I verify this JSON is correct using Wiremock given that the fields are unique each time? Is there a way I can leave those fields to "any" or something in Wiremock?
obj.verfyObjContaining("{\"id\": 123 ,\"timestamp\": 11:11:11}");
Timestamp and ID are unique so this doesn't match.

Setting them to any isn't your only option. You can also mock the timestamp and id. Setting them to a static value during the test run. The advantage of that would be that you at least test that the value is being pushed out with the api call.
Unfortunately without any code posted I can not give more details than that.

Sorted it! Found a "matching()" verification function in Wiremock which takes a regex.

Related

Ignore Field in json in assert operation

I'm trying to write a MUNIT test case for mule service and want to ignore a field having timestamp. Currently, i'm using below code to perform the compare.
org.skyscreamer.jsonassert.JSONAssert.assertEquals(getResource('json/item-locations.json').asString(), payload, false);
I want to ignore field "creationDateTime" which is available in my json message.
Just delete the field from the message before comparing it. If you want to make sure it's actually there, then replace it with a constant value, but only if it exists.

How to ignore some value in spring-ws-test

I follow this to create test for testing my endpoint. Problem is that in my response I am returning current time which I dont want to test. Is there some way how to ignore some value like: ${IGNORE}
The default ResponseMatchers class supplied with Spring-WS uses the PayloadDiffMatcher in order to compare the given and expected payload. The compare is done using an XMLUnit Diff. You could extend the PayloadDiffMatcher (or implement your own custom ResponseMatcher) so that it allows specifying a filter for your current time element as illustrated here.
Another option is to use the xpath() ResponseMatcher and only check parts of the returned response, ignoring the time element.

java-Share data among different scenarios in a single feature

Cucumber java
My feature file looks like
Feature
Scenario1:.... Generate a unique number
Scenario2:.... Do some validations on the unique number generated
Using spring for dependency injection, the unique number generated # Scenario1 is assigned to a String, the same need to be used across the Scenario2 as well.
But I'm getting a String value as null #Scenario2. I think the dependency injection # scenario2 is creatin a new object and is getting the default value as null.
Please help me on to resolve this issue. Need to know how java objects can be passed across different scenarios in a single feature..
Use Singleton?
1) Generate unique number at 1st scenario
2) getInstance() at 2nd
Use gherkin with qaf where it provides different ways to share information between steps or scenarios.
For example, If your step returns value you can use like:
Then get text of 'element'
And store into 'applicaiton.refID'
to refer any stored value or any property you can use ${property}. For example
Given application to update is '${applicaiton.refID}'
You can applicaiton.refID in any of subsequent scenario.
If you want to do this in java step, you can write code something like below:
//store value for further use
getBundle().setProperty("applicaiton.refID","myvalue");
//retrieve applicaiton.refID any where
getBundle().getString("applicaiton.refID");

Web service response is MessageElement?

I am trying to figure out how to use this service, which should print out holidays in US: http://www.holidaywebservice.com/Holidays/HolidayService.asmx?WSDL
So, I generated Java classes for it, and tried to call its method, which should return list of available countries:
holidayServiceLocator.getHolidayServiceSoap().getCountriesAvailable().get_any()
getAny() method returns org.apache.axis.message.MessageElement[] type of object, and this is where I am lost.
As I can understand, MessageElement is used in order to store XML, am I correct? In that case, how should I handle it in order to get correct result (list of supported countries for this service)?
You can either use MessageElement.getElementsByTagName(String name) if you know the tag names in the response or you can use MessageElement.getChildElements() to iterate through all of them one by one.

Querying FHIR resrouces using JSON and Java

I'm trying to figure out a basic approach to querying FHIR resources. My first task is to query using a REST interface. Using the information on the Search page, I see there are 7 search parameter types (NUMBER, DATE, STRING, TOKEN, REFERENCE, COMPOSITE, QUANTITY). My question is:
How does one determine a parameter's type when it's passed to the server in a URL's query string?
Since modifiers like :exact and :token only apply to certain parameter types, it seems important to identify the type of each parameter in the query string. I'm hoping the server is not expected to look up parameter types based on the resource being queried.
I'm using FHIR 0.81 with Java and JSON.
Thanks,
Rich
The server does need to look up the parameter types depending on the resource being queried. The server has to actually recognise the parameters to do anything with them anyway.
(and I assume you mean 0.0.81)

Categories

Resources