From 35bbc2c5c08b37d0126b18c29630142eb209bf24 Mon Sep 17 00:00:00 2001 From: rathnapandi Date: Mon, 4 Dec 2023 14:27:01 -0700 Subject: [PATCH] - fix integration test --- .../axway/apim/api/model/OutboundProfile.java | 3 +- .../java/com/axway/apim/api/model/TagMap.java | 6 ++-- .../java/com/axway/apim/lib/utils/Utils.java | 4 +-- .../apim/api/model/OutboundProfileTest.java | 35 ++++++++++++++++++- .../apiimport/actions/APIQuotaManager.java | 2 -- .../OutboundMethodLevelTestIT.java | 19 +++++----- .../method-level-outboundbound-api-key.json | 3 +- 7 files changed, 54 insertions(+), 18 deletions(-) diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/OutboundProfile.java b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/OutboundProfile.java index bdb0c45ad..583c0800d 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/OutboundProfile.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/OutboundProfile.java @@ -2,6 +2,7 @@ import com.axway.apim.adapter.jackson.PolicyDeserializer; import com.axway.apim.lib.error.AppException; +import com.axway.apim.lib.utils.Utils; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.apache.commons.lang3.StringUtils; @@ -132,7 +133,7 @@ && policiesAreEqual(this.getRoutePolicy(), otherOutboundProfile.getRoutePolicy() && StringUtils.equalsIgnoreCase(this.getRouteType(), otherOutboundProfile.getRouteType()) && StringUtils.equalsIgnoreCase(this.getAuthenticationProfile(), otherOutboundProfile.getAuthenticationProfile()) - && (thisParameters == null || thisParameters.equals(otherParameters)); + && Utils.compareValues(thisParameters, otherParameters); } else { return false; } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/TagMap.java b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/TagMap.java index 6055c43f6..f5b932285 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/TagMap.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/TagMap.java @@ -1,6 +1,7 @@ package com.axway.apim.api.model; import java.util.LinkedHashMap; +import java.util.Map; import java.util.Objects; public class TagMap extends LinkedHashMap { @@ -15,9 +16,10 @@ public boolean equals(Object o) { if (!(o instanceof TagMap)) return false; TagMap otherTagMap = (TagMap) o; if (otherTagMap.size() != size()) return false; - for (String tagName : this.keySet()) { + for (Map.Entry entry : this.entrySet()) { + String tagName = entry.getKey(); if (!otherTagMap.containsKey(tagName)) return false; - String[] myTags = this.get(tagName); + String[] myTags = entry.getValue(); String[] otherTags = otherTagMap.get(tagName); if (!Objects.deepEquals(myTags, otherTags)) return false; } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/lib/utils/Utils.java b/modules/apim-adapter/src/main/java/com/axway/apim/lib/utils/Utils.java index ba8640eed..d430272e9 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/lib/utils/Utils.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/lib/utils/Utils.java @@ -48,7 +48,7 @@ public class Utils { private static final Logger LOG = LoggerFactory.getLogger(Utils.class); - public static final String MASKED_PASSWORD = "********"; + public static final String MASKED_VALUE = "********"; public enum FedKeyType { FilterCircuit(""), OAuthAppProfile(""); @@ -368,7 +368,7 @@ public static boolean compareValues(Object actualValue, Object desiredValue) { } public static String getEncryptedPassword() { - return MASKED_PASSWORD; + return MASKED_VALUE; } public static String createFileName(String host, String stage, String prefix) throws AppException { diff --git a/modules/apim-adapter/src/test/java/com/axway/apim/api/model/OutboundProfileTest.java b/modules/apim-adapter/src/test/java/com/axway/apim/api/model/OutboundProfileTest.java index 438d92d95..0d82d0d12 100644 --- a/modules/apim-adapter/src/test/java/com/axway/apim/api/model/OutboundProfileTest.java +++ b/modules/apim-adapter/src/test/java/com/axway/apim/api/model/OutboundProfileTest.java @@ -1,10 +1,16 @@ package com.axway.apim.api.model; +import com.axway.apim.lib.utils.Utils; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import org.testng.Assert; import org.testng.annotations.Test; import com.axway.apim.lib.error.AppException; +import java.util.List; + public class OutboundProfileTest { @Test public void testWithCustomRequestPolicy() throws AppException { @@ -146,4 +152,31 @@ public void testDefaultValueRoute() throws AppException { actualProfile.setRoutePolicy(null); Assert.assertEquals(actualProfile.getRouteType(), "proxy", "The route type is proxy"); } -} \ No newline at end of file + + @Test + public void equalOutboundProfileWithMethod() throws JsonProcessingException { + String source = "{\n" + + " \"7024b732-4c36-4583-a122-4f2da87d5ff3\": {\n" + + " \"apiId\": \"fb7ff6b2-406d-4063-ab0a-9e06d1480ec3\",\n" + + " \"apiMethodId\": \"a03014c4-de43-4b9c-be05-10f09e5b33ff\",\n" + + " \"authenticationProfile\": \"HTTP Basic outbound Test 193\",\n" + + " \"parameters\": [\n" + + " {\n" + + " \"additional\": true,\n" + + " \"exclude\": false,\n" + + " \"name\": \"additionalOutboundParam\",\n" + + " \"paramType\": \"header\",\n" + + " \"required\": false,\n" + + " \"type\": \"string\",\n" + + " \"value\": \"Test-Value\"\n" + + " }\n" + + " ],\n" + + " \"routeType\": \"proxy\"\n" + + " }\n" + + " }"; + + ObjectMapper objectMapper = new ObjectMapper(); + OutboundProfile outboundProfiles = objectMapper.readValue(source, OutboundProfile.class); + Assert.assertTrue(Utils.compareValues(outboundProfiles, outboundProfiles)); + } +} diff --git a/modules/apis/src/main/java/com/axway/apim/apiimport/actions/APIQuotaManager.java b/modules/apis/src/main/java/com/axway/apim/apiimport/actions/APIQuotaManager.java index 1d1e04351..64d03ad1f 100644 --- a/modules/apis/src/main/java/com/axway/apim/apiimport/actions/APIQuotaManager.java +++ b/modules/apis/src/main/java/com/axway/apim/apiimport/actions/APIQuotaManager.java @@ -71,8 +71,6 @@ public void updateRestrictions(List actualRestrictions, List mergedRestrictions = addOrMergeRestriction(actualRestrictions, desiredRestrictions); populateMethodId(createdAPI, mergedRestrictions); // If there is an actual API, remove the restrictions for the current actual API diff --git a/modules/apis/src/test/java/com/axway/apim/test/methodLevel/OutboundMethodLevelTestIT.java b/modules/apis/src/test/java/com/axway/apim/test/methodLevel/OutboundMethodLevelTestIT.java index c09c66e6f..bfc6f9780 100644 --- a/modules/apis/src/test/java/com/axway/apim/test/methodLevel/OutboundMethodLevelTestIT.java +++ b/modules/apis/src/test/java/com/axway/apim/test/methodLevel/OutboundMethodLevelTestIT.java @@ -20,25 +20,25 @@ public class OutboundMethodLevelTestIT extends TestNGCitrusTestRunner { private ImportTestAction swaggerImport; - + @CitrusTest @Test @Parameters("context") public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException { swaggerImport = new ImportTestAction(); description("Validate Outbound Method level settings are applied"); - + variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true)); variable("apiPath", "/basic-outbound-method-level-api-${apiNumber}"); variable("apiName", "Basic Outbound Method-Level-API-${apiNumber}"); - - echo("####### Try to replicate an API having Outbound Method-Level settings declared #######"); + + echo("####### Try to replicate an API having Outbound Method-Level settings declared #######"); createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json"); createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/methodLevel/method-level-outboundbound-api-key.json"); createVariable("state", "unpublished"); createVariable("expectedReturnCode", "0"); createVariable("outboundProfileName", "HTTP Basic outbound Test ${apiNumber}"); swaggerImport.doExecute(context); - + echo("####### Validate the FE-API has been configured with outbound HTTP-Basic on method level #######"); http(builder -> builder.client("apiManager").send().get("/proxies").header("Content-Type", "application/json")); http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON) @@ -48,21 +48,22 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio .extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId") .extractFromPayload("$.[?(@.path=='${apiPath}')].apiId", "backendApiId") ); - + http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}/operations").header("Content-Type", "application/json")); http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON) .extractFromPayload("$.[?(@.name=='getOrderById')].id", "apiMethodId")); - + http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}").header("Content-Type", "application/json")); http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON) .validate("$.[?(@.id=='${apiId}')].outboundProfiles.${apiMethodId}.authenticationProfile", "${outboundProfileName}") .validate("$.[?(@.id=='${apiId}')].outboundProfiles.${apiMethodId}.apiId", "${backendApiId}") ); - - echo("####### Perform a No-Change #######"); + + echo("####### Perform a No-Change #######"); createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json"); createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/methodLevel/method-level-outboundbound-api-key.json"); createVariable("state", "unpublished"); + createVariable("enforce", "false"); createVariable("expectedReturnCode", "10"); createVariable("outboundProfileName", "HTTP Basic outbound Test ${apiNumber}"); swaggerImport.doExecute(context); diff --git a/modules/apis/src/test/resources/com/axway/apim/test/files/methodLevel/method-level-outboundbound-api-key.json b/modules/apis/src/test/resources/com/axway/apim/test/files/methodLevel/method-level-outboundbound-api-key.json index d69a005fe..d03367378 100644 --- a/modules/apis/src/test/resources/com/axway/apim/test/files/methodLevel/method-level-outboundbound-api-key.json +++ b/modules/apis/src/test/resources/com/axway/apim/test/files/methodLevel/method-level-outboundbound-api-key.json @@ -25,6 +25,7 @@ "name":"additionalOutboundParam", "required":false, "type":"string", + "format": null, "paramType":"header", "value":"Test-Value", "exclude":false, @@ -43,4 +44,4 @@ "type":"http_basic" } ] -} \ No newline at end of file +}