Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into jdk21
Browse files Browse the repository at this point in the history
  • Loading branch information
chamilaadhi committed Dec 2, 2023
2 parents 22836f0 + caf52e5 commit 965f19c
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
node-version: '10.x'
- name: Build product-apim with Test.
run: mvn clean install --file pom.xml -DskipBenchMarkTest=true
run: mvn clean install --file pom.xml -DskipBenchMarkTest=true -DskipRestartTests=true
env:
PRODUCT_APIM_TEST_GROUPS: ${{ matrix.segment }}
- name: Prepare upload testng report
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ For additional support information please refer to http://wso2.com/support

For more information on WSO2 API Manager please visit https://wso2.com/api-management/

Survey On Open Source Community Communication
==================================

WSO2 wants to learn more about our open source software (OSS) community and your communication preferences to serve you better.

In addition, we may reach out to a small number of respondents to ask additional questions and offer a small gift.

Link to survey: https://forms.gle/h5q4M3K7vyXba3bK6


Known Issues of WSO2 API Manager
==================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10187,7 +10187,10 @@ paths:
style: simple
responses:
"200":
content: {}
content:
application/json:
schema:
type: string
description: |
OK.
Requested swagger document of the API is returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Name | Type | Description | Notes

<a name="getAPIProductSwagger"></a>
# **getAPIProductSwagger**
> getAPIProductSwagger(apiProductId, accept, ifNoneMatch)
> String getAPIProductSwagger(apiProductId, accept, ifNoneMatch)
Get Swagger Definition

