How to ignore some value in spring-ws-test - java

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.

Related

Apache Freemarker - How to use Java code to compare value of a parameter

I have a json template as below
{
"Account_Number" : "${accNo}"
}
I want to use a user-defined directive which is basically a Java code to check if accNo is greater than 0. If not, I want to set the value as 0000.
I was reading here ( https://freemarker.apache.org/docs/pgui_datamodel_directive.html) that it is possible to write Java code by implementing the TemplateDirectiveModel interface. However, I was unable to retrieve the value of accNo.
Is it possible to achieve the above using user-defined directive? If yes, how?
You want something like <#accNoJson value=accNo />, then you can get it from params parameter of TemplateDirectiveModel.execute. If you want something like <#accNoJson/> (which is a bit odd), then you can get it with env.getVariable("accNo"), where env is the 1st parameter of TemplateDirectiveModel.execute.
The most typical approach would be ${accNoJson(accNo)}, in which case you should implement TemplateMethodModelEx.

Wiremock- Verifying unique JSON matches expected?

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.

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.

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.

Objectify: Get list of Strings NOT EQUAL to provided value

I need to get the list of items whose datePublished IS NOT "". However, the code below doesn't work. Any ideas? Thanks
Query<Diagram> q=ofy.query(Diagram.class).filter("datePublished !=", "").order("-likes").limit(18);
When applying an inequality filter in the GAE datastore there are some restrictions.
You can read more here: https://developers.google.com/appengine/docs/java/datastore/queries
In this case, to have an inequality on datePublished you must order on that same field primarily before you can order on another.
So assuming the datePublished field is indexed:
Query<Diagram> q=ofy.query(Diagram.class).filter("datePublished !=", "").order("datePublished").order("-likes").limit(18);
Assuming this isn't a migration concern, you may want to consider denormalising this data when you store it, for example setting a 'noDatePublished' boolean.

Categories

Resources