Use APIs to Manage Test Data Models

This article explains with the help of an example about how test data engineers (TDEs) can use exposed CA TDM Portal APIs to manage test data models after they create them.
tdm42
This article explains with the help of an example about how test data engineers (TDEs) can use exposed CA TDM Portal APIs to manage test data models after they create them.
This article covers the following tasks. You perform all these tasks by using the APIs. You get the information about the available test data models for a specific project and version. You then identify the test data model that you want to update and delete. 
2
2
Note:
For more information about test data model concepts, prerequisites, assumptions, and considerations, see Use APIs to Design and Consume Automated Test Data Services.
This page refers to the following API Services:
Update a Test Data Model
The process to update a test data model is as follows:
Note:
 These examples use the sample Northwind database that is available for Microsoft SQL Server. Refer the Microsoft website to download the Northwind database.
You can update the following properties of a test data model irrespective of whether the visible parameter is set to true or false. The visible parameter is used only to decide whether you want to display the test data model to testers.
  • Name of the test data model.
  • Description of the test data model.
  • Visibility of the test data model.
  • Display name of the root entity.
You cannot update the following properties:
  • Name of the root entity.
  • Model keys and root entity.
  • Data source of the root entity.
Get the Security Token
Use the login API to log in and generate a security token. You use your CA TDM Portal login credentials to generate the security token. You can then use the same security token to perform all other operations. The security token remains valid for 24 hours.
Follow these steps:
  1. Access an application that allows you to encode your credentials to the Base64 format.
  2. Enter your CA TDM Portal login credentials (in the format 
    <user name>:<password>
    ) in the source field.
    Note:
     Ensure that the credentials have appropriate permissions to perform all the required operations.
  3. Click the option to encode the credentials. The encoded Base64 format for the example is displayed as follows:
    ZwRTaX5pc4SxYXSvcjptYXJtaXRl
  4. Copy the encoded value.
  5. Access the following CA TDM Portal API:
    POST https://<server>:<host>/TestDataManager/user/login
  6. Enter the encoded value in the 
    Authorization
     field, which is as follows for the example:
    Basic YWRtaW5pc3RyYXRvcjptYXJtaXRl
  7. Run the API to get a security token for your credentials.
  8. Note the value of the 
    token
     parameter in the response body, which is as follows for the example:
    eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
    You have successfully generated a security token that you can use in all the subsequent operations explained in this article.
Get the Project ID
Get the project ID that includes the required test data model. Note the project ID, because you will be using it in all the subsequent operations.
Follow these steps:
  1. Access the following CA TDM Portal API:
    GET https://<server>:<host>/TDMProjectService/api/ca/v1/projects
  2. Enter the security token in the 
    Authorization
     field as follows:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  3. Run the API and review the response body. The following example response is generated:
    [
    {
    "name": "Order",
    "description": "This is Order Management project.",
    "dateOrder": "YMD",
    "id": 141357,
    "inheritTables": true,
    "timestampPrecision": 3,
    "type": "DB",
    "levels": [],
    "created": null,
    "updated": null,
    "versions": [],
    "grantedFunctions": []
    },
    {
    "name": "StoreFront - Example Project - Oracle",
    "description": "StoreFront - Oracle",
    "dateOrder": "YMD",
    "id": 1760,
    "inheritTables": true,
    "timestampPrecision": 6,
    "type": "DB",
    "levels": [],
    "created": null,
    "updated": null,
    "versions": [],
    "grantedFunctions": []
    },
    {
    "name": "StoreFront - Example Project - SQL Server",
    "description": "StoreFront - Example Project - SQL Server",
    "dateOrder": "YMD",
    "id": 2234,
    "inheritTables": true,
    "timestampPrecision": 3,
    "type": "DB",
    "levels": [],
    "created": null,
    "updated": null,
    "versions": [],
    "grantedFunctions": []
    },
    {
    "name": "TDMPublish_Centrica",
    "description": "TDMPublish_Centrica",
    "dateOrder": "YMD",
    "id": 7739,
    "inheritTables": true,
    "timestampPrecision": 3,
    "type": "DB",
    "levels": [],
    "created": null,
    "updated": null,
    "versions": [],
    "grantedFunctions": []
    }
    ]
  4. Identify the project and note the project ID. For this example, the project is Order with the ID 141357.
