From 7a1ac4da6abad48918cbe6103898fea92812779c Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 8 Nov 2023 11:31:17 +0530 Subject: [PATCH] Improve code --- .../operator/synchronizer/data_store.go | 2 +- .../wso2/apk/integration/api/BaseSteps.java | 5 ++ .../tests/api/APIDefinitionEndpoint.feature | 28 +++++------ .../tests/api/GlobalInterceptor.feature | 8 ++-- .../resources/tests/api/Interceptor.feature | 46 +++++++++---------- 5 files changed, 47 insertions(+), 42 deletions(-) diff --git a/adapter/internal/operator/synchronizer/data_store.go b/adapter/internal/operator/synchronizer/data_store.go index 4eee0495e..d08503d42 100644 --- a/adapter/internal/operator/synchronizer/data_store.go +++ b/adapter/internal/operator/synchronizer/data_store.go @@ -403,7 +403,7 @@ func (ods *OperatorDataStore) processGatewayState(gatewayDef *gwapiv1b1.Gateway, customRateLimitPolicies map[string]*dpv1alpha1.RateLimitPolicy) (GatewayState, []string, bool) { ods.mu.Lock() defer ods.mu.Unlock() - var updated bool + updated := false events := []string{} cachedGateway := ods.gatewayStore[utils.NamespacedName(gatewayDef)] diff --git a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java index de1142251..1643a27ca 100644 --- a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java +++ b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java @@ -245,6 +245,11 @@ public void waitForSeconds(int seconds) throws InterruptedException { Thread.sleep(seconds * 1000); } + @Then("I wait for api deployment") + public void waitAPIDeployment() throws InterruptedException { + waitForSeconds(10); + } + @Then("the response headers contains key {string} and value {string}") public void containsHeader(String key, String value) { key = Utils.resolveVariables(key, sharedContext.getValueStore()); diff --git a/test/cucumber-tests/src/test/resources/tests/api/APIDefinitionEndpoint.feature b/test/cucumber-tests/src/test/resources/tests/api/APIDefinitionEndpoint.feature index cf70177ce..f8b1c8326 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/APIDefinitionEndpoint.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/APIDefinitionEndpoint.feature @@ -7,13 +7,13 @@ Feature: API Definition Endpoint And make the API deployment request Then the response status code should be 200 Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-default/3.14/api-definition" with body "" And I eventually receive 200 response code, not accepting - |429| + | 429 | And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-default/api-definition" with body "" And I eventually receive 200 response code, not accepting - |429| + | 429 | Scenario: Testing custom API definition endpoint Given The system is ready @@ -23,19 +23,19 @@ Feature: API Definition Endpoint And make the API deployment request Then the response status code should be 200 Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-custom/3.14/docs" with body "" And I eventually receive 200 response code, not accepting - |429| + | 429 | And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-custom/docs" with body "" And I eventually receive 200 response code, not accepting - |429| + | 429 | And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-custom/api-definition" with body "" And I eventually receive 404 response code, not accepting - |429| + | 429 | And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-custom/3.14/api-definition" with body "" And I eventually receive 404 response code, not accepting - |429| + | 429 | Scenario: Testing a deleted production endpoint Given The system is ready @@ -44,14 +44,14 @@ Feature: API Definition Endpoint And the definition file "artifacts/definitions/employees_api.json" And make the API deployment request Then the response status code should be 200 - And I wait for 1 minute + And I wait for api deployment Then I set headers | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-default/3.14/api-definition" with body "" Then the response status code should be 404 And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-default/api-definition" with body "" Then the response status code should be 404 - + Scenario: Testing a deleted production endpoint Given The system is ready And I have a valid subscription @@ -63,7 +63,7 @@ Feature: API Definition Endpoint And the definition file "artifacts/definitions/employees_api.json" And make the API deployment request Then the response status code should be 200 - And I wait for 1 minute + And I wait for api deployment Then I set headers | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.sandbox.gw.wso2.com:9095/test-definition-default/3.14/api-definition" with body "" @@ -79,6 +79,6 @@ Feature: API Definition Endpoint Then the response status code should be Examples: - | apiID | expectedStatusCode | - | custom-api-definition-endpoint-test | 202 | - | default-api-definition-endpoint-test | 202 | + | apiID | expectedStatusCode | + | custom-api-definition-endpoint-test | 202 | + | default-api-definition-endpoint-test | 202 | diff --git a/test/cucumber-tests/src/test/resources/tests/api/GlobalInterceptor.feature b/test/cucumber-tests/src/test/resources/tests/api/GlobalInterceptor.feature index 41bff9d90..64bd4a25f 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/GlobalInterceptor.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/GlobalInterceptor.feature @@ -7,9 +7,9 @@ Feature: API Deployment with Global Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "579ba27a1e03e2fdf099d1b6745e265f2d495606" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/globalinterceptor/1.0.0/get" with body "" Then the response status code should be 200 And the response body should contain "\"Gw-Header\": \"GW-header-value\"" @@ -21,5 +21,5 @@ Feature: API Deployment with Global Interceptor Then the response status code should be Examples: - | apiID | expectedStatusCode | - | 579ba27a1e03e2fdf099d1b6745e265f2d495606 | 202 | \ No newline at end of file + | apiID | expectedStatusCode | + | 579ba27a1e03e2fdf099d1b6745e265f2d495606 | 202 | \ No newline at end of file diff --git a/test/cucumber-tests/src/test/resources/tests/api/Interceptor.feature b/test/cucumber-tests/src/test/resources/tests/api/Interceptor.feature index 9edeee430..ebe91519c 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/Interceptor.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/Interceptor.feature @@ -7,9 +7,9 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" Then the response status code should be 200 And the response body should not contain "\"Interceptor-Header\"" @@ -18,9 +18,9 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" Then the response status code should be 200 And the response body should contain "\"Interceptor-Header\": \"Interceptor-header-value\"" @@ -29,9 +29,9 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" Then the response status code should be 200 Then the response headers contains key "interceptor-response-header" and value "Interceptor-Response-header-value" @@ -41,9 +41,9 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" Then the response status code should be 200 Then the response headers contains key "interceptor-response-header" and value "Interceptor-Response-header-value" @@ -53,7 +53,7 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" @@ -65,7 +65,7 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" @@ -77,7 +77,7 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" @@ -89,9 +89,9 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" And the response body should contain "\"Interceptor-Header\": \"Interceptor-header-value\"" Then the response status code should be 200 @@ -101,20 +101,20 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" And the response body should not contain "\"Interceptor-Header\"" Then the response status code should be 200 Then the response headers not contains key "interceptor-response-header" Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/headers" with body "" And the response body should contain - |"Interceptor-Header": "Interceptor-header-value"| - |"Interceptor-Header-Apigroup": "Gold"| - |"Interceptor-Header-Apitier": "Unlimited"| + | "Interceptor-Header": "Interceptor-header-value" | + | "Interceptor-Header-Apigroup": "Gold" | + | "Interceptor-Header-Apitier": "Unlimited" | Then the response status code should be 200 Then the response headers contains key "interceptor-response-header" and value "Interceptor-Response-header-value" Then I use the APK Conf file "artifacts/apk-confs/interceptors/withRequestAndResponsetls.apk-conf" @@ -122,9 +122,9 @@ Feature: API Deployment with Interceptor And make the API deployment request Then the response status code should be 200 And the response body should contain "547961eeaafed989119c45ffc13f8b87bfda821d" - And I wait for 1 minute + And I wait for api deployment Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I send "GET" request to "https://default.gw.wso2.com:9095/interceptor/1.0.0/get" with body "" And the response body should contain "\"Interceptor-Header\": \"Interceptor-header-value\"" Then the response status code should be 200 @@ -136,5 +136,5 @@ Feature: API Deployment with Interceptor Then the response status code should be Examples: - | apiID | expectedStatusCode | - | 547961eeaafed989119c45ffc13f8b87bfda821d | 202 | \ No newline at end of file + | apiID | expectedStatusCode | + | 547961eeaafed989119c45ffc13f8b87bfda821d | 202 | \ No newline at end of file