Rest API testing with JGiven - jgiven

I am quite new to JGiven and currently I have a set of REST API tests automated using Rest Assured and TestNG framework. I am also exploring JGiven as a framework to run the API tests for the advantages it gives with the human readable given when thens and the reports that it generates too. Rest Assured as a library lets us inject the URLs and actually make the REST calls. I want to understand if we have such capabilities within JGiven to actually make the REST calls. If so, I'd like to see an example and understand how I can do that. If not, can someone kindly advice and suggest the best way to achieve it with JGiven. I've been trying to search for this information but have struggled to do so thus far.
Thanks in advance.

JGiven is useful for creating test scenarios that are understandable by domain experts. It is a general tool that can be used for any kind of testing, including testing REST APIs. JGiven adds an understandable layer on top of your underlying test infrastructure. However, you will typically need tools in addition to JGiven to implement the underlying layer. So for testing REST APIs you will use a tool like Rest Assured in combination with JGiven. With JGiven you describe your scenario in the domain language, with Rest Assured you will execute the REST calls.

Related

Rest Assured vs Cucumber

I know what Rest Assured is and for what purpose it is used and the same for the cucumber.
But the thing is what we can achieve with Rest Assured, we can also do with Cucumber for testing.
Rest Assured simply calls the web service and validates the response. We can't use Rest Assured during the Maven build because the service needs to be up and running.
But with Cucumber I can directly call the web service's business service layer and DOA layer and validate the response. Cucumber can invoke this at Maven build time.
So question is which one is better? I know we can use/integrate Cucumber with Rest Assured but.
Cucumber is a BDD tool and can be used to describe the expected behavior and use those descriptions as the basis for test automation.
RestAsured is a tool to test API's/http calls.
They do something different.
You could use them both: Cucumber to describe you functionality, and RestAssured to do http calls.
But with Cucumber i can directly call the web service's business service layer and doa layer and validate the response.
This is not necessarily true, and it has to do with the test level you want to achieve.
So if you just want to do tests on a unit level, then yes, you don't need to use REST assured, you can perfectly specify your tests with Cucumber feature files, and in the step definitions, you can test the service layer and the DOA layer directly, like you mentioned.
If you want to test a running instance of the webservice then you can use REST Assured or REST Assured plus Cucumber. REST Assured will only help you simplify the actual definition of each part of the test and the interactions with endpoints and its expectations, and Cucumber will allow you to define the high-level scenarios made of those steps.
So the question is which one is better? I knew we can use integrate cucumber with rest assured but.
All in all, it's not a matter of which one is better, but what level of testing you're trying to achieve and how you want to achieve it. A unit level you might not need REST assured. On an integration/live-execution level, then yes, you can use that library. In both levels, you can specify your tests using Cucumber.
Rest assured is java Api libraries to do automate REST web services. we can automated Rest apis by using BDD method,BDD is method and Cucumber is leading and free tool for that
Rest assured is not a tool it is a java library which we can use for test restful webservices, and yes cucumber is recommended to use because customer is giving better reporting which rest assured is not supporting to reports.
So I can recommend use cucumber framework to test API

SOA with SOAP and REST implementation

I am struggling with the concept SOA. Lets say there is a big project which contains a lot of specific business logic and resources. From what I've found SOAP and REST makes sense, SOAP for the business logic part and REST for the resources/CRUD part.
The idea that I have in mind is to use SOAP as a public entry-point and use the REST as an internal API for SOAP (because it should not have business logic), this way I can utilize the strength of both structures.
The problem here is that writing detail/overview requests will probably be in REST and SOAP services, which isn't good for maintenance.
Should mixing SOAP and REST be avoided or can they be used in the proper way of how I described it?
EDIT I will try to make a more specific case. I also came across a good article http://www.infoq.com/articles/tilkov-rest-doubts. Which will resolve a lot of problems with using business logic in REST, by renaming the models differently.
For example if you have an order with products and you have discount on it can be calculated after (creating) POSTing products to an /order URL for example. And the discount is visible after GETing the product on /order URL. This fits perfectly in REST.
However when for some reason you can't have product x and y in the same order, this seems a bit difficult to do in a REST service. Because you will have to give proper error message like 'x and y can't be in one order', this is exposing business logic and seems to fit better in SOAP. Is there a way to do this is REST and if so, is it better to do use REST in this case?
A broad question, perhaps too broad. Of course it depends on what you are building. If you provide some more details, platform, targeting what kind of devices, etc you will get a better answer.
However, consider building RESTful api's for everything, public + internal. I'd suggest checking out ServiceStack https://github.com/ServiceStack/ServiceStack/wiki/Why-Servicestack docs which discuss an approach for api's. Even if you don't use their toolset, the concepts will help you build your own web api's.