Get the Version ID
After you get the project ID, you must get the associated version ID. Note the version ID, because you will be using it in all the subsequent operations.
Follow these steps:
  1. Access the following CA TDM Portal API:
    GET https://<server>:<host>/TDMProjectService/api/ca/v1/projects/{projectId}/versions
  2. Enter the security token in the 
    Authorization
     field as follows:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  3. Enter the project ID as 141357 in the
    projectId
    field. 
  4. Run the API and review the response body. The following example response is generated:
    [
    {
    "id": 141358,
    "name": "1.0",
    "created": "2017-03-07T07:28:09+0000",
    "description": "This is Order Management version 1.0.",
    "projectName": null,
    "levelDetails": null,
    "registeredObjectCount": 0,
    "tablesUsed": null,
    "isGeneric": false
    }
    ]
  5. Note the version ID, which is 141358 in this example.
Get Test Data Models for the Identified Project and Version
Get the list of test data models for your specific project and version. After you get the list, identify the test data model that you want to update.
Follow these steps:
  1. Access the following CA TDM Portal API:
    GET https://<server>:<host>/TDMDataReservationService/api/ca/v1/testDataModels
  2. Enter the security token in the 
    Authorization
     field as follows:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  3. Enter information in the following fields:
    • projectId
      Specifies the ID of the project for which you want to retrieve test data models. For this example, the value is 141357.
    • versionId
      Specifies the ID of the project version for which you want to retrieve test data models. For this example, the value is 141358.
  4. Run the API and review the response body. The following example response is generated:
    {
    "numberOfTestDataModels": 2,
    "totalNumberOfTestDataModels": 2,
    "testDataModelsList": [
    {
    "id": 386,
    "name": "Orders",
    "description": "This test data model is for Orders Management application.",
    "visible": true,
    "projectId": 141357,
    "versionId": 141358
    },
    {
    "id": 410,
    "name": "Product_Purchase",
    "description": "This test data model is for the Purchase application.",
    "visible": true,
    "projectId": 141357,
    "versionId": 141358
    }
    ]
    }
    Note that the specified project and version include two test data models: Orders and Product_Purchase.
  5. Identify the test data model that you want to update and note its ID. For this example, Product_Purchase with the ID 410 is chosen for the update.
Get Details of the Identified Test Data Model
After you note the test data model ID that you want to update, you can retrieve its details to review the information and note the properties that you want to update.
Follow these steps:
  1. Access the following CA TDM Portal API:
    GET https://<server>:<host>/TDMDataReservationService/api/ca/v1/testDataModels/{testDataModelId}
  2. Enter the security token in the 
    Authorization
     field as follows:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  3. Enter information in the following fields as follows:
    • testDataModelId
      Specifies the ID of the test data model for which you want to get the details. For this example, the value of the test data model ID is 410.
    • projectId
      Specifies the ID of the project for which you want to retrieve test data models. For this example, the value is 141357.
    • versionId
      Specifies the ID of the project version for which you want to retrieve test data models. For this example, the value is 141358.
  4. Run the API and review the response body. The following example response is generated for the Product_Purchase (410) test data model:
    {
    "id": 410,
    "name": "Product_Purchase",
    "description": "This test data model is for the Purchase application.",
    "visible": true,
    "modelKeys": [
    "ProductID"
    ],
    "root": {
    "displayName": "Products",
    "rootEntity": {
    "id": 393,
    "name": "Products",
    "primaryKeys": [
    "ProductID"
    ],
    "dataSource": "Orders_DS"
    }
    },
    "projectId": 141357,
    "versionId": 141358,
    "creationDate": "2017-03-10 11:10:01.159",
    "modifiedDate": "2017-03-10 11:10:01.159",
    "createdBy": "John",
    "modifiedBy": "John"
    }
  5. Review the properties that you want to update. For this example, the display name Products is identified to be changed to Supplier_Product.
