I have some model objects I'm using in my Java client application. Later these model objects will be populated / retrieved from remote services (e.g. SOAP). Now I want to do manual / automatic testing of the frontend before implementing these services. The model objects are mostly POJO and I want to store some sample test data in files and populate them with some easy method.
E.g. having model object School (with name (String) and teachers (List)) and Teacher with lastname and firstname, I want to store actual test data in some XML / text file and create some schools containing teachers from these data.
What are you using in this situation? I'm not familiar with TTD yet, but I can't imagine that there is no generic framework for doing this.
[edit]
I've choosen Spring to mock up my sample data / services, but the other alternatives mentioned here would have worked as well.
Sounds like a good use of XML serialization. You can use any XML serialization tool you like: XStream, etc.
Another nice tool is SOAP UI. If you point it to the WSDL for your service it'll create the XML request for you. Fill in the values and off you go. These can be saved, so perhaps that's a good way to generate test cases.
You can also use Spring to mock your remote service(s) and their responses.
In this case, all you have to do is loading an applicationContext that will simulate your backend system(s) by replying exactly what you want for your test purpose.
Why not keep the test data in Java? You have no extra stages, formats or libraries to deal with. It's fast and you have the power and familiarity of Java on your side.
First, I'd agree with duffymo that XStream and SOAP UI are viable options. However, I've also used the approach described by Tom Hawtin, as described below.
A helper class constructs a set of test instances of the model classes, some valid and some invalid in specific ways, and builds the appropriate object graphs. An initial test case uses a valid object object graph. Successive tests substitute invalid objects for valid ones in the initial setup, checking that the appropriate errors are returned.
The helper class provides a single point of control for constructing objects whose contents are appropriately related for the scenarios needed in testing.
Related
As part of my RFT QA Automation, I have to store the state(Object) of Java bean and should access the object across the whole application, Singleton may not work here as it is not a web application, would you please suggest any other approach to store the state of java beans.
Appreciate your help.
Thanks
I'm not sure to understand your problem but why not:
serialize the objects to disk/database/...
use a static store (static singleton)
Basically it is a typical Serialization/Deserialization issue. In general you need an ability to write the state of the class on to persistant layer and then to be able to restore the "same" instance from persistant layer. There is a built-in Java mechanizm that works through Serializable interface. However it is rarely used due to its inconvinience. One of te most popular ways to do this is to Serialize your class instances into JSON or XML format and then read it back and instanciate it from that format. If you need the Text to be human readable XML is preferred, otherwise JSON is the usual choice. The best tool to use for JSON serialization is JSON Jackson (FasterXML/jackson) Here are the relevant links: Json Jackson home. The main class that you will need to use is ObjectMapper. It is easy to use. Here is an article with example. Once you get a Json String of your instance write it into a file or DB and then read it and use ObjectMapper to -recreate your instance. It is simple and works very well
Is it possible to get the json data from a restService using code instead of using the pathinfo?
looking for something like: getComponent("restService1").get...
<xe:restService id="restService1" pathInfo="rest">
<xe:this.service>
<xe:jdbcQueryJsonService connectionName="mssql" contentType="application/json">
<xe:this.sqlQuery><![CDATA[SELECT * FROM Order]]></xe:this.sqlQuery>
</xe:jdbcQueryJsonService>
</xe:this.service>
</xe:restService>
I don't think that this is possible without deeply hacking into the core ExtLib REST services.
In these services, the output is generated and written to the defined output stream, which is normally the one from the HttpResponse.
You have two options for this:
Create your own rest service for jdbcQueryJsonService by extending the existing one and add your own method for accessing the output stream
Use reflection to access the private property which holds the outputstream instance
For both options I don't think that this is worth the effort. It's a lot easier to create your own JDBC connection to the SQL server and transform the result to JSON by your own.
EDIT:
Don't forget that you are accessing a component. A component doesn't know something about the output, which is generated by the renderer depending of the current state of the component. While the ExtLib REST Services are a little bit different of the JSF concepts (their output is generated by a servlet), the pattern is the same.
That's why no XPages / JSF component has such a method.
We have REST webservice. It operates over JSON data representation. I would like to provide functional testing. I plan to use RestAssured framework. It provides understandable methods for testing correctness of output json.
Example, get("/method").then().assertThat().body("obj.field", equalTo(5));
But one problem arise: if json structure will change, all tests shall be invalid. For example, if field should be renamed to field2 we shall fix all test with occurrences of field. The problem is very similar to web pages testing problem, where we should check presence of some web elements, etc. It was solved introducing by Page Object pattern. Does some similar solution exist for testing of REST api or could you advise some elegant one?
In the example given in your question you validate the entire body of a response object in which case it is probable you will create brittle tests.
However it looks like REST-Assured already provides all the functionality you need to test specific parts of a JSON response:
JSON example
JSON Advanced Examples
Using JSON Path
You can even map objects and then do whatever you wish with the objects constructed, for example validation and manipulation.
See here for more examples.
Just like with an HTML page, one way to write tests less exposed to changes is to use a strategy to locate the target you want to evaluate.
With a web page you would use an XPath query, a CSS Seletor or directly the id to avoid dependecies over the ancestors.
So how to do it with a JSON ?
Well you could use a Regular expression, but it can get really messy or you could use an XPath like query for JSON :
http://goessner.net/articles/JsonPath/
http://defiantjs.com/
So in your case, writing reliable tests is more about what you evaluate rather than the framework you use to do it.
Changes in REST API (especial public) are less frequent than in GUI. When changes in API are introduced they should be marked with new version and do not break old one (in most cases). So keep your tests as simple as possible, without introducing additional patterns, that will have some benefits - you can easily throw them away and write new. Hihger test framework complexity provides hihger maintanence costs. Any way in REST-Assured you may create ResponseSpecification and reuse it in assertions.
I need a custom definition of ServiceNow for my business. For which, I'll have to configure many tables like Incident, CIs to name a few, then the views, forms etc. I am aware that it can be done through UI provided at our instance. But doing it through a program which can configure our definition on a fresh instance in one go will be a challenge.
But I think it should be possible, to give you a scenario here's what I might be doing..
-- I need to create new views on a table, new fields on that view, adding dependent fields, new choices in the choice list for a choice field and the list goes on...
Is there any way to do it in Java? maybe using JSON Web services provided by ServiceNow?
Or is there any API in java which can simplify the work, like the one for BMC Remedy?
I understand that it is a big task, please let me know if there is any other way to do it.
PS: I am familiar with the JSON web service API available for ServiceNow.
I agree with Joey. It sounds like a vanilla use case for Update Sets.
I can't fully understand the purpose of data binding in jsp of spring. Does someone have a full understanding of it?
You have html on one side, and java objects on the other side. You have to convert between these two. That's what binding is for - you tell spring to handle this conversion, i.e. to bind html inputs to object fields.
Classically, data binding was used within applications to take advantage of data stored in databases. Windows Forms data binding allows you to access data.
look at this
www.dapfor.com
typically in a web app, data is loaded from a database. This is not done in the jsp layer (typically). The databinding is simply a way to get your data (i.e. model objects) available on the jsps.
You may want to access your input form / URL parameters in an OO fashion: input.getUserName(), input.getBirthDate(). Spring (as well as other web frameworks, but in different ways) provides you with means of transparently "binding" the input.
This binding process involves conversion (from a Strings to whatever -- Date objects, numbers, your custom classes etc.) and validation, so you get all that out of the box (all you need to do is sometimes configure it to work as you want it).
Since HTML came with stateless, binding data came to resolve that problem.