In this blogpost I will show you how easy it is to add some unit tests to your application when you use Maven together with the 12.1.3 Oracle software ( like WebLogic , JDeveloper or Eclipse OEPE).
To demonstrate this, I will create a RESTful Person Service in JDeveloper 12.1.3 which will use the Maven project layout.
We will do the following:
Create a Project and Application based on a Maven Archetype.
Create a JAX-RS 2.0 Person Resource
In the Maven Test phase, we will test this Person Rest Service.
In the Maven Integration Test phase, we will test the Person Resource on a WebLogic domain and run some external soupUI tests.
Before we can start, we need to use oracle-maven-sync-12.1.3.jar plugin to populate our local or maven repository with all the Oracle binaries.
For more information how to do this you can take a look at one of the following links.
We start by creating a new application in JDeveloper 12.1.3
Go to the Maven tree and select Generate from Archetype.
Provide the maven Group and Artifact id and lookup the basic-webservice Archetype.
When you search for webLogic you will find the basic web service archetypes. Make sure you select the 12.1.3 one.
This will create a Web Service Project but we also need to create an application. So the next step is the Application creation dialog.
Choose JAX-RS 2.0 Style
Choose RESTful Service From New
Provide all the REST service details and enable application/json as Media Types.
And viola we got our Person RESTful Service.
JDeveloper will automatically add the JAX-RS 2.0 shared library to your project.
This finishes our basic service.
This is how the final Person service will look like.
We can now add some unit tests to the Maven Test phase. We will make 2 JUnit test cases where we will use JerseyTest, so we can test the Person Resource and one with Mockito so we can also mock the data of the Person Resource.
For these tests a lightweight grizzly2 HTTP container will be started by Maven.
The pom's dependency libraries which we will need.
Using only JerseyTest is probably not so meaningful because you probably also need an emulate your EJB's but here you have the JerseyTest snippet
And the JerseyTest with Mockito snippet.
To demonstrate this, I will create a RESTful Person Service in JDeveloper 12.1.3 which will use the Maven project layout.
We will do the following:
Create a Project and Application based on a Maven Archetype.
Create a JAX-RS 2.0 Person Resource
In the Maven Test phase, we will test this Person Rest Service.
- Use JerseyTest to test the Person Resource
- Use JerseyTest and Mockito to test and mock the Person Rest Service.
In the Maven Integration Test phase, we will test the Person Resource on a WebLogic domain and run some external soupUI tests.
- Create a WebLogic Domain
- Start the AdminServer
- Deploy the JAX-RS 2.0 shared library and our Person Rest Service
- Run some soapUI test cases.
- Remove the WebLogic domain.
Before we can start, we need to use oracle-maven-sync-12.1.3.jar plugin to populate our local or maven repository with all the Oracle binaries.
For more information how to do this you can take a look at one of the following links.
- https://redstack.wordpress.com/2014/07/09/new-maven-support-in-soa-12c/
- http://biemond.blogspot.nl/2014/06/maven-support-for-1213-service-bus-soa.html
We start by creating a new application in JDeveloper 12.1.3
Go to the Maven tree and select Generate from Archetype.
When you search for webLogic you will find the basic web service archetypes. Make sure you select the 12.1.3 one.
This will create a Web Service Project but we also need to create an application. So the next step is the Application creation dialog.
Because we want to use JAX-RS and not JAX-WS, so we need to delete the SayHello web service.
Next step is adding the REST Web Service feature to this project.
Create a RESTful Service class
Choose JAX-RS 2.0 Style
Choose RESTful Service From New
Provide all the REST service details and enable application/json as Media Types.
And viola we got our Person RESTful Service.
JDeveloper will automatically add the JAX-RS 2.0 shared library to your project.
This finishes our basic service.
This is how the final Person service will look like.
For these tests a lightweight grizzly2 HTTP container will be started by Maven.
The pom's dependency libraries which we will need.
No comments:
Post a Comment