RestFuse vs Rest Assured vs MockMVC Rest Service Unit Test Framework

I've been trying to find a simple all purpose unit test framework for Spring MVC based Rest Services I've written.
I've been searching online and narrowed it down to:
RestFuse (http://developer.eclipsesource.com/restfuse/)
Rest Assured (https://github.com/jayway/rest-assured)
MockMVC (http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-rest-api/)
I like RestFuse because it's mostly annotation based, but rest assured seems to have a easier way of passing parameters and checking responses. And finally being a Spring MVC Rest Service project, I'm wondering if I should just stick with the already established way of testing Rest Services in Spring with MockMVC.
Interested to get any feedback, as well as performance, past experiences and if there's anything else I should take into consideration.
Rest-Assured is gaining acceptance over the other frameworks to test REST services in Java. Having BDD style fluent interface, its easy to read the test scripts also, with minimal learning curve.
I am using this framework for verifying REST services as an end user, and it has been easier to implement test scripts for them. Hence I cannot comment much on Spring MVC part of REST-assured.
However, this blog post gives you more details on RestAssured v2.2 which includes spring-mock-mvc module built on top of MockMVC giving BDD style fluent interface flavor through REST assured. The blog post also cautions:
When not to use it:
RestAssuredMockMvc is not to be considered a complete replacement to
vanilla MockMvc since it contains more specific features coupled to
Spring MVC. For example right now there’s no first class support for
things like flash attributes and principals. You can how ever add
those by using an interceptor. Standard REST Assured also supports a
lot of different authentication schemes and filters which are not
available in the RestAssuredMockMvc API. Another reason for why you
may want to use the standard REST Assured API is if it’s important to
your organization to test the REST API in a real container (for
example if you’ve configured authentication or authorization in a
container specific manner) or if you’re using JAX-RS (or any other
framework regardless of language).
Finally, have a look at REST-Assured spring-mvc-webapp examples in REST-assured codebase, and decide, whether you like to give a try for it and make the best use of both REST-assured and MockMVC frameworks.
The beauty of MockMVC is that it provides a mock servlet container, allowing you to integration-test your REST services without deploying to a web server. I believe that you can still leverage this power when using REST Assured with the spring-mock-mvc module.
Another framework that I just learned of is Karate. Its author is currently experimenting with a mechanism to allow execution in a mock servlet container (see Peter Thomas' answer to Is there a mechanism for integration testing JAX-RS services without deploying (a la MockMVC)?).

Any reason why I can't use both the REST and SOAP versions of the DocuSign API together?

DocuSign highly recommends using the REST API instead of SOAP, and they push heavily for that in your initial implementation. They even suggest that new features may one day only be implemented in REST, which is my main concern. I'm leaning toward using their SOAP API anyway for our integration, and my primary question is this:
Let's assume the future scenario I fear - I build my DocuSign integration layer on the SOAP API. Next year, DocuSign does in fact leave the SOAP model behind, releases new features on the REST API only, and I desperately need to use one of those features. Is there any reason that I can't simply leave all of my SOAP integration in place, and implement integration with the new feature using the REST API? I understand that referencing both APIs would bloat the size of my deployment a bit, but I can accept that risk. Other than that, is there any compelling reason that I can't use both side-by-side? Would it break something?
It's perfectly acceptable to use a mix of DocuSign SOAP API and REST API in your integration. In fact, that's a very common scenario for the exact reason you mention -- some features are implemented only in SOAP or only in REST, so it's often necessary to use a mixed approach in order to get the full functionality that you require.

Is there an example in CPAN of a module that implements a REST based API using modern Perl techniques?

I would like to create a module for the Pinboard API.
Though very similar to the old Delicious API, there are enough changes that I would like to re-implement to specifically work for Pinboard.
The Net::Delicious module was build initially in 2002 and I see that many of the newer REST best Modules are implemented in a new way. Net::Twitter, WebService::Dropbox and WWW::Vimeo::Simple seem to have different methodologies on how to implement their respective REST API.
Net::Twitter is very complex and heavy implementation in my opion. WebService::Dropbox is extremely light as is the API it implements. WWW::Vimeo::Simple seems to be between the two in terms of complexity.
I also spent some time looking at REST::Client but it probably would not be useful if you want to implement more that one or two methods.
What are the best practices for implementing a complete REST webservice? and also to test the responses without being able to connect to the service.
What you want is Net::HTTP::Spore. It's a moosy framework for REST clients in modern Perl. See also these slides