Expand Down Expand Up @@ -261,7 +261,8 @@ public class Example {
String accept = "\"application/json\""; // String | Media types acceptable for the response. Default is application/json.
String ifNoneMatch = "ifNoneMatch_example"; // String | Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource.
try {
apiInstance.getAPIProductSwagger(apiProductId, accept, ifNoneMatch);
String result = apiInstance.getAPIProductSwagger(apiProductId, accept, ifNoneMatch);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ApiProductsApi#getAPIProductSwagger");
System.err.println("Status code: " + e.getCode());
Expand All @@ -283,7 +284,7 @@ Name | Type | Description | Notes

### Return type

null (empty response body)
**String**

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ private okhttp3.Call getAPIProductSwaggerValidateBeforeCall(String apiProductId,
* @param apiProductId **API Product ID** consisting of the **UUID** of the API Product. Using the **UUID** in the API call is recommended. (required)
* @param accept Media types acceptable for the response. Default is application/json. (optional, default to &quot;application/json&quot;)
* @param ifNoneMatch Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource. (optional)
* @return String
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
Expand All @@ -528,8 +529,9 @@ private okhttp3.Call getAPIProductSwaggerValidateBeforeCall(String apiProductId,
<tr><td> 406 </td><td> Not Acceptable. The requested media type is not supported. </td><td> - </td></tr>
</table>
*/
public void getAPIProductSwagger(String apiProductId, String accept, String ifNoneMatch) throws ApiException {
getAPIProductSwaggerWithHttpInfo(apiProductId, accept, ifNoneMatch);
public String getAPIProductSwagger(String apiProductId, String accept, String ifNoneMatch) throws ApiException {
ApiResponse<String> localVarResp = getAPIProductSwaggerWithHttpInfo(apiProductId, accept, ifNoneMatch);
return localVarResp.getData();
}

/**
Expand All @@ -538,7 +540,7 @@ public void getAPIProductSwagger(String apiProductId, String accept, String ifNo
* @param apiProductId **API Product ID** consisting of the **UUID** of the API Product. Using the **UUID** in the API call is recommended. (required)
* @param accept Media types acceptable for the response. Default is application/json. (optional, default to &quot;application/json&quot;)
* @param ifNoneMatch Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource. (optional)
* @return ApiResponse&lt;Void&gt;
* @return ApiResponse&lt;String&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
Expand All @@ -549,9 +551,10 @@ public void getAPIProductSwagger(String apiProductId, String accept, String ifNo
<tr><td> 406 </td><td> Not Acceptable. The requested media type is not supported. </td><td> - </td></tr>
</table>
*/
public ApiResponse<Void> getAPIProductSwaggerWithHttpInfo(String apiProductId, String accept, String ifNoneMatch) throws ApiException {
public ApiResponse<String> getAPIProductSwaggerWithHttpInfo(String apiProductId, String accept, String ifNoneMatch) throws ApiException {
okhttp3.Call localVarCall = getAPIProductSwaggerValidateBeforeCall(apiProductId, accept, ifNoneMatch, null);
return localVarApiClient.execute(localVarCall);
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand All @@ -572,10 +575,11 @@ public ApiResponse<Void> getAPIProductSwaggerWithHttpInfo(String apiProductId, S
<tr><td> 406 </td><td> Not Acceptable. The requested media type is not supported. </td><td> - </td></tr>
</table>
*/
public okhttp3.Call getAPIProductSwaggerAsync(String apiProductId, String accept, String ifNoneMatch, final ApiCallback<Void> _callback) throws ApiException {
public okhttp3.Call getAPIProductSwaggerAsync(String apiProductId, String accept, String ifNoneMatch, final ApiCallback<String> _callback) throws ApiException {

okhttp3.Call localVarCall = getAPIProductSwaggerValidateBeforeCall(apiProductId, accept, ifNoneMatch, _callback);
localVarApiClient.executeAsync(localVarCall, _callback);
Type localVarReturnType = new TypeToken<String>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5693,7 +5693,11 @@ paths:
The content type of the body.
schema:
type: string
content: {}
content:
application/json:
schema:
type: string
example: ""
304:
description: |
Not Modified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,13 @@ public String getSwaggerByID(String apiId) throws ApiException {
return response.getData();
}

public String getAPIProductSwaggerByID(String apiProductId) throws ApiException {

ApiResponse<String> response = apiProductsApi.getAPIProductSwaggerWithHttpInfo(apiProductId, null, null);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
return response.getData();
}

public String updateSwagger(String apiId, String definition) throws ApiException {

ApiResponse<String> apiResponse = apIsApi.updateAPISwaggerWithHttpInfo(apiId, null, definition, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.wso2.am.integration.clients.publisher.api.v1.dto.APIOperationPoliciesDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.APIProductDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.LifecycleStateDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.OpenAPIDefinitionValidationResponseDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.OperationPolicyDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.WorkflowResponseDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.APIOperationsDTO;
Expand All @@ -49,10 +50,13 @@
import org.wso2.am.integration.test.utils.bean.APILifeCycleState;
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;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
import org.wso2.carbon.integration.common.admin.client.UserManagementClient;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -65,6 +69,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class APIProductCreationTestCase extends APIManagerLifecycleBaseTest {

Expand All @@ -76,6 +81,7 @@ public class APIProductCreationTestCase extends APIManagerLifecycleBaseTest {
private static final String SCOPE = "restricted_scope";
private ApiTestHelper apiTestHelper;
private ApiProductTestHelper apiProductTestHelper;
private String resourcePath;

@Factory(dataProvider = "userModeDataProvider")
public APIProductCreationTestCase(TestUserMode userMode) {
Expand All @@ -96,6 +102,8 @@ public static Object[][] userModeDataProvider() {
public void initialize() throws Exception {

super.init(userMode);
resourcePath = TestConfigurationProvider.getResourceLocation() + File.separator + "oas" + File.separator + "v3"
+ File.separator + "api-product" + File.separator;
userManagementClient = new UserManagementClient(keyManagerContext.getContextUrls().getBackEndUrl(),
createSession(keyManagerContext));
apiTestHelper = new ApiTestHelper(restAPIPublisher, restAPIStore, getAMResourceLocation(),
Expand Down Expand Up @@ -605,6 +613,73 @@ public void testCreateAndDeployApiProductWithMutualSSLEnabled() throws Exception
Assert.assertNotNull(revisionUUID);
}

@Test(groups = { "wso2.am" }, description = "API product swagger definition reference verification")
public void testAPIProductSwaggerDefinition() throws Exception {

// Create a REST API using swagger definition
List<APIDTO> apisToBeUsed = new ArrayList<>();
String swaggerPath = resourcePath + "test-api-1-oas.yaml";
File definition = new File(swaggerPath);
org.json.JSONObject endpoints = new org.json.JSONObject();
endpoints.put("url", "https://test.com");

org.json.JSONObject endpointConfig = new org.json.JSONObject();
endpointConfig.put("endpoint_type", "http");
endpointConfig.put("production_endpoints", endpoints);
endpointConfig.put("sandbox_endpoints", endpoints);

List<String> tierList = new ArrayList<>();
tierList.add(APIMIntegrationConstants.API_TIER.SILVER);
tierList.add(APIMIntegrationConstants.API_TIER.GOLD);

org.json.JSONObject apiProperties = new org.json.JSONObject();
apiProperties.put("name", "testAPI1");
apiProperties.put("context", "/testapi1");
apiProperties.put("version", "1.0.0");
apiProperties.put("provider", user.getUserName());
apiProperties.put("endpointConfig", endpointConfig);
apiProperties.put("policies", tierList);

APIDTO apiOne = restAPIPublisher.importOASDefinition(definition, apiProperties.toString());
APIDTO apiTwo = apiTestHelper.createApiTwo(getBackendEndServiceEndPointHttp("wildcard/resources"));
apisToBeUsed.add(apiOne);
apisToBeUsed.add(apiTwo);

// Create API Product and verify in publisher
final String provider = user.getUserName();
final String name = UUID.randomUUID().toString();
final String context = "/" + UUID.randomUUID().toString();

List<String> policies = Arrays.asList(TIER_UNLIMITED, TIER_GOLD);

APIProductDTO apiProductDTO = apiProductTestHelper.createAPIProductInPublisher(
provider, name, context, apisToBeUsed, policies);
createAPIProductRevisionAndDeployUsingRest(apiProductDTO.getId(), restAPIPublisher);
waitForAPIDeployment();
apiProductTestHelper.verfiyApiProductInPublisher(apiProductDTO);
apiProductDTO = publishAPIProduct(apiProductDTO.getId());
String apiProductID = apiProductDTO.getId();

// Get api product definition and validate
String apiProductDefinition = restAPIPublisher.getAPIProductSwaggerByID(apiProductID);
validateDefinition(apiProductDefinition);
}

private void validateDefinition(String oasDefinition) throws Exception {
File file = geTempFileWithContent(oasDefinition);
OpenAPIDefinitionValidationResponseDTO responseDTO = restAPIPublisher.validateOASDefinition(file);
assertTrue(responseDTO.isIsValid());
}

private File geTempFileWithContent(String swagger) throws Exception {
File temp = File.createTempFile("swagger", ".json");
temp.deleteOnExit();
BufferedWriter out = new BufferedWriter(new FileWriter(temp));
out.write(swagger);
out.close();
return temp;
}

@AfterClass(alwaysRun = true)
public void cleanUpArtifacts() throws Exception {

Expand Down
Loading

0 comments on commit 965f19c

Please sign in to comment.