Update the Identified Test Data Model
After you identify the test data model and the properties that you want to update, you can use the update test data model API to do the update.
Follow these steps:
  1. Access the following CA TDM Portal API:
    PUT https://<server>:<host>/TDMDataReservationService/api/ca/v1/testDataModels/{testDataModelId}
  2. Enter the security token in the 
    Authorization
     field as follows:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  3. Enter information in the following fields as follows:
    • testDataModelId
      Specifies the ID of the test data model that you want to update. For this example, the value is 410.
    • projectId
      Specifies the ID of the project that is related to the test data model for which you want to update the details. For this example, the value is 141357.
    • versionId
      Specifies the ID of the project version that is related to the test data model for which you want to update the details. For this example, the value is 141358.
    • testDataModel
      Specifies the payload that includes the test data model parameters. Specify the parameter values that you want to update. This payload includes the following parameters:
      • description
        Specifies the description of the test data model that you are creating. For this example, the value of the description is "This test data model is for the Purchase application."
      • modelKeys
        Specifies the list of model keys for the root. For this example, the value of the model key is ProductID, which is the primary key in the Products entity.
      • name
         Specifies the name of the test data model that you are updating. For this example, the value of the test data model name is Product_Purchase.
      • root
         
        Specifies the test data model root details.
      • visible
        Specifies whether you want this test data model to be visible to testers. For this example, the value is set to true.
      • displayName
         
        Specifies the display name of the model key. For this example, the value of the display name of the model key is Supplier_Product.
      • rootEntity
         
        Specifies the root entity details (entity data source and entity name).
      • dataSource
         
        Specifies the data source of the entity. For this example, the value is Orders_DS.
      • name
        Specifies the name of the entity. For this example, the value is Products.
      For this example, the display name (Products) for the model key is chosen for the update (Supplier_Product).
      {
      "description": "This test data model is for the Purchase application.",
      "modelKeys": [
      "ProductID"
      ],
      "name": "Product_Purchase",
      "root": {
      "displayName": "
      Supplier_Product
      ",
      "rootEntity": {
      "dataSource": "Orders_DS",
      "name": "Products"
      }
      },
      "visible": true
      }
  4. Run the API and review the response body. The following example response is generated for the test data model ID (410):
    {
    "id": 410,
    "name": "Product_Purchase",
    "description": "This test data model is for the Purchase application.",
    "visible": true,
    "modelKeys": [
    "ProductID"
    ],
    "root": {
    "displayName": "
    Supplier_Product
    ",
    "rootEntity": {
    "id": 393,
    "name": "Products",
    "primaryKeys": [
    "ProductID"
    ],
    "dataSource": "Orders_DS"
    }
    },
    "projectId": 141357,
    "versionId": 141358,
    "creationDate": "2017-03-10 11:10:01.159",
    "modifiedDate": "2017-03-10 11:43:12.703",
    "createdBy": "John",
    "modifiedBy": "John"
    }
  5. Review that the response includes the updated property. In this case, the display name for the model key is changed to Supplier_Product.
You have successfully updated a test data model.
Delete a Test Data Model
The process to delete a test data model is as follows:
Note:
 These examples use the sample Northwind database that is available for Microsoft SQL Server. Refer the Microsoft website to download the Northwind database.
Get the Security Token
Use the login API to log in and generate a security token. You use your CA TDM Portal login credentials to generate the security token. You can then use the same security token to perform all other operations. The security token remains valid for 24 hours. To get the security token and log into the CA TDM Portal, follow the instructions in the corresponding section in Update a Test Data Model.
Get the Project ID
Get the project ID that includes the required test data model. Note the project ID, because you will be using it in all the subsequent operations. To get the project ID, follow the detailed instructions in the corresponding section in Update a Test Data Model.
Summary of the example value used in this API is as follows:
  • Authorization:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
The following response is generated, note the project ID (141357):
{
"name": "Order",
"description": "This is Order Management project.",
"dateOrder": "YMD",
"id": 141357,
"inheritTables": true,
"timestampPrecision": 3,
"type": "DB",
"levels": [],
"created": null,
"updated": null,
"versions": [],
"grantedFunctions": []
},
{
"name": "StoreFront - Example Project - Oracle",
"description": "StoreFront - Oracle",
"dateOrder": "YMD",
"id": 1760,
"inheritTables": true,
"timestampPrecision": 6,
"type": "DB",
"levels": [],
"created": null,
"updated": null,
"versions": [],
"grantedFunctions": []
},
{
"name": "StoreFront - Example Project - SQL Server",
"description": "StoreFront - Example Project - SQL Server",
"dateOrder": "YMD",
"id": 2234,
"inheritTables": true,
"timestampPrecision": 3,
"type": "DB",
"levels": [],
"created": null,
"updated": null,
"versions": [],
"grantedFunctions": []
},
{
"name": "TDMPublish_Centrica",
"description": "TDMPublish_Centrica",
"dateOrder": "YMD",
"id": 7739,
"inheritTables": true,
"timestampPrecision": 3,
"type": "DB",
"levels": [],
"created": null,
"updated": null,
"versions": [],
"grantedFunctions": []
}
]
Get the Version ID
After you get the project ID, you must get the associated version ID. Note the version ID, because you will be using it in all the subsequent operations. To get the version ID associated with the retrieved project ID, follow the detailed instructions in the corresponding section in Update a Test Data Model.
Summary of the example values used in this API is as follows:
  • Authorization:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  • projectId:
     141357
