JUnit JavaBean assert not null deep - junit

How can a JavaBean be tested for deep not null?
I have a JavaBean with about 400 properties. MyBatis fetches the data from a database and uses a Result Map to initialize the JavaBean. What I'm looking to do is test the Result Map for correctness. The first step I'm considering is to test for deep not null.

Use java.beans.Introspector to get BeanInfo and getPropertyDescriptors().

Related

How to convert Model Test prediction annotation into XMLs?

I Train my lane marking model and test my dataset in which it gives accurate results. so i need to convert those test result annotation into XMLs or into JSON. how can i do this using python ?

Is there an elegant way to get JSON Data from OdataV4 Model in Openui5?

(openui5 Version 1.42)
Hello,
I have a list of items, whose data is provided by an odatav4 model (sap.ui.model.odata.v4.ODataModel)
When I select an Item, I bind it to a detail view with its own controller.
Now I would like to get the data from the odata model.
This solution does not work, as the odata v4 model does not support the read method:
Converting ODataModel into JSON Model
Is there a way to get the data of the selected entry as json (model or directly as data)?
What I can get is a property from the context in my controller:
this.getView().getBindingContext("ams").getProperty("Ident)
returns 1. The Identifier of my selected entry.
If you call the method getObject on the binding context you should get the entity as json.
this.getView().getBindingContext("ams").getObject()
You can use Context.getObject. This delivers the complete object that the context points to. However there is a bug in 1.42; the result is wrapped and you have to access it via .value[0]. This bug has been fixed in 1.44.7. See the release notes.
A solution that works in 1.42 and all following releases is to make use of the fact that getObject also can deliver parts of the object. Deliver an empty sPath parameter:
this.getView().getBindingContext("ams").getObject("")

How to Unit Test JsonMarshaller with pretty print enabled?

I have a method called JsonMarshall(T t) that takes an object and converts it into Json String. Inside this method I'm using the Objectmapper to accomplish this task:
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(t)
Now, lets say I have a class ClientName with the attributes Title and Name that I'm using for my test. Now when I try to convert ClientName into json string with my method and test this method by asserting its output against some expected Json String such as:
expectedString = "{\"title\":\"RandomTitle",\"Name\":\"RandomName\"}"
I get two scenarios:
Test fails when I use mapper.writerWithDefaultPrettyPrinter().writeValueAsString(t) in my method.
Test passes when I only do mapper.writeValueAsString(t)
So I guess the indentation of the writerWithDefaultPrettyPrinter() is causing the test to fail.
Any ideas how I can go about making this test pass for the first scenario?
I assume the first test fails because the output is pretty printed and contains additional format signs such as line breaks and whitespaces.
What you could do:
Just use another expected string in the first test method.
Parse the return string of your method under test and use the deserialized object for the test method.
You can use a JsonPath lib for your test (Works similar to XPath).
I use JsonPathResultMatcher to test RESTful Webservices based on the Spring Framework.
As an alternative to #Patrick's perfectly reasonable options, I'd suggest a fourth choice: You can mock the Objectmapper with a tool like JMockit, Mockito or Easymock, and simply ensure that your JsonMarshall method calls the appropriate method(s) on Objectmapper.
This, of course, assumes that you have no doubts that mapper.writerWithDefaultPrettyPrinter().writeValueAsString() does what it is supposed to do and that it is what you want to do. If you have any doubts about either of these conditions, it would be best not to mock, at least for now.

how to handle a size=0 response in MYSQL & Mule

I'm using mulesoft esb 3.7 with MySQL. If I run a query with no resultset I notice the payload has a value of size=0...How do I evaluate that in a choice router? Is it #[flowVars.size==0] or #[payload==null]?
Thanks
#sam, use a debugger and check whether the type of the resultset is a collection or not, say if it is a list then use #[payload.size()==0] if not then you'll see that the payload is null or not.
database component always returns a List object so no need of collection check.
you can check directly #[payload.size()==0]
In case of restful exception handling, use the validation component is-not-empty. If it's empty, the NotFoundException will be thrown. Easy to handle it in the exception strategie.
<validation:is-not-empty value="#[payload]" exceptionClass="org.mule.module.apikit.exception.NotFoundException" />

Using jmeter variable in if controller

I want to use the jmeter if controller and use a jmeter variable which I get while processing the previous response.
I have two services search and register. The logic I want to use is hit the search service, if I get a good response (i.e. the search exists) no need to register. If the search is empty hit register service and check the search service again.
So I have a Simple controller. Under simple controller I have search service with BSF assertion. Next thing under simple controller is the if controller (with register service) for which I need a variable (say ${found} )
I will be creating the variable in bsf assertion as
import groovy.json.*
def slurper = new JsonSlurper()
def result = slurper.parseText(prev.getResponseDataAsString())
if (result.id != null ) {
def found = 0 // can be text logical or any other type ..
}
Question: Can I use the variable ${found} created in the bsf assertion search service as a condition for If controller ? Will it be available beyond the service. Will it be better to have it as user defined variable ?
Depending on found variable type it can be:
vars.put("found", found); - for String
vars.put("found", String.valueOf(found)); - for chars, integers, floats, doubles, booleans, etc.
vars.putObject("found", found) - for anything which cannot be cast to a String
props.put(found, found); - for any Object types. Opposite to JMeter Variables JMeter Properties have "global" scope and Variables visibility is limited to the current thread group only so if you need to pass this value to another Thread Group you need to use properties.
Be careful while setting conditions in the If Controller as in case of string literals you'll need to put both variable and value in quotation marks like:
"${found}"=="someid"
See How to use JMeter's 'IF' Controller and get Pie. guide for more details.
By the way, there is a couple of test elements available via JMeter Plugins which are designed to work with JSON data so you won't have to use BSF scripting:
JSON Path Extractor - to perform correlation on JSON data
JSON Path Assertion - to use assertions on response
yes the variable "found" can be used. But you need to add the following at the end of your code
vars.put("found",found);
Hope this will help.