Testing the REST Service in OpenShift
You can deploy the REST service in OpenShift environment and test by using the built-in tester and the Swagger UI.
- Procedure
- In the Project Explorer, expand the tibco.bwce.sample.binding.rest.BookStore.application process and expand the folder.
- In the
Properties window, expand the
tibco.bwce.sample.binding.rest.BookStore.application and set the default
Application Profile to
Docker as shown in the following image:
- Expand the Package Unit and select Overview.
- In the Overview window select Export Application for Deployment.
- In your Docker environment, navigate to the directory containing your EAR file.
- To login to the OpenShift environment, run the following command:
oc login <OpenShift_Server_URL>
- If the project is not created, create an OpenShift project by running the following command:
oc new-project <PROJECT_NAME>
- To build an application docker image, run the following command:
docker build -t <APPLICATION_NAME> .
- To tag an application docker image with your docker repository, run the following command:
docker tag <APPLICATION_IMAGE_NAME><DOCKER_REPOSITORY_NAME>/<APPLICATION_IMAGE_NAME>
- To push a docker image to the docker repository, run the following command.
docker push <DOCKER_REPOSITORY_NAME>/<APPLICATION_IMAGE_NAME>
Note: Here the docker hub registry is used to push the docker image. You can push images to OpenShift internal registry or any other public registry. - To use the OpenShift configuration file (YAML or JSON) and push the application on OpenShift, run the following command.
oc create -f <MANIFEST_FILENAME>
- To create a route for application, run the following command.
oc expose service <APPLICATION_SERVICE_NAME>
- To view the route of an application, run the following command:
oc get route
- Open the Google Chrome browser and open
http://ROUTABLE_URL/swagger
. - In the Swagger UI, click Books or Events to see the operations and then click MyBooks to see the REST service operations you just added. For more information, see Testing the POST and GET Operations.
- Expand the Books and Events headers, and test the operations as follows.
In the Swagger UI, click Books or Events to view the following operations for the Books and Events headers:
Books
- POST books
- GET books
- GET book by ISBN
- PUT book by ISBN
- DELETE book by ISBN
Events
- POST Events
- GET Events
- GET Event by EventID
- PUT Event by EventID
- DELETE Event by EventID
GET books returns the following similar output:
{ "Book": [ { "isbn": "0061122416", "name": "The Alchemist", "description": "Every few decades a book is published that changes the lives of its readers forever. The Alchemist is such a book", "authorName": "Paul Coelho", "releaseDate": "2006-04-25", "vintage": true, "signed": true, "price": 11.9 }, { "isbn": "0071450149", "name": "The Power to Predict", "description": "How Real Time Businesses Anticipate Customer Needs, Create Opportunities, and Beat the Competition", "authorName": "Vivek Ranadive", "releaseDate": "2006-01-26", "vintage": false, "signed": true, "price": 15.999 } ] }
GET books by ISBN returns the following similar output for ISBN 0061122416:
{ "isbn": "0061122416", "name": "The Alchemist", "description": "Every few decades a book is published that changes the lives of its readers forever. The Alchemist is such a book", "authorName": "Paul Coelho", "releaseDate": "2006-04-25", "vintage": true, "signed": true, "price": 11.9 }