Building and exporting test resources

This page applies to Apigee and Apigee hybrid.

View Apigee Edge documentation.

Before you test APIs, you may need to build a set of test resources, such as API products, developers, or apps, that represent those same resources that might exist in the production environment in your Apigee organization.

Build and export test resources as described in the following sections. See also Managing folders and files in an Apigee workspace.

Building test resources

To build test resources, create a test bundle and edit the test resources defined in the following table.

Test resource Description
API products (products.json) Define the API products used to bundle APIs and make them available to developers.
Developers (developers.json) Register the developers that will access your APIs.
Developer apps (developerapps.json) Register apps to control access to your APIs.
Key value maps (maps.json) Define the key value maps (KVMs) used by your APIs to store data for retrieval at runtime.

Creating a test bundle

To create a test bundle in Cloud Code:

  1. Perform one of the following actions:

    • Position your cursor over the test data folder in your Apigee workspace and click Create test bundle icon. + displays when you position the cursor over tests folder

    • Select View > Command Palette to open the Command palette and select Cloud Code: Create Apigee test bundle.

  2. Enter a unique name for the test bundle and press Enter.

The test bundle is added to the test data folder in the Apigee section.

Test folder with developerapps.json, developers.json, maps.json, and products.json files

Configure the test resources, as described in the following sections.

Defining API products (products.json)

Define the API products used to bundle APIs and make them available to developers. For more information about API products, see What is an API product?

To define API products, update the products.json file using the configuration wizard or by editing the products.json configuration file directly. For a description of the fields in the products.json file, see Resource: ApiProduct.

To define API products using the configuration wizard:

  1. Position your cursor over the products.json file for the test bundle and click Wizard icon to define an API product. The Create API product wizard opens.

    First page of the Create API product wizard

  2. Enter a name for the API product and step through the configuration wizard to autopopulate fields in the products.json file. The products.json file is opened in the editor.

  3. Edit the configuration information, as required.

  4. Select File > Save or ⌘S to save your edits.

The following example defines the myapiproduct API product that contains the helloworld API proxy.

[
  {
    "apiResources": [
      "/",
      "/*",
      "/**"
    ],
    "quota": "100",
    "quotaInterval": "1",
    "quotaTimeUnit": "minute",
    "name": "myapiproduct",
    "displayName": "My first API product",
    "proxies": [
      "helloworld"
    ]
  }
]

Registering developers (developers.json)

Register the developers that will access your APIs. For more information about developers, see Registering app developers.

To register developers, update the developers.json file using the configuration wizard or by editing the developers.json configuration file directly. For a description of the fields in the developers.json file, see Resource: Developer.

To register developers using the configuration wizard:

  1. Position your cursor over the developers.json file for the test bundle and click Cloud Code Wizard icon to register developers.
  2. Enter the developer email and other values in the configuration wizard to autopopulate fields in the developers.json file. The developers.json file is opened in the editor.
  3. Edit the configuration, as required.
  4. Select File > Save or ⌘S to save your edits.

The following example defines the developer ahamilton@example.com:

[
  {
    "email": "ahamilton@example.com",
    "userName": "ahamilton",
    "firstName": "Alex",
    "lastName": "Hamilton"
  }
]

Registering developer apps (developerapps.json)

Register developer apps to control access to your APIs. For more information about registering developer apps, see Controlling access to your APIs by registering apps.

To register developers apps, update the developerapps.json file using the configuration wizard or by editing the developerapps.json configuration file directly. For a description of the fields in the developerapps.json file, see Resource: DeveloperApp.

To register developer apps using the configuration wizard:

  1. Position your cursor over the developerapps.json file for the test bundle and click Wizard icon to register developer apps.
  2. Select the developer and other values to autopopulate fields in the developerapps.json file. The developerapps.json file is opened in the editor.

  3. Edit the configuration, as required.

  4. Select File > Save or ⌘S to save your edits.

The following example registers the developer app myapp for ahamilton@example.com and associates myproduct:

[
  {
    "attributes": [
      {
        "name": "sample_attribute_0",
        "value": "sample_attribute_value_0"
      }
    ],
    "developerEmail": "ahamilton@example.com",
    "name": "myapp",
    "callbackUrl": "",
    "keyExpiresIn": "",
    "apiProducts": [
      "myproduct"
    ]
  }
]

Defining key value maps (maps.json)

Define the key value maps (KVMs) used by your APIs to store data for retrieval at runtime. For more information about KVMs, see Using key value maps.

To define key value maps, update the maps.json file using the configuration wizard or by editing the maps.json configuration file directly. For a description of the fields in the maps.json file, see KeyValueMap resource.

To define KVMs using the configuration wizard:

  1. Position your cursor over the maps.json file for the test bundle and click Wizard icon to define key value maps.
  2. Select the scope and other values to autopopulate fields in the maps.json file. The maps.json file is opened in the editor.
  3. Edit the configuration, as required.
  4. Select File > Save or ⌘S to save your edits.

The following example defines the mykvm encrypted KVM:

[
  {
    "name": "mykvm",
    "encrypted": true
  }
]

Exporting test resources to the Apigee Emulator

To export the test resources to the Apigee Emulator:

  1. Position the cursor over the test bundle that you want to export and click Export test resource icon.

    Export icon displays when you position your cursor over the test bundle name

  2. If multiple containers for the Apigee Emulator are running, select the container to which you want to deploy the environment.

The active test resources appear in the Apigee Emulator, as shown in the following figure.

Active test resources including API products, developers, and developer apps

View the test resource contents to obtain specific resource information, such as an API key for testing which is generated automatically and included in the developer app test resource.