From 8d0732dd10bac5739fe839f38759cac8d77640c7 Mon Sep 17 00:00:00 2001 From: HiranyaKavishani Date: Fri, 29 Dec 2023 01:31:08 +0800 Subject: [PATCH] Adding integration test cases for APIProduct Versioning (#13286) --- .../publisher-api.yaml.sha256 | 2 +- .../clients/publisher/api/openapi.yaml | 100 ++++++++++++ .../clients/publisher/docs/APIDTO.md | 1 + .../clients/publisher/docs/APIProductDTO.md | 3 + .../clients/publisher/docs/ApiProductsApi.md | 74 +++++++++ .../publisher/api/v1/ApiProductsApi.java | 143 ++++++++++++++++++ .../clients/publisher/api/v1/dto/APIDTO.java | 31 +++- .../publisher/api/v1/dto/APIProductDTO.java | 89 ++++++++++- .../src/main/resources/publisher-api.yaml | 65 +++++++- .../test/impl/ApiProductTestHelper.java | 17 ++- .../am/integration/test/impl/DtoFactory.java | 5 +- .../test/impl/RestAPIPublisherImpl.java | 47 +++--- .../revision/APIProductRevisionTestCase.java | 5 +- .../APIProductCreationTestCase.java | 116 ++++++++++++-- .../lifecycle/APIProductLifecycleTest.java | 3 +- .../restapi/admin/EnvironmentTestCase.java | 3 +- .../WorkflowApprovalExecutorTest.java | 3 +- pom.xml | 4 +- 18 files changed, 668 insertions(+), 43 deletions(-) diff --git a/modules/integration/tests-common/clients/publisher/.openapi-generator/publisher-api.yaml.sha256 b/modules/integration/tests-common/clients/publisher/.openapi-generator/publisher-api.yaml.sha256 index 22bf2e2101..8e761e046a 100644 --- a/modules/integration/tests-common/clients/publisher/.openapi-generator/publisher-api.yaml.sha256 +++ b/modules/integration/tests-common/clients/publisher/.openapi-generator/publisher-api.yaml.sha256 @@ -1 +1 @@ -e8e65082ff752153ae78c9fa8bbb657df3d59b3273fb70c9dcac53fc4f8915b3 \ No newline at end of file +98955626332fa43085771a8f446ec2195a5b9335f93b89baf64b29bafcafbedd \ No newline at end of file diff --git a/modules/integration/tests-common/clients/publisher/api/openapi.yaml b/modules/integration/tests-common/clients/publisher/api/openapi.yaml index 7d115b7d96..d47406610b 100644 --- a/modules/integration/tests-common/clients/publisher/api/openapi.yaml +++ b/modules/integration/tests-common/clients/publisher/api/openapi.yaml @@ -11899,6 +11899,95 @@ paths: source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" "https://127.0.0.1:9443/api/am/publisher/v4/api-products/890a4f4d-09eb-4877-a323-57f6ce2ed79b/restore-revision?revisionId=e0824883-3e86-403a-aec1-22bbc454eb7c"' x-accepts: application/json + /api-products/copy-api-products: + post: + description: | + This operation can be used to create a new version of an existing API Products. The new version is specified as `newVersion` query parameter. New API Product will be in `CREATED` state. + operationId: createNewAPIProductVersion + parameters: + - description: Version of the new API Product. + explode: true + in: query + name: newVersion + required: true + schema: + maxLength: 30 + type: string + style: form + - description: Specifies whether new API Product should be added as default + version. + explode: true + in: query + name: defaultVersion + required: false + schema: + default: false + type: boolean + style: form + - description: | + **API Product ID** consisting of the **UUID** of the API Product. + The combination of the provider, name and the version of the API Product is also accepted as a valid API Product ID. + Should be formatted as **provider-name-version**. + explode: true + in: query + name: apiProductId + required: true + schema: + type: string + style: form + responses: + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/APIProduct' + description: | + Created. + Successful response with the newly created API Product as entity in the body. Location header contains URL of newly created API Product. + headers: + Location: + description: | + The URL of the newly created API Product. + explode: false + schema: + type: string + style: simple + "400": + content: + application/json: + example: + code: 400 + message: Bad Request + description: Invalid request or validation error + moreInfo: "" + error: [] + schema: + $ref: '#/components/schemas/Error' + description: Bad Request. Invalid request or validation error. + "404": + content: + application/json: + example: + code: 404 + message: Not Found + description: The specified resource does not exist + moreInfo: "" + error: [] + schema: + $ref: '#/components/schemas/Error' + description: Not Found. The specified resource does not exist. + security: + - OAuth2Security: + - apim:api_publish + - apim:api_manage + summary: Create a New API Product Version + tags: + - API Products + x-code-samples: + - lang: Curl + source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/publisher/v4/api-products/copy-api-products?newVersion=2.0&defaultVersion=false&apiproductId=2fd14eb8-b828-4013-b448-0739d2e76bf7"' + x-accepts: application/json /api-products/export: get: description: | @@ -17082,12 +17171,14 @@ components: transport: - http - https + version: 1.0.0 tags: - pizza - food revisionId: 1 visibleTenants: [] cacheTimeout: 300 + isDefaultVersion: false apis: - name: PizzaShackAPI apiId: 01234567-0123-0123-0123-012345678901 @@ -17139,6 +17230,12 @@ components: maxLength: 60 minLength: 1 type: string + version: + example: 1.0.0 + maxLength: 30 + minLength: 1 + pattern: ^[^~!@#;:%^*()+={}|\\<>"',&/$\[\]\s+\/]+$ + type: string description: description: A brief description about the API example: This is a simple API for Pizza Shack online pizza delivery store @@ -17160,6 +17257,9 @@ components: enableSchemaValidation: example: false type: boolean + isDefaultVersion: + example: false + type: boolean isRevision: example: false type: boolean diff --git a/modules/integration/tests-common/clients/publisher/docs/APIDTO.md b/modules/integration/tests-common/clients/publisher/docs/APIDTO.md index 1b635027e6..a3a8119b18 100644 --- a/modules/integration/tests-common/clients/publisher/docs/APIDTO.md +++ b/modules/integration/tests-common/clients/publisher/docs/APIDTO.md @@ -31,6 +31,7 @@ Name | Type | Description | Notes **policies** | **List<String>** | | [optional] **apiThrottlingPolicy** | **String** | The API level throttling policy selected for the particular API | [optional] **authorizationHeader** | **String** | Name of the Authorization header used for invoking the API. If it is not set, Authorization header name specified in tenant or system level will be used. | [optional] +**apiKeyHeader** | **String** | Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. | [optional] **securityScheme** | **List<String>** | Types of API security, the current API secured with. It can be either OAuth2 or mutual SSL or both. If it is not set OAuth2 will be set as the security for the current API. | [optional] **maxTps** | [**APIMaxTpsDTO**](APIMaxTpsDTO.md) | | [optional] **visibility** | [**VisibilityEnum**](#VisibilityEnum) | The visibility level of the API. Accepts one of the following. PUBLIC, PRIVATE, RESTRICTED. | [optional] diff --git a/modules/integration/tests-common/clients/publisher/docs/APIProductDTO.md b/modules/integration/tests-common/clients/publisher/docs/APIProductDTO.md index 91ea7557aa..29695adb4b 100644 --- a/modules/integration/tests-common/clients/publisher/docs/APIProductDTO.md +++ b/modules/integration/tests-common/clients/publisher/docs/APIProductDTO.md @@ -9,11 +9,13 @@ Name | Type | Description | Notes **id** | **String** | UUID of the api product | [optional] [readonly] **name** | **String** | Name of the API Product | **context** | **String** | | [optional] +**version** | **String** | | [optional] **description** | **String** | A brief description about the API | [optional] **provider** | **String** | If the provider value is not given, the user invoking the API will be used as the provider. | [optional] **hasThumbnail** | **Boolean** | | [optional] **state** | **String** | State of the API product. Only published api products are visible on the Developer Portal | [optional] **enableSchemaValidation** | **Boolean** | | [optional] +**isDefaultVersion** | **Boolean** | | [optional] **isRevision** | **Boolean** | | [optional] **revisionedApiProductId** | **String** | UUID of the api product registry artifact | [optional] [readonly] **revisionId** | **Integer** | | [optional] @@ -30,6 +32,7 @@ Name | Type | Description | Notes **policies** | **List<String>** | | [optional] **apiThrottlingPolicy** | **String** | The API level throttling policy selected for the particular API Product | [optional] **authorizationHeader** | **String** | Name of the Authorization header used for invoking the API. If it is not set, Authorization header name specified in tenant or system level will be used. | [optional] +**apiKeyHeader** | **String** | Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. | [optional] **securityScheme** | **List<String>** | Types of API security, the current API secured with. It can be either OAuth2 or mutual SSL or both. If it is not set OAuth2 will be set as the security for the current API. | [optional] **subscriptionAvailability** | [**SubscriptionAvailabilityEnum**](#SubscriptionAvailabilityEnum) | The subscription availability. Accepts one of the following. CURRENT_TENANT, ALL_TENANTS or SPECIFIC_TENANTS. | [optional] **subscriptionAvailableTenants** | **List<String>** | | [optional] diff --git a/modules/integration/tests-common/clients/publisher/docs/ApiProductsApi.md b/modules/integration/tests-common/clients/publisher/docs/ApiProductsApi.md index 869926f3c5..1e2ca93790 100644 --- a/modules/integration/tests-common/clients/publisher/docs/ApiProductsApi.md +++ b/modules/integration/tests-common/clients/publisher/docs/ApiProductsApi.md @@ -5,6 +5,7 @@ All URIs are relative to *https://apis.wso2.com/api/am/publisher/v4* Method | HTTP request | Description ------------- | ------------- | ------------- [**createAPIProduct**](ApiProductsApi.md#createAPIProduct) | **POST** /api-products | Create a New API Product +[**createNewAPIProductVersion**](ApiProductsApi.md#createNewAPIProductVersion) | **POST** /api-products/copy-api-products | Create a New API Product Version [**deleteAPIProduct**](ApiProductsApi.md#deleteAPIProduct) | **DELETE** /api-products/{apiProductId} | Delete an API Product [**getAPIProduct**](ApiProductsApi.md#getAPIProduct) | **GET** /api-products/{apiProductId} | Get Details of an API Product [**getAPIProductSwagger**](ApiProductsApi.md#getAPIProductSwagger) | **GET** /api-products/{apiProductId}/swagger | Get Swagger Definition @@ -84,6 +85,79 @@ Name | Type | Description | Notes **400** | Bad Request. Invalid request or validation error. | - | **415** | Unsupported Media Type. The entity of the request was not in a supported format. | - | + +# **createNewAPIProductVersion** +> APIProductDTO createNewAPIProductVersion(newVersion, apiProductId, defaultVersion) + +Create a New API Product Version + +This operation can be used to create a new version of an existing API Products. The new version is specified as `newVersion` query parameter. New API Product will be in `CREATED` state. + +### Example +```java +// Import classes: +import org.wso2.am.integration.clients.publisher.api.ApiClient; +import org.wso2.am.integration.clients.publisher.api.ApiException; +import org.wso2.am.integration.clients.publisher.api.Configuration; +import org.wso2.am.integration.clients.publisher.api.auth.*; +import org.wso2.am.integration.clients.publisher.api.models.*; +import org.wso2.am.integration.clients.publisher.api.v1.ApiProductsApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://apis.wso2.com/api/am/publisher/v4"); + + // Configure OAuth2 access token for authorization: OAuth2Security + OAuth OAuth2Security = (OAuth) defaultClient.getAuthentication("OAuth2Security"); + OAuth2Security.setAccessToken("YOUR ACCESS TOKEN"); + + ApiProductsApi apiInstance = new ApiProductsApi(defaultClient); + String newVersion = "newVersion_example"; // String | Version of the new API Product. + String apiProductId = "apiProductId_example"; // String | **API Product ID** consisting of the **UUID** of the API Product. The combination of the provider, name and the version of the API Product is also accepted as a valid API Product ID. Should be formatted as **provider-name-version**. + Boolean defaultVersion = false; // Boolean | Specifies whether new API Product should be added as default version. + try { + APIProductDTO result = apiInstance.createNewAPIProductVersion(newVersion, apiProductId, defaultVersion); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling ApiProductsApi#createNewAPIProductVersion"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **newVersion** | **String**| Version of the new API Product. | + **apiProductId** | **String**| **API Product ID** consisting of the **UUID** of the API Product. The combination of the provider, name and the version of the API Product is also accepted as a valid API Product ID. Should be formatted as **provider-name-version**. | + **defaultVersion** | **Boolean**| Specifies whether new API Product should be added as default version. | [optional] [default to false] + +### Return type + +[**APIProductDTO**](APIProductDTO.md) + +### Authorization + +[OAuth2Security](../README.md#OAuth2Security) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +**201** | Created. Successful response with the newly created API Product as entity in the body. Location header contains URL of newly created API Product. | * Location - The URL of the newly created API Product.
| +**400** | Bad Request. Invalid request or validation error. | - | +**404** | Not Found. The specified resource does not exist. | - | + # **deleteAPIProduct** > deleteAPIProduct(apiProductId, ifMatch) diff --git a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/ApiProductsApi.java b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/ApiProductsApi.java index ebf588dbb9..07dcb2beb0 100644 --- a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/ApiProductsApi.java +++ b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/ApiProductsApi.java @@ -177,6 +177,149 @@ public okhttp3.Call createAPIProductAsync(APIProductDTO apIProductDTO, final Api localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); return localVarCall; } + /** + * Build call for createNewAPIProductVersion + * @param newVersion Version of the new API Product. (required) + * @param apiProductId **API Product ID** consisting of the **UUID** of the API Product. The combination of the provider, name and the version of the API Product is also accepted as a valid API Product ID. Should be formatted as **provider-name-version**. (required) + * @param defaultVersion Specifies whether new API Product should be added as default version. (optional, default to false) + * @param _callback Callback for upload/download progress + * @return Call to execute + * @throws ApiException If fail to serialize the request body object + * @http.response.details + + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created API Product as entity in the body. Location header contains URL of newly created API Product. * Location - The URL of the newly created API Product.
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public okhttp3.Call createNewAPIProductVersionCall(String newVersion, String apiProductId, Boolean defaultVersion, final ApiCallback _callback) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/api-products/copy-api-products"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + if (newVersion != null) { + localVarQueryParams.addAll(localVarApiClient.parameterToPair("newVersion", newVersion)); + } + + if (defaultVersion != null) { + localVarQueryParams.addAll(localVarApiClient.parameterToPair("defaultVersion", defaultVersion)); + } + + if (apiProductId != null) { + localVarQueryParams.addAll(localVarApiClient.parameterToPair("apiProductId", apiProductId)); + } + + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + final String[] localVarContentTypes = { + + }; + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + + String[] localVarAuthNames = new String[] { "OAuth2Security" }; + return localVarApiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); + } + + @SuppressWarnings("rawtypes") + private okhttp3.Call createNewAPIProductVersionValidateBeforeCall(String newVersion, String apiProductId, Boolean defaultVersion, final ApiCallback _callback) throws ApiException { + + // verify the required parameter 'newVersion' is set + if (newVersion == null) { + throw new ApiException("Missing the required parameter 'newVersion' when calling createNewAPIProductVersion(Async)"); + } + + // verify the required parameter 'apiProductId' is set + if (apiProductId == null) { + throw new ApiException("Missing the required parameter 'apiProductId' when calling createNewAPIProductVersion(Async)"); + } + + + okhttp3.Call localVarCall = createNewAPIProductVersionCall(newVersion, apiProductId, defaultVersion, _callback); + return localVarCall; + + } + + /** + * Create a New API Product Version + * This operation can be used to create a new version of an existing API Products. The new version is specified as `newVersion` query parameter. New API Product will be in `CREATED` state. + * @param newVersion Version of the new API Product. (required) + * @param apiProductId **API Product ID** consisting of the **UUID** of the API Product. The combination of the provider, name and the version of the API Product is also accepted as a valid API Product ID. Should be formatted as **provider-name-version**. (required) + * @param defaultVersion Specifies whether new API Product should be added as default version. (optional, default to false) + * @return APIProductDTO + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created API Product as entity in the body. Location header contains URL of newly created API Product. * Location - The URL of the newly created API Product.
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public APIProductDTO createNewAPIProductVersion(String newVersion, String apiProductId, Boolean defaultVersion) throws ApiException { + ApiResponse localVarResp = createNewAPIProductVersionWithHttpInfo(newVersion, apiProductId, defaultVersion); + return localVarResp.getData(); + } + + /** + * Create a New API Product Version + * This operation can be used to create a new version of an existing API Products. The new version is specified as `newVersion` query parameter. New API Product will be in `CREATED` state. + * @param newVersion Version of the new API Product. (required) + * @param apiProductId **API Product ID** consisting of the **UUID** of the API Product. The combination of the provider, name and the version of the API Product is also accepted as a valid API Product ID. Should be formatted as **provider-name-version**. (required) + * @param defaultVersion Specifies whether new API Product should be added as default version. (optional, default to false) + * @return ApiResponse<APIProductDTO> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created API Product as entity in the body. Location header contains URL of newly created API Product. * Location - The URL of the newly created API Product.
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public ApiResponse createNewAPIProductVersionWithHttpInfo(String newVersion, String apiProductId, Boolean defaultVersion) throws ApiException { + okhttp3.Call localVarCall = createNewAPIProductVersionValidateBeforeCall(newVersion, apiProductId, defaultVersion, null); + Type localVarReturnType = new TypeToken(){}.getType(); + return localVarApiClient.execute(localVarCall, localVarReturnType); + } + + /** + * Create a New API Product Version (asynchronously) + * This operation can be used to create a new version of an existing API Products. The new version is specified as `newVersion` query parameter. New API Product will be in `CREATED` state. + * @param newVersion Version of the new API Product. (required) + * @param apiProductId **API Product ID** consisting of the **UUID** of the API Product. The combination of the provider, name and the version of the API Product is also accepted as a valid API Product ID. Should be formatted as **provider-name-version**. (required) + * @param defaultVersion Specifies whether new API Product should be added as default version. (optional, default to false) + * @param _callback The callback to be executed when the API call finishes + * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object + * @http.response.details + + + + + +
Status Code Description Response Headers
201 Created. Successful response with the newly created API Product as entity in the body. Location header contains URL of newly created API Product. * Location - The URL of the newly created API Product.
400 Bad Request. Invalid request or validation error. -
404 Not Found. The specified resource does not exist. -
+ */ + public okhttp3.Call createNewAPIProductVersionAsync(String newVersion, String apiProductId, Boolean defaultVersion, final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = createNewAPIProductVersionValidateBeforeCall(newVersion, apiProductId, defaultVersion, _callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } /** * Build call for deleteAPIProduct * @param apiProductId **API Product ID** consisting of the **UUID** of the API Product. Using the **UUID** in the API call is recommended. (required) diff --git a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java index be8c66c016..2ccfa175ca 100644 --- a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java +++ b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java @@ -256,6 +256,10 @@ public AudienceEnum read(final JsonReader jsonReader) throws IOException { @SerializedName(SERIALIZED_NAME_AUTHORIZATION_HEADER) private String authorizationHeader; + public static final String SERIALIZED_NAME_API_KEY_HEADER = "apiKeyHeader"; + @SerializedName(SERIALIZED_NAME_API_KEY_HEADER) + private String apiKeyHeader; + public static final String SERIALIZED_NAME_SECURITY_SCHEME = "securityScheme"; @SerializedName(SERIALIZED_NAME_SECURITY_SCHEME) private List securityScheme = null; @@ -1151,6 +1155,29 @@ public void setAuthorizationHeader(String authorizationHeader) { } + public APIDTO apiKeyHeader(String apiKeyHeader) { + + this.apiKeyHeader = apiKeyHeader; + return this; + } + + /** + * Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. + * @return apiKeyHeader + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "apiKey", value = "Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. ") + + public String getApiKeyHeader() { + return apiKeyHeader; + } + + + public void setApiKeyHeader(String apiKeyHeader) { + this.apiKeyHeader = apiKeyHeader; + } + + public APIDTO securityScheme(List securityScheme) { this.securityScheme = securityScheme; @@ -1921,6 +1948,7 @@ public boolean equals(Object o) { Objects.equals(this.policies, API.policies) && Objects.equals(this.apiThrottlingPolicy, API.apiThrottlingPolicy) && Objects.equals(this.authorizationHeader, API.authorizationHeader) && + Objects.equals(this.apiKeyHeader, API.apiKeyHeader) && Objects.equals(this.securityScheme, API.securityScheme) && Objects.equals(this.maxTps, API.maxTps) && Objects.equals(this.visibility, API.visibility) && @@ -1957,7 +1985,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(id, name, description, context, version, provider, lifeCycleStatus, wsdlInfo, wsdlUrl, responseCachingEnabled, cacheTimeout, hasThumbnail, isDefaultVersion, isRevision, revisionedApiId, revisionId, enableSchemaValidation, enableSubscriberVerification, type, audience, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, securityScheme, maxTps, visibility, visibleRoles, visibleTenants, mediationPolicies, apiPolicies, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, accessControl, accessControlRoles, businessInformation, corsConfiguration, websubSubscriptionConfiguration, workflowStatus, createdTime, lastUpdatedTimestamp, lastUpdatedTime, endpointConfig, endpointImplementationType, scopes, operations, threatProtectionPolicies, categories, keyManagers, serviceInfo, advertiseInfo, gatewayVendor, asyncTransportProtocols); + return Objects.hash(id, name, description, context, version, provider, lifeCycleStatus, wsdlInfo, wsdlUrl, responseCachingEnabled, cacheTimeout, hasThumbnail, isDefaultVersion, isRevision, revisionedApiId, revisionId, enableSchemaValidation, enableSubscriberVerification, type, audience, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, apiKeyHeader, securityScheme, maxTps, visibility, visibleRoles, visibleTenants, mediationPolicies, apiPolicies, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, accessControl, accessControlRoles, businessInformation, corsConfiguration, websubSubscriptionConfiguration, workflowStatus, createdTime, lastUpdatedTimestamp, lastUpdatedTime, endpointConfig, endpointImplementationType, scopes, operations, threatProtectionPolicies, categories, keyManagers, serviceInfo, advertiseInfo, gatewayVendor, asyncTransportProtocols); } @@ -1990,6 +2018,7 @@ public String toString() { sb.append(" policies: ").append(toIndentedString(policies)).append("\n"); sb.append(" apiThrottlingPolicy: ").append(toIndentedString(apiThrottlingPolicy)).append("\n"); sb.append(" authorizationHeader: ").append(toIndentedString(authorizationHeader)).append("\n"); + sb.append(" apiKeyHeader: ").append(toIndentedString(apiKeyHeader)).append("\n"); sb.append(" securityScheme: ").append(toIndentedString(securityScheme)).append("\n"); sb.append(" maxTps: ").append(toIndentedString(maxTps)).append("\n"); sb.append(" visibility: ").append(toIndentedString(visibility)).append("\n"); diff --git a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIProductDTO.java b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIProductDTO.java index 23cbfba4b7..7e6ade971e 100644 --- a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIProductDTO.java +++ b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIProductDTO.java @@ -52,6 +52,10 @@ public class APIProductDTO { @SerializedName(SERIALIZED_NAME_CONTEXT) private String context; + public static final String SERIALIZED_NAME_VERSION = "version"; + @SerializedName(SERIALIZED_NAME_VERSION) + private String version; + public static final String SERIALIZED_NAME_DESCRIPTION = "description"; @SerializedName(SERIALIZED_NAME_DESCRIPTION) private String description; @@ -72,6 +76,10 @@ public class APIProductDTO { @SerializedName(SERIALIZED_NAME_ENABLE_SCHEMA_VALIDATION) private Boolean enableSchemaValidation; + public static final String SERIALIZED_NAME_IS_DEFAULT_VERSION = "isDefaultVersion"; + @SerializedName(SERIALIZED_NAME_IS_DEFAULT_VERSION) + private Boolean isDefaultVersion; + public static final String SERIALIZED_NAME_IS_REVISION = "isRevision"; @SerializedName(SERIALIZED_NAME_IS_REVISION) private Boolean isRevision; @@ -279,6 +287,10 @@ public ApiTypeEnum read(final JsonReader jsonReader) throws IOException { @SerializedName(SERIALIZED_NAME_AUTHORIZATION_HEADER) private String authorizationHeader; + public static final String SERIALIZED_NAME_API_KEY_HEADER = "apiKeyHeader"; + @SerializedName(SERIALIZED_NAME_API_KEY_HEADER) + private String apiKeyHeader; + public static final String SERIALIZED_NAME_SECURITY_SCHEME = "securityScheme"; @SerializedName(SERIALIZED_NAME_SECURITY_SCHEME) private List securityScheme = null; @@ -461,6 +473,29 @@ public void setContext(String context) { } + public APIProductDTO version(String version) { + + this.version = version; + return this; + } + + /** + * Get version + * @return version + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "1.0.0", value = "") + + public String getVersion() { + return version; + } + + + public void setVersion(String version) { + this.version = version; + } + + public APIProductDTO description(String description) { this.description = description; @@ -576,6 +611,29 @@ public void setEnableSchemaValidation(Boolean enableSchemaValidation) { } + public APIProductDTO isDefaultVersion(Boolean isDefaultVersion) { + + this.isDefaultVersion = isDefaultVersion; + return this; + } + + /** + * Get isDefaultVersion + * @return isDefaultVersion + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "false", value = "") + + public Boolean isIsDefaultVersion() { + return isDefaultVersion; + } + + + public void setIsDefaultVersion(Boolean isDefaultVersion) { + this.isDefaultVersion = isDefaultVersion; + } + + public APIProductDTO isRevision(Boolean isRevision) { this.isRevision = isRevision; @@ -944,6 +1002,29 @@ public void setAuthorizationHeader(String authorizationHeader) { } + public APIProductDTO apiKeyHeader(String apiKeyHeader) { + + this.apiKeyHeader = apiKeyHeader; + return this; + } + + /** + * Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. + * @return apiKeyHeader + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "apiKey", value = "Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. ") + + public String getApiKeyHeader() { + return apiKeyHeader; + } + + + public void setApiKeyHeader(String apiKeyHeader) { + this.apiKeyHeader = apiKeyHeader; + } + + public APIProductDTO securityScheme(List securityScheme) { this.securityScheme = securityScheme; @@ -1324,11 +1405,13 @@ public boolean equals(Object o) { return Objects.equals(this.id, apIProduct.id) && Objects.equals(this.name, apIProduct.name) && Objects.equals(this.context, apIProduct.context) && + Objects.equals(this.version, apIProduct.version) && Objects.equals(this.description, apIProduct.description) && Objects.equals(this.provider, apIProduct.provider) && Objects.equals(this.hasThumbnail, apIProduct.hasThumbnail) && Objects.equals(this.state, apIProduct.state) && Objects.equals(this.enableSchemaValidation, apIProduct.enableSchemaValidation) && + Objects.equals(this.isDefaultVersion, apIProduct.isDefaultVersion) && Objects.equals(this.isRevision, apIProduct.isRevision) && Objects.equals(this.revisionedApiProductId, apIProduct.revisionedApiProductId) && Objects.equals(this.revisionId, apIProduct.revisionId) && @@ -1345,6 +1428,7 @@ public boolean equals(Object o) { Objects.equals(this.policies, apIProduct.policies) && Objects.equals(this.apiThrottlingPolicy, apIProduct.apiThrottlingPolicy) && Objects.equals(this.authorizationHeader, apIProduct.authorizationHeader) && + Objects.equals(this.apiKeyHeader, apIProduct.apiKeyHeader) && Objects.equals(this.securityScheme, apIProduct.securityScheme) && Objects.equals(this.subscriptionAvailability, apIProduct.subscriptionAvailability) && Objects.equals(this.subscriptionAvailableTenants, apIProduct.subscriptionAvailableTenants) && @@ -1365,7 +1449,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(id, name, context, description, provider, hasThumbnail, state, enableSchemaValidation, isRevision, revisionedApiProductId, revisionId, responseCachingEnabled, cacheTimeout, visibility, visibleRoles, visibleTenants, accessControl, accessControlRoles, apiType, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, securityScheme, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, businessInformation, corsConfiguration, createdTime, lastUpdatedTimestamp, lastUpdatedTime, gatewayVendor, apis, scopes, categories, workflowStatus); + return Objects.hash(id, name, context, version, description, provider, hasThumbnail, state, enableSchemaValidation, isDefaultVersion, isRevision, revisionedApiProductId, revisionId, responseCachingEnabled, cacheTimeout, visibility, visibleRoles, visibleTenants, accessControl, accessControlRoles, apiType, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, apiKeyHeader, securityScheme, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, businessInformation, corsConfiguration, createdTime, lastUpdatedTimestamp, lastUpdatedTime, gatewayVendor, apis, scopes, categories, workflowStatus); } @@ -1376,11 +1460,13 @@ public String toString() { sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" context: ").append(toIndentedString(context)).append("\n"); + sb.append(" version: ").append(toIndentedString(version)).append("\n"); sb.append(" description: ").append(toIndentedString(description)).append("\n"); sb.append(" provider: ").append(toIndentedString(provider)).append("\n"); sb.append(" hasThumbnail: ").append(toIndentedString(hasThumbnail)).append("\n"); sb.append(" state: ").append(toIndentedString(state)).append("\n"); sb.append(" enableSchemaValidation: ").append(toIndentedString(enableSchemaValidation)).append("\n"); + sb.append(" isDefaultVersion: ").append(toIndentedString(isDefaultVersion)).append("\n"); sb.append(" isRevision: ").append(toIndentedString(isRevision)).append("\n"); sb.append(" revisionedApiProductId: ").append(toIndentedString(revisionedApiProductId)).append("\n"); sb.append(" revisionId: ").append(toIndentedString(revisionId)).append("\n"); @@ -1397,6 +1483,7 @@ public String toString() { sb.append(" policies: ").append(toIndentedString(policies)).append("\n"); sb.append(" apiThrottlingPolicy: ").append(toIndentedString(apiThrottlingPolicy)).append("\n"); sb.append(" authorizationHeader: ").append(toIndentedString(authorizationHeader)).append("\n"); + sb.append(" apiKeyHeader: ").append(toIndentedString(apiKeyHeader)).append("\n"); sb.append(" securityScheme: ").append(toIndentedString(securityScheme)).append("\n"); sb.append(" subscriptionAvailability: ").append(toIndentedString(subscriptionAvailability)).append("\n"); sb.append(" subscriptionAvailableTenants: ").append(toIndentedString(subscriptionAvailableTenants)).append("\n"); diff --git a/modules/integration/tests-common/clients/publisher/src/main/resources/publisher-api.yaml b/modules/integration/tests-common/clients/publisher/src/main/resources/publisher-api.yaml index 83cba82ebd..15c9492378 100644 --- a/modules/integration/tests-common/clients/publisher/src/main/resources/publisher-api.yaml +++ b/modules/integration/tests-common/clients/publisher/src/main/resources/publisher-api.yaml @@ -6604,6 +6604,60 @@ paths: source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" "https://127.0.0.1:9443/api/am/publisher/v4/api-products/890a4f4d-09eb-4877-a323-57f6ce2ed79b/restore-revision?revisionId=e0824883-3e86-403a-aec1-22bbc454eb7c"' + /api-products/copy-api-products: + #-------------------------------------------------------- + # Create new product version from the existing API Product + #-------------------------------------------------------- + post: + tags: + - API Products + summary: Create a New API Product Version + description: | + This operation can be used to create a new version of an existing API Products. The new version is specified as `newVersion` query parameter. New API Product will be in `CREATED` state. + parameters: + - name: newVersion + in: query + description: Version of the new API Product. + required: true + schema: + maxLength: 30 + type: string + - name: defaultVersion + in: query + description: Specifies whether new API Product should be added as default version. + schema: + type: boolean + default: false + - $ref: '#/components/parameters/apiProductId-Q' + responses: + 201: + description: | + Created. + Successful response with the newly created API Product as entity in the body. Location header contains URL of newly created API Product. + headers: + Location: + description: | + The URL of the newly created API Product. + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/APIProduct' + 400: + $ref: '#/components/responses/BadRequest' + 404: + $ref: '#/components/responses/NotFound' + security: + - OAuth2Security: + - apim:api_publish + - apim:api_manage + x-code-samples: + - lang: Curl + source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/publisher/v4/api-products/copy-api-products?newVersion=2.0&defaultVersion=false&apiproductId=2fd14eb8-b828-4013-b448-0739d2e76bf7"' + operationId: createNewAPIProductVersion + /api-products/export: get: tags: @@ -9288,6 +9342,12 @@ components: minLength: 1 type: string example: pizzaproduct + version: + maxLength: 30 + minLength: 1 + type: string + pattern: '^[^~!@#;:%^*()+={}|\\<>"'',&/$\[\]\s+\/]+$' + example: 1.0.0 description: type: string description: A brief description about the API @@ -9309,6 +9369,9 @@ components: enableSchemaValidation: type: boolean example: false + isDefaultVersion: + type: boolean + example: false isRevision: type: boolean example: false @@ -12511,4 +12574,4 @@ components: apim:tier_manage: View, update and delete throttling policies apim:api_list_view: View, Retrieve API list apim:api_definition_view: View, Retrieve API definition - apim:policies_import_export: Export and import policies related operations \ No newline at end of file + apim:policies_import_export: Export and import policies related operations diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/ApiProductTestHelper.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/ApiProductTestHelper.java index 451bd8ffbf..99d9d1ba8a 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/ApiProductTestHelper.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/ApiProductTestHelper.java @@ -47,14 +47,14 @@ public ApiProductTestHelper(RestAPIPublisherImpl restAPIPublisher, RestAPIStoreI this.restAPIStore = restAPIStore; } - public APIProductDTO createAPIProductInPublisher(String provider, String name, String context, - List apisToBeUsed, List policies) + public APIProductDTO createAPIProductInPublisher(String provider, String name, String context, String version, + List apisToBeUsed, List policies) throws ApiException { // Select resources from APIs to be used by APIProduct List resourcesForProduct = getResourcesForProduct(apisToBeUsed); // Generate APIProductDTO - APIProductDTO apiProductDTO = DtoFactory.createApiProductDTO(provider, name, context, + APIProductDTO apiProductDTO = DtoFactory.createApiProductDTO(provider, name, context, version, resourcesForProduct, policies); // Create APIProduct and validate response code @@ -67,6 +67,7 @@ public APIProductDTO createAPIProductInPublisher(String provider, String name, S // Validate mandatory fields returned in response data Assert.assertTrue(provider.equalsIgnoreCase(responseData.getProvider())); Assert.assertEquals(responseData.getName(), name); + Assert.assertEquals(responseData.getVersion(), version); if ("carbon.super".equals(restAPIPublisher.tenantDomain)) { Assert.assertEquals(responseData.getContext(), context); } else { @@ -314,7 +315,15 @@ private void verifyApiDtoWithApiProduct(org.wso2.am.integration.clients.store.ap Assert.assertEquals(apiDTO.getId(), apiProductDTO.getId()); Assert.assertEquals(apiDTO.getAdditionalProperties(), apiProductDTO.getAdditionalProperties()); verifyBusinessInformation(apiDTO.getBusinessInformation(), apiProductDTO.getBusinessInformation()); - Assert.assertEquals(apiDTO.getContext(), apiProductDTO.getContext()); + + String context = apiProductDTO.getContext(); + String version = apiProductDTO.getVersion(); + if (context.startsWith("/{version}")) { + Assert.assertEquals(apiDTO.getContext(), context.replace("{version}", version)); + } else { + Assert.assertEquals(apiDTO.getContext(), context.concat("/").concat(version)); + } + Assert.assertEquals(apiDTO.getDescription(), apiProductDTO.getDescription()); Assert.assertEquals(apiDTO.getLifeCycleStatus(), apiProductDTO.getState()); Assert.assertEquals(apiDTO.getName(), apiProductDTO.getName()); diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/DtoFactory.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/DtoFactory.java index 8d233c6551..2c330f8efe 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/DtoFactory.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/DtoFactory.java @@ -43,14 +43,15 @@ public static ExportThrottlePolicyDTO createExportThrottlePolicyDTO(String type, return exportPolicy; } - public static APIProductDTO createApiProductDTO(String provider, String name, String context, List apis, - List polices) { + public static APIProductDTO createApiProductDTO(String provider, String name, String context, String version, + List apis, List polices) { return new APIProductDTO(). accessControl(APIProductDTO.AccessControlEnum.NONE). visibility(APIProductDTO.VisibilityEnum.PUBLIC). apis(apis). context(context). name(name). + version(version). policies(polices). provider(provider); } diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIPublisherImpl.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIPublisherImpl.java index 94a8aaa301..49e473418a 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIPublisherImpl.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIPublisherImpl.java @@ -521,6 +521,27 @@ public HttpResponse copyAPI(String newVersion, String apiId, Boolean isDefault) return response; } + + /** + * copy API from existing API Product + * + * @param newVersion - new version of the API Product + * @param apiProductId - existing API Product Id + * @param isDefault - make the default version + * @return - http response object + * @throws APIManagerIntegrationTestException - Throws if error occurred at API Product copy operation + */ + public HttpResponse copyAPIProduct(String newVersion, String apiProductId, Boolean isDefault) throws ApiException { + + APIProductDTO apiProductDto = apiProductsApi.createNewAPIProductVersion(newVersion, apiProductId, isDefault); + HttpResponse response = null; + if (StringUtils.isNotEmpty(apiProductDto.getId())) { + response = new HttpResponse(apiProductDto.getId(), 200); + } + return response; + } + + /** * @param newVersion * @param apiId @@ -1701,7 +1722,7 @@ private void waitForDeployAPI(String apiUUID, String revisionUUID, String apiTyp if ("APIProduct".equals(apiType)) { APIProductDTO apiProduct = getApiProduct(revisionUUID); context = apiProduct.getContext(); - version = "1.0.0"; + version = apiProduct.getVersion(); provider = apiProduct.getProvider(); name = apiProduct.getName(); apiPolicy = apiProduct.getApiThrottlingPolicy(); @@ -1715,15 +1736,12 @@ private void waitForDeployAPI(String apiUUID, String revisionUUID, String apiTyp } APIInfoDTO apiInfo = restAPIGateway.getAPIInfo(apiUUID); if (apiInfo != null) { - if (!"APIProduct".equals(apiType)) { - if (context.startsWith("/{version}")) { - Assert.assertEquals(apiInfo.getContext(), context.replace("{version}", version)); - } else { - Assert.assertEquals(apiInfo.getContext(), context.concat("/").concat(version)); - } + if (context.startsWith("/{version}")) { + Assert.assertEquals(apiInfo.getContext(), context.replace("{version}", version)); } else { - Assert.assertEquals(apiInfo.getContext(), context); - + log.info("AAAAAAAAAA********************************************AAAAAAAAAA"); + log.info("context: " + context + " version: " + version); + Assert.assertEquals(apiInfo.getContext(), context.concat("/").concat(version)); } Assert.assertEquals(apiInfo.getName(), name); Assert.assertEquals(apiInfo.getProvider(), provider); @@ -1752,15 +1770,10 @@ private void waitForDeployAPI(String apiUUID, String revisionUUID, String apiTyp } apiInfo = restAPIGateway.getAPIInfo(apiUUID); if (apiInfo != null) { - if (!"APIProduct".equals(apiType)) { - if (context.startsWith("/{version}")) { - Assert.assertEquals(apiInfo.getContext(), context.replace("{version}", version)); - } else { - Assert.assertEquals(apiInfo.getContext(), context.concat("/").concat(version)); - } + if (context.startsWith("/{version}")) { + Assert.assertEquals(apiInfo.getContext(), context.replace("{version}", version)); } else { - Assert.assertEquals(apiInfo.getContext(), context); - + Assert.assertEquals(apiInfo.getContext(), context.concat("/").concat(version)); } Assert.assertEquals(apiInfo.getName(), name); Assert.assertEquals(apiInfo.getProvider(), provider); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/revision/APIProductRevisionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/revision/APIProductRevisionTestCase.java index a80b5b225e..d24e36c41f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/revision/APIProductRevisionTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/revision/APIProductRevisionTestCase.java @@ -79,10 +79,11 @@ public void testAddingAPIProductRevision() throws Exception { final String provider = UUID.randomUUID().toString(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); apiId = apiProductDTO.getId(); @@ -132,7 +133,7 @@ public void testDeployAPIProductRevisions() throws Exception { HttpResponse apiRevisionsDeployResponse = restAPIPublisher.deployAPIProductRevision(apiId, revisionUUID, apiRevisionDeployRequestList,"APIProduct"); assertEquals(apiRevisionsDeployResponse.getResponseCode(), HTTP_RESPONSE_CODE_CREATED, - "Unable to deploy API Product Revisions:" +apiRevisionsDeployResponse.getData()); + "Unable to deploy API Product Revisions:" + apiRevisionsDeployResponse.getData()); } @Test(groups = {"wso2.am"}, description = "Test UnDeploying API Product Revision to gateway environments", diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java index 7f6cb9e9cb..0318d32994 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/APIProductCreationTestCase.java @@ -16,6 +16,7 @@ package org.wso2.am.integration.tests.apiproduct; +import com.google.gson.Gson; import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpStatus; @@ -47,7 +48,9 @@ import org.wso2.am.integration.test.impl.InvocationStatusCodes; import org.wso2.am.integration.test.utils.APIManagerIntegrationTestException; import org.wso2.am.integration.test.utils.base.APIMIntegrationConstants; +import org.wso2.am.integration.test.utils.bean.APILifeCycleAction; import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APIRequest; import org.wso2.am.integration.tests.api.lifecycle.APIManagerLifecycleBaseTest; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; @@ -59,6 +62,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -67,6 +71,8 @@ import java.util.Map; import java.util.UUID; +import javax.ws.rs.core.Response; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -81,6 +87,7 @@ public class APIProductCreationTestCase extends APIManagerLifecycleBaseTest { private static final String SCOPE = "restricted_scope"; private ApiTestHelper apiTestHelper; private ApiProductTestHelper apiProductTestHelper; + private String apiProductId2; private String resourcePath; @Factory(dataProvider = "userModeDataProvider") @@ -140,10 +147,11 @@ public void testCreateAndInvokeApiProduct() throws Exception { final String provider = user.getUserName(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); waitForAPIDeployment(); @@ -208,6 +216,88 @@ public void testCreateAndInvokeApiProduct() throws Exception { Assert.assertEquals(httpResponse.getHeaders().get("Version"), "v2"); } + @Test(groups = {"wso2.am"}, description = "Create new version and publish") + public void testAPIProductNewVersionCreation() throws Exception { + + String APIVersionNew = "2.0.0"; + // Pre-Conditions : Create APIs + List apisToBeUsed = new ArrayList<>(); + APIDTO apiOne = apiTestHelper.createApiOne(getBackendEndServiceEndPointHttp("wildcard/resources")); + APIDTO apiTwo = apiTestHelper.createApiTwo(getBackendEndServiceEndPointHttp("wildcard/resources")); + apisToBeUsed.add(apiOne); + apisToBeUsed.add(apiTwo); + + // Step 1 : Create APIProduct + final String provider = user.getUserName(); + final String name = UUID.randomUUID().toString(); + final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; + + List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); + + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, + apisToBeUsed, policies); + createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); + waitForAPIDeployment(); + + // Step 2 : Verify created APIProduct in publisher + apiProductTestHelper.verfiyApiProductInPublisher(apiProductDTO); + + apiProductDTO = publishAPIProduct(apiProductDTO.getId()); + HttpResponse apiProductCopyResponse = restAPIPublisher.copyAPIProduct(APIVersionNew, + apiProductDTO.getId(), false); + + Assert.assertEquals(apiProductCopyResponse.getResponseCode(), Response.Status.OK.getStatusCode(), + "Response Code Mismatch"); + apiProductId2 = apiProductCopyResponse.getData(); + + //test the copied api Product + APIProductDTO newApiProductDTO = restAPIPublisher.getApiProduct(apiProductId2); + Assert.assertEquals(newApiProductDTO.getVersion(), APIVersionNew); + } + + + @Test(groups = {"wso2.am"}, description = "Create new version by setting isDefaultVersion and publish") + public void testAPIProductNewVersionCreationWithDefaultVersion() throws Exception { + // Pre-Conditions : Create APIs + List apisToBeUsed = new ArrayList<>(); + APIDTO apiOne = apiTestHelper.createApiOne(getBackendEndServiceEndPointHttp("wildcard/resources")); + APIDTO apiTwo = apiTestHelper.createApiTwo(getBackendEndServiceEndPointHttp("wildcard/resources")); + apisToBeUsed.add(apiOne); + apisToBeUsed.add(apiTwo); + + // Step 1 : Create APIProduct + final String provider = user.getUserName(); + final String name = UUID.randomUUID().toString(); + final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; + + List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); + + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, + apisToBeUsed, policies); + createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); + waitForAPIDeployment(); + + // Step 2 : Verify created APIProduct in publisher + apiProductTestHelper.verfiyApiProductInPublisher(apiProductDTO); + + String APIVersionNew = "2.0.0"; + apiProductDTO = publishAPIProduct(apiProductDTO.getId()); + HttpResponse apiProductCopyResponse = restAPIPublisher.copyAPIProduct(APIVersionNew, apiProductDTO.getId(), true); + Assert.assertEquals(apiProductCopyResponse.getResponseCode(), Response.Status.OK.getStatusCode(), + "Response Code Mismatch"); + + apiProductId2 = apiProductCopyResponse.getData(); + + //test the copied api Product + APIProductDTO newApiProductDTO = restAPIPublisher.getApiProduct(apiProductId2); + Assert.assertEquals(newApiProductDTO.getVersion(), APIVersionNew); + + boolean isDefaultVersion = Boolean.TRUE.equals(newApiProductDTO.isIsDefaultVersion()); + Assert.assertEquals(isDefaultVersion, true, "Copied API Product is not the default version"); + } + @Test(groups = {"wso2.am"}, description = "Test creation and invocation of API Product which depends " + "on a visibility restricted API") public void testCreateAndInvokeApiProductWithVisibilityRestrictedApi() throws Exception { @@ -224,10 +314,11 @@ public void testCreateAndInvokeApiProductWithVisibilityRestrictedApi() throws Ex final String provider = user.getUserName(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); waitForAPIDeployment(); @@ -287,10 +378,11 @@ public void testCreateAndInvokeApiProductWithScopes() throws Exception { final String provider = user.getUserName(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); waitForAPIDeployment(); @@ -357,10 +449,11 @@ public void testCreateAndInvokeApiProductWithOperationPoliciesInRequestApi() thr final String provider = user.getUserName(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); waitForAPIDeployment(); @@ -449,10 +542,11 @@ public void testCreateAndInvokeApiProductWithOperationPoliciesInResponseApi() th final String provider = user.getUserName(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); waitForAPIDeployment(); @@ -536,11 +630,12 @@ public void testCreateApiProductWithAdvertiseOnlyApi() throws Exception { final String provider = user.getUserName(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); // Step 1 : Create APIProduct - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); waitForAPIDeployment(); @@ -596,7 +691,9 @@ public void testCreateAndDeployApiProductWithMutualSSLEnabled() throws Exception String name = UUID.randomUUID().toString(); String context = "/" + UUID.randomUUID().toString(); List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + final String version = "1.0.0"; + + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); // Step 3: Enable Mutual SSL with client certificate @@ -649,11 +746,12 @@ public void testAPIProductSwaggerDefinition() throws Exception { final String provider = user.getUserName(); final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID().toString(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher( - provider, name, context, apisToBeUsed, policies); + provider, name, context, version, apisToBeUsed, policies); createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher); waitForAPIDeployment(); apiProductTestHelper.verfiyApiProductInPublisher(apiProductDTO); @@ -679,7 +777,7 @@ private File geTempFileWithContent(String swagger) throws Exception { out.close(); return temp; } - + @AfterClass(alwaysRun = true) public void cleanUpArtifacts() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/lifecycle/APIProductLifecycleTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/lifecycle/APIProductLifecycleTest.java index 9fa500f6ce..c41eaa809b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/lifecycle/APIProductLifecycleTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/apiproduct/lifecycle/APIProductLifecycleTest.java @@ -124,10 +124,11 @@ public void testCreateAPIProduct() throws Exception { } final String name = UUID.randomUUID().toString(); context = "/" + UUID.randomUUID(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); apiProductId = apiProductDTO.getId(); assert apiProductDTO.getState() != null; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/EnvironmentTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/EnvironmentTestCase.java index 5825d6366a..c9769b94e9 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/EnvironmentTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/EnvironmentTestCase.java @@ -482,9 +482,10 @@ private void addApiAndProductRevision() throws Exception { provider = provider + "@" + tenantDomain; } + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, + APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(provider, name, context, version, apisToBeUsed, policies); waitForAPIDeployment(); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/workflow/WorkflowApprovalExecutorTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/workflow/WorkflowApprovalExecutorTest.java index f62ab945a2..45b85a52d1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/workflow/WorkflowApprovalExecutorTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/workflow/WorkflowApprovalExecutorTest.java @@ -299,10 +299,11 @@ private void createAndDeployAPIProduct() throws Exception { final String name = UUID.randomUUID().toString(); final String context = "/" + UUID.randomUUID(); + final String version = "1.0.0"; List policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD); - apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(USER_SMITH, name, context, apisToBeUsed, + apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(USER_SMITH, name, context, version, apisToBeUsed, policies); apiProductId = apiProductDTO.getId(); assert apiProductDTO.getState() != null; diff --git a/pom.xml b/pom.xml index aa01ecbbad..0a58dc314c 100644 --- a/pom.xml +++ b/pom.xml @@ -1277,10 +1277,10 @@ 5.3.5 - 9.0.484 + 9.0.486 - 9.28.202 + 9.28.207 [9.0.0, 10.0.0)