The following example response is generated; note the version ID (141358):
[
{
"id": 141358,
"name": "1.0",
"created": "2017-03-07T07:28:09+0000",
"description": "This is Order Management version 1.0.",
"projectName": null,
"levelDetails": null,
"registeredObjectCount": 0,
"tablesUsed": null,
"isGeneric": false
}
]
Get Test Data Models for the Identified Project and Version
Get the list of test data models for your specific project and version. After you get the list, identify the test data model that you want to update. To get all the test data models for the retrieved project and version, follow the detailed instructions in the corresponding section in Update a Test Data Model.
Summary of the example values used in this API is as follows:
  • Authorization:
     Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  • projectId:
     141357
  • versionID:
     141358
The following response is generated:
{
"numberOfTestDataModels": 2,
"totalNumberOfTestDataModels": 2,
"testDataModelsList": [
{
"id": 386,
"name": "Orders",
"description": "This test data model is for Orders Management application.",
"visible": true,
"projectId": 141357,
"versionId": 141358
},
{
"id": 410,
"name": "Product_Purchase",
"description": "This test data model is for the Purchase application.",
"visible": true,
"projectId": 141357,
"versionId": 141358
}
]
}
Identify the test data model that you want to delete and note its ID. For this example, Product_Purchase with the ID 410 is chosen for the deletion.
Get Details of the Identified Test Data Model
After you note the test data model ID that you want to delete, you can retrieve its details to review the information in more detail. To get details of a specific test data model, follow the instructions in the corresponding section in Update a Test Data Model.
Summary of the example values used in this API is as follows:
  • Authorization:
     Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  • testDataModelId: 
    410
  • projectId:
     141357
  • versionId:
     141358
The following example response is generated for the Product_Purchase (410) test data model:
{
"id": 410,
"name": "Product_Purchase",
"description": "This test data model is for the Purchase application.",
"visible": true,
"modelKeys": [
"ProductID"
],
"root": {
"displayName": "Products",
"rootEntity": {
"id": 393,
"name": "Products",
"primaryKeys": [
"ProductID"
],
"dataSource": "Orders_DS"
}
},
"projectId": 141357,
"versionId": 141358,
"creationDate": "2017-03-10 11:10:01.159",
"modifiedDate": "2017-03-10 11:10:01.159",
"createdBy": "John",
"modifiedBy": "John"
}
Review the properties to confirm that you want to delete this test data model.
Delete the Identified Test Data Model
After you identify and confirm the appropriate test data model (410 in this case), you can go ahead and delete it.
Follows these steps:
  1. Access the following CA TDM Portal API:
    DELETE https://<server>:<host>/TDMDataReservationService/api/ca/v1/testDataModels/{testDataModelId}
  2. Enter the security token in the 
    Authorization
     field as follows:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  3. Enter information in the following fields as follows:
    • testDataModelId
      Specifies the ID of the test data model that you want to delete. For this example, the value of the test data model ID is 410.
    • projectId
      Specifies the ID of the project related to the test data model that you want to delete. For this example, the value of the project ID is 141357.
    • versionId
      Specifies the ID of the project version related to the test data model that you want to delete. For this example, the value of the version ID is 141358.
  4. Run the API and review the response body:
    {
    "message": "Test Data Model is deleted successfully."
    }
  5. Review that the response includes a message that states that the test data model (410) is deleted successfully.
Verify the Deletion
After you run the delete API to delete the test data model, you can verify whether the test data model is appearing in the project version. 
Follow these steps:
  1. Access the following CA TDM Portal API:
    GET https://<server>:<host>/TDMDataReservationService/api/ca/v1/testDataModels
  2. Enter the security token in the 
    Authorization
     field as follows:
    Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBZG1pbmlU0VSX0lEBTExfUFJPSkVDVFNcIjpbMTAwXX0ifQ.7T1CyH_xQK0vQcBB7dLojUxm8ENTeRRrdOa-RQ5l4Ro
  3. Enter information in the following fields:
    • projectId
      Specifies the ID of the project for which you want to retrieve test data models. For this example, the value is 141357.
    • versionId
      Specifies the ID of the project version for which you want to retrieve test data models. For this example, the value is 141358.
  4. Run the API and review the response body. The following example response is generated:
    {
    "numberOfTestDataModels": 1,
    "totalNumberOfTestDataModels": 1,
    "testDataModelsList": [
    {
    "id": 386,
    "name": "Orders",
    "description": "This test data model is for Orders Management application.",
    "visible": false,
    "projectId": 141357,
    "versionId": 141358
    }
    ]
    }
  5. Note that the specified project version now does not  include the two test data models. The Product_Purchase test data model is no longer available, which is correct.
You have successfully deleted a test data model.