Introducing the all-new TIBCO Community site!

For current users, please click "Sign In" to reset your password and access the enhanced features. If you're a first-time visitor, we extend a warm welcome—click "Sign Up" to become a part of the TIBCO Community!

If you're seeking alternative community sites, explore ibi, Jaspersoft, and Spotfire.

Jump to content
  • Testing APIs with Mock apps

    Vikas Kumar 9

    Modeling and testing APIs

    1. Getting started
    2. Prerequisites
    3. My first API
    4. Adding resources
    5. Import & Export
    6. Managing API specs
    7. Testing with Mock apps
    8. Advanced topics

    Now that you can create and manage your API specs, let?s think about testing! TIBCO Cloud Integration includes an integrated testing capability that allows you to generate a mock application to see if your new API design matches your expectations. Once you create a mock app it will get a unique URL to share with, for example, front-end developers so they can start testing and designing end user applications before any code is ever written. That almost sounds too good to be true? Let?s spend a few minutes to create a mock app and see for yourself!

    Create a Mock app

    On the API specs page you can hover over your API, click on the context menu and select Create Mock app. After you click that option you can specify the name of your new app. The default name is the name and the version of the API spec, so if you?re still following along with this tutorial it should be bookstore_1_0_0_mock_app. Click on the blue Create button to create the Mock application. After TCI is done building, you?ll be presented with a shiny new app. Click on View and Test 1 Endpoint and click on View API to see the test page for your app, though we?ll go over testing in a bit more detail.

    Update your response

    Remember the sample data we used to create the JSON schema? That sample data will be returned when you start testing your app. To view and update the sample data, click on your app to go the Apps detail page. By default the Implementation tab is selected, which is exactly the place we need to be. On that tab you?ll see all the resources your API spec has together with the methods (so in our case you?ll see a GET and POST for /books/{id}). As you click on any of the cards you?ll see the data that is returned when that response is triggered. If you?ve been following along, click on the response for the GET method. You?ll see an empty text box! Now would be a good time to update that with some information. Put the below sample response in the textbox and click Save when you?re done

     { "internalID": "5678BYOD",   "title": "My other new book" } 

    After that click Update Mock app to make the new changes active and you?ll be directed back to the Apps page.

    Test your Mock

    Now that everything is updates, let?s focus on testing! From the Apps page, click on View and Test 1 Endpoint and click on View API to see the test page for your app. With this page you can test your Mock application (by the way, all apps that expost APIs have this page and it works in the same way for all of those). On that page you can see both the GET and POST method we created earlier in the tutorial.Let?s start with the GET method first. As you can see, the sample data we pasted earlier is visible as the example response. You?ll see that the id is bold, meaning it is mandatory and the device is optional (also note that it already contains the predefined value pc). So let?s put in some details in for id (e.g. 12345) and hit Try it out!. The response should be exactly what we pasted just now:

     { "internalID": "1234AAX",   "title": "My new book"   } 

    For the POST method, we also need an id and it is asing for a body. This is the actual content of the API request and it also shows a sample message. You can copy/paste another sample here below or try your own:

     { "author": "Mr. Author",    "description": "Best book ever",    "price": 99.99,    "title": "APIs for dummies" } 

    You can click on Try it out! as well and you should see the response coming back

     { "internalID": "1234AAX",    "title": "My new book"   } 

    Okay, that is slightly underwelming? the responses are the same for both. That is totally expected as we copy/pasted the same sample for both the response of the GET and the POST method. Check the advanced topics to add a bit more logic to your mock app and make the answers a little different.

    Check the logs

    From the logs tab of the apps detail page you can view the logs. As logs are streamed from your app into TCI you can see them on the Log tab of your apps? details page. Logs can be viewed in a scrolling real time display, or you can select a time range to view historical logs. So if you?ve been following along with this tutorial you should see both the GET as well as the POST methods being logged.


    User Feedback

    Recommended Comments

    There are no comments to display.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Create New...