1

I'm working in a Migration API Testing project also I'm new to API testing. I have this scenario -

  1. There are 2 services, Service A and Service B.
  2. Service A has the response like this when I request for data { "firstName":"John", "age":31, "dob":"20-12-1988" }
  3. Service B returns response like { "name":"John", "age":31, "dateOfBirth":"20-12-1988" }

Now, we see the values returned are same but the attribute (in bold) changes. My test is to validate whether the data is received correct with appropriate attribute. I do the same through manual way currently. But there are lots of services to be tested like this. So I thought of using some automation to do the same. I'm able to fetch the response strings for both the services but not sure how to validate them.

Is there any solution that you guys can suggest to crack this ?

  • Thanks Rsf. I should have added this already. I prefer using Java for automation here. – user3810877 Jan 6 '17 at 16:49
0

@user246 anwser is acceptable, but it is not extendable to new services and forces all clients that need use this data to be dependable of this transformer function.

I would create a interface for service data transformers (or normalizers, if you like it better). This interface would provide a method for get the data for a given standard key.

The implementations of this interface would map the standard keys for a service-specific key and return the data.

A singleton object would provide the list of standard keys.

You can easily extend to new services only by creating a new implementation of the interface. All clients will only depend upon the interface abstraction, what is a good thing.

If you use Python, you can create a Java-like interface using the abc module and the json module to parse the json data.

enter image description here

1

I would probably write something that already knows about changes between the old keyset and the new keyset. I would write a function that uses that information to transform serviceA's response from the old format to the new format. Using the example above, I would replace firstname with name and dob with dateOfBirth. Then I would write something that compares that result to serviceB's response.

A Google search will turn up plenty of Java libraries for parsing JSON. Note that it's risk to transform serviceA's response and then convert it back to a JSON string, because you can't guarantee the result specify the key/value pairs in the same order as before. If the stringify function relies on a HashMap or HashSet iteration order, it may produce different results across different Java version. (That happens when you switch between Java 7 and Java 8). Instead, you should parse both JSON strings and then compare the parsed results.

0

Code it, Python is currently my preferred and it offers the json module, I'm sure other languages have similar modules

0

You will need to convert one of the sides to other, this should be relative simple to code. If you need help ask the developers of one of the system to assist you.

Here is some example code to change a JSON to another type of JSON: https://codereview.stackexchange.com/questions/14429/convert-json-to-a-different-format-nested-json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.