Testing an API with the Local Test Environment
Use the Local Test Environment (LTE) to test APIs on your local machine, without the need to connect to an API Connect management server. The Local Test Environment is a lightweight API Manager running on your local machine. It allows you to rapidly test APIs locally.
API Connect provides
the following methods for testing an API on your local machine:
- Invoke the API from the API Designer UI application running in Online mode as described in Testing an API.
- Call the API in the Local Test Environment with a cURL command, as described in the following sections.
Prerequisites
- The API Connect developer toolkit, including the API Designer user interface, installed. For installation and running instructions, see Installing the toolkit.
- The Local Test Environment and the API Designer must be from the same API Connect fix pack release in order for them to work together.
- Docker installed.Note: The Local Test Environment is not supported with Docker Version 18.09.x.
- A minimum of 4 GB of RAM available to Docker if a single gateway type is used, or 6 GB if both
the DataPower® API Gateway and DataPower Gateway (v5 compatible) are used.Note: As you increase the number of APIs that are published to your gateways, you will need to allocate further memory to Docker. You will also need to start the Local Test Environment with a larger database; see
apic-lte start
. - If you are using Windows, ensure that your C: drive (or the drive on which your HOME directory is located, if different), is enabled as a shared drive so that the Local Test Environment files are accessible to the Docker containers.
Installing the Local Test Environment
There are two options for installing the Local Test
Environment:
- Each user downloads the Local Test Environment images to their local machine and installs the Local Test Environment from there.
- One user downloads the Local Test Environment images and uploads them to a private Docker registry, from where any user can install the Local Test Environment.
To install the Local Test
Environment from your local machine, complete the following steps:
Note: In all Local Test
Environment commands
that are used on the remainder of this page, replace platform with
macOS
, linux
, or windows
, depending on your
platform, as follows:- macOS: replace
platform-apic-lte
withosx-apic-lte
- Linux: replace
platform-apic-lte
withlinux-apic-lte
- Windows: replace
platform-apic-lte
withwin-apic-lte
To upload the Local Test
Environment images to a private Docker
registry, complete the following steps:
Starting the Local Test Environment
- Start the Docker images by running the following command:
platform-apic-lte start
Note:- By default, the
platform-apic-lte start
command starts only a DataPower API Gateway. To also start a DataPower Gateway (v5 compatible), enter the following command:platform-apic-lte start --datapower-gateway-enabled --datapower-api-gateway-enabled
- The Local Test
Environment might fail to
start with an error message that includes the strings
Error: certificate is not yet valid
andCERT_NOT_YET_VALID
. The most likely cause is that the date and time setting is incorrect on the machine that is the running the Local Test Environment. Ensure that the date and time setting is correct, before attempting the start command again. If you are using Docker for Windows, the clock in the Docker containers can become out of sync with the system clock, especially after a machine has been put in sleep mode. In this case, restarting Docker should fix the clock discrepancy; for more information, see https://github.com/docker/for-win/issues/4526. - By default, the LTE starts with an empty backend database that does not contain the APIs and
Products that might have been published during an earlier run of the LTE. To start the LTE with the
backend database that was used during the previous run, use the flag
--keep-config
, for example,platform-apic-lte start --keep-config
. When you use--keep-config
any other flag that is specified for the start is ignored. Instead the same flags that were used during the earlier start are used, in particular the same gateways are enabled.
- By default, the
- Verify that the Local Test Environment is installed and running correctly by
running the following commands:
Note: To configure the toolkit credentials for Local Test Environment, use
the following
command:
apic client-creds:set ~/.apic-lte/credentials.json
Preparing an API for testing in the Local Test Environment
To prepare an API for testing in the Local Test
Environment, you must publish it to
the Sandbox Catalog in the Local Test
Environment. If you want to test an
API that you already published, proceed to Testing an API in the Local Test Environment., otherwise, complete the following steps:
Testing an API in the Local Test Environment.
To test an API in the Local Test
Environment, issue a REST API call to the following
URL:
https://localhost:9444/localtest/sandbox/basepath/operation_path?client_id=lte_client_id
where:- basepath is the base path that is configured in the API definition.
- operation_path is the path for the operation that you want to invoke, as configured in the API definition.
- lte_client_id is the client ID for the test application in the local test
environment, as returned by the
platform-apic-lte status
command in step 2.
The following example show how to test the API that is created in the tutorial Creating a proxy
REST API definition, by using the
curl
utility; the API returns the details
of bank
branches:curl -k https://localhost:9444/localtest/sandbox/branches/details?client_id=80963e74076afe50d346d76401c3c08a
[{"id":"0b3a8cf0-7e78-11e5-8059-a1020f32cce5","type":"atm","address":{"street1":"600 Anton Blvd.","street2":"Floor 5","city":"Costa Mesa","state":"CA","zip_code":"92626"}},
{"id":"9d72ece0-7e7b-11e5-9038-55f9f9c08c06","type":"atm","address":{"street1":"4660 La Jolla Village Drive","street2":"Suite 300","city":"San Diego","state":"CA","zip_code":"92122"}},
{"id":"ae648760-7e77-11e5-8059-a1020f32cce5","type":"atm","address":{"street1":"New Orchard Road","city":"Armonk","state":"NY","zip_code":"10504"}},
{"id":"c23397f0-7e76-11e5-8059-a1020f32cce5","type":"branch","phone":"512-286-5000","address":{"street1":"11400 Burnet Rd.","city":"Austin","state":"TX","zip_code":"78758-3415"}},
{"id":"ca841550-7e77-11e5-8059-a1020f32cce5","type":"atm","address":{"street1":"334 Route 9W","city":"Palisades","state":"NY","zip_code":"10964"}},
{"id":"dc132eb0-7e7b-11e5-9038-55f9f9c08c06","type":"branch","phone":"978-899-3444","address":{"street1":"550 King St.","city":"Littleton","state":"MA","zip_code":"01460-1250"}},
{"id":"e1161670-7e76-11e5-8059-a1020f32cce5","type":"branch","phone":"561-893-7700","address":{"street1":"5901 Broken Sound Pkwy. NW","city":"Boca Raton","state":"FL","zip_code":"33487-2773"}},
{"id":"f9ca9ab0-7e7b-11e5-9038-55f9f9c08c06","type":"atm","address":{"street1":"1 Rogers Street","city":"Cambridge","state":"MA","zip_code":"02142"}}]
Local Test Environment commands
The following table summarizes the Local Test
Environment commands; use the
help
command to get full usage details for any command.
Command | Description |
---|---|
platform-apic-lte help command |
Display help information for any command. |
platform-apic-lte init |
Download the Local Test Environment Docker images. |
platform-apic-lte start |
Start the Local Test
Environment
Docker images. Use the --database-max-heap-size parameter to set the size of the
Local Test
Environment database, in bytes;
for
example: The
default value is 1024M .Tip: By default, the
platform-apic-lte start command deletes all previous data and
re-initializes the Local Test
Environment
configuration, so all your previous configuration, including published Products, is deleted. To
retain the previous configuration, and to apply the same command parameters that were used in the
previous platform-apic-lte start command, supply the
--keep-config parameter. |
platform-apic-lte status |
Display status information for the Local Test Environment components, and endpoint and authentication details. |
platform-apic-lte stop |
Stop the Local Test Environment Docker images. |
platform-apic-lte version |
Display Local Test Environment version information. |
Troubleshooting the Local Test Environment
You can consult the log file for each Local Test Environment microservice or database by using the following command:
docker logs container-name
where container-name is one of the following:
apic-lte-juhu
: the authentication gatewayapic-lte-apim
: the API Management serviceapic-lte-lur
: the Local User Registryapic-lte-db
: the Postgres database of the API Management serviceapic-lte-datapower-api-gateway
: the DataPower API Gatewayapic-lte-datapower-gateway
: the DataPower Gateway (v5 compatible)
You can access the gateway logs in either of the following ways:
Local Test Environment port values
If any of the default port values for the Local Test
Environment components conflict with
ports already in use on your system, you can change them when you start the Local Test
Environment by passing one or more
--component
port_value
parameters to the
platform-apic-lte start
command, where:- component is the Local Test Environment component whose port value you want to change.
- port_value is the required value.
For
example:
platform-apic-lte start --datapower-api-gateway-api-port 9445
The following table lists the components, together with the corresponding
component parameters, and the default port values:
Component | component parameter | Default port value |
---|---|---|
DataPower API Gateway API port | datapower-api-gateway-api-port |
9444 |
DataPower API Gateway API Connect service port | datapower-api-gateway-apic-service-port |
3001 |
DataPower API Gateway REST management port | datapower-api-gateway-rest-management-port |
5555 |
DataPower API Gateway SSH port | datapower-api-gateway-ssh-port |
9023 |
DataPower API Gateway administration web UI | datapower-api-gateway-web-gui-port |
9091 |
DataPower API Gateway XML management port | datapower-api-gateway-xml-management-port |
5551 |
DataPower Gateway (v5 compatible) API port | datapower-gateway-api-port |
9443 |
DataPower Gateway (v5 compatible) API Connect service port | datapower-gateway-apic-service-port |
3000 |
DataPower Gateway (v5 compatible) REST management port | datapower-gateway-rest-management-port |
5554 |
DataPower Gateway (v5 compatible) SSH port | datapower-gateway-ssh-port |
9022 |
DataPower Gateway (v5 compatible) administration web UI | datapower-gateway-web-gui-port |
9090 |
DataPower Gateway (v5 compatible) XML management port | datapower-gateway-xml-management-port |
5550 |
Platform API port | platform-api-port |
2000 |