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.
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.
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.
We can now run mvn clean test
This is nice, but the next question is "Can we also run this Application on a WebLogic Container and do some external tests"
For this we can use the weblogic-maven-plugin in the integration-test Maven phase.
The WebLogic plugin can create a new WebLogic Domain, Start the AdminServer, Deploy the JAX-RS 2 shared library, our Application and off course stop the AdminServer and remove the domain.
In SoapUI 5.0 I made a Testcase for this Person REST Service and add the soapUI project xml to our JDeveloper project.
The Maven soapUI plugin , In my case I added the smartbear private repository to my own Nexus repository.
Now we can start maven with mvn clean deploy
Create a new WebLogic domain ( inside the maven target folder ), deploy our application together with the shared library.
Start the soapUI testcases.
With this as result.
You can find this demo project on github https://github.com/biemond/Person-Rest-MavenApp