Testing the REST Service

You can now test the REST service using the built-in tester and the Swagger UI.

Procedure

Note: The Swagger framework used to test the REST service is accessed using the port specified by the bw.rest.docApi.port property in the <TIBCO_HOME>\bw\<version>\domains\<domain name>\appnodes\<appspace name>\<appnode name>\config.ini file. By default, this property is set to port 7777. If you have multiple REST applications running on separate AppNodes on a single machine or server, you must configure these port numbers to be unique for each AppNode. To do so, edit the bw.rest.docApi.port property in the config.ini file for each AppNode.

If there are multiple REST applications running within a single AppNode, there is no need to configure this port.

  1. In the Project Explorer, expand the tibco.bw.sample.binding.rest.BookStore.application process and expand the Package Unit > Properties folder.
  2. In the Properties window, open the tibco.bw.sample.binding.rest.BookStore process and set the default ApplicationProfile to match the operating system you are running on. The bracketed profile in the column head is the one that is selected:


  3. Provide valid values for the application properties including a valid user name, password, and database URL to connect to your PostgreSQL database if different from the default setting.
  4. Verify your JDBC connection.
    1. Expand the Resources folder in the Project Explorer for the tibco.bw.sample.binding.rest.BookStore process.
    2. Double-click JDBCConnectionResource.jdbsResource.
    3. In the JDBC Driver section of the window, click Test Connection to verify the connection. If you change the JDBC driver folder from the default, click Click Here to Set Preferences and set the JDBC driver folder to the folder where you downloaded PostgreSQL JDBC Driver.


  5. Click File > Save.
  6. In the Project Explorer, expand the Processes directory if it is not expanded and double-click MyBooks.bwp.
  7. Click Run > Debug Configurations.
  8. In the left-hand tree of the Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
  9. Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the check box next to tibco.bw.sample.binding.rest.BookStore.application.
  10. Click Debug. This runs the sample in Debug mode.
    The Console view is opened and shows engine messages similar to: Started BW Application [tibco.bw.sample.binding.rest.BookStore.application:1.0].
  11. In the Console view, press Enter to display the prompt: <>@BWEclipseAppNode>
    Enter the OSGi command lrestdoc. This lists the Swagger UI URL as the discovery URL: [Application Name]: tibco.bw.sample.binding.rest.BookStore.application [Discovery Url]: http://localhost:7777/tibco.bw.sample.binding.rest.BookStore.application
  12. Launch the Google Chrome browser.
  13. Open http://localhost:7777/tibco.bw.sample.binding.rest.BookStore.application
  14. Click Books or Events to see the operations. Click MyBooks to see the REST service operations you just added. For more information, see the section Testing the POST and GET Operations .

  15. Expand the Books and Events headers, and test out the operations as listed below.

Result

Click Books or Events in the Swagger UI to view the following operations for Books and Events:

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 an output similar to the following:

{
  "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 an output similar to the following 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
    }

The books.log file is generated with the following information:

POST Books------->{"Book":[{"isbn":"1451648537","name":"Steve Jobs","description":"Biography of Apple Co-Founder Steve Jobs","authorName":"Walter Isaacson","releaseDate":"2012-10-24","vintage":false,"signed":false,"price":21},{"isbn":"0385537859","name":"Inferno","description":"Robert Langdon returns in Dan Brown's latest fast paced action thirller","authorName":"Dan Brown","releaseDate":"2013-05-14","vintage":false,"signed":true,"price":14.09},{"isbn":"0399103421","name":"The Godfather","description":"The Godfather is an epic story of a New York's top mafia family, loyalty, and how men of honor live in their own world, and die by their own laws.","authorName":"Mario Puzo","releaseDate":"1969-03-10","vintage":true,"signed":true,"price":50}]}**************************************************************

GET Books------->{"Book":[{"isbn":"1451648537","name":"Steve Jobs","description":"Biography of Apple Co-Founder Steve Jobs","authorName":"Walter Isaacson","releaseDate":"2012-10-24+05:30","vintage":false,"signed":false,"price":21},{"isbn":"0385537859","name":"Inferno","description":"Robert Langdon returns in Dan Brown's latest fast paced action thirller","authorName":"Dan Brown","releaseDate":"2013-05-14+05:30","vintage":false,"signed":true,"price":14.09},{"isbn":"0399103421","name":"The Godfather","description":"The Godfather is an epic story of a New York's top mafia family, loyalty, and how men of honor live in their own world, and die by their own laws.","authorName":"Mario Puzo","releaseDate":"1969-03-10+05:30","vintage":true,"signed":true,"price":50}]}**************************************************************

GET Book By ISBN------->{"isbn":"1451648537","name":"Steve Jobs","description":"Biography of Apple Co-Founder Steve Jobs","authorName":"Walter Isaacson","releaseDate":"2012-10-24+05:30","vintage":false,"signed":false,"price":21}**************************************************************

DELETE Book By ISBN-------->"Deleted book with ISBN - 1451648537"**************************************************************

GET Events By ISBN---->{}**************************************************************