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.

Prerequisites

Ensure that the OpenShift environment is set up to deploy the application.

Procedure

  1. In the Project Explorer, expand the tibco.bwce.sample.binding.rest.BookStore.application process and expand the Package Unit > Properties folder.
  2. 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:
  3. Expand the Package Unit and select Overview.
  4. In the Overview window select Export Application for Deployment.
  5. In your Docker environment, navigate to the directory containing your EAR file.
  6. To login to the OpenShift environment, run the following command:
    oc login <OpenShift_Server_URL>
  7. If the project is not created, create an OpenShift project by running the following command:
    oc new-project <PROJECT_NAME>
  8. To build an application docker image, run the following command:
    docker build -t <APPLICATION_NAME> .
  9. 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>
  10. 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.
  11. To use the OpenShift configuration file (YAML or JSON) and push the application on OpenShift, run the following command.
    oc create -f <MANIFEST_FILENAME>
  12. To create a route for application, run the following command.
    oc expose service <APPLICATION_SERVICE_NAME>
  13. To view the route of an application, run the following command:
    oc get route
  14. Open the Google Chrome browser and open http://ROUTABLE_URL/swagger.
  15. 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.
  16. Expand the Books and Events headers, and test the operations as follows.

Result

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
    }