Skip to content

Commit

Permalink
- fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Dec 4, 2023
1 parent 568d1f3 commit 35bbc2c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String[]> {
Expand All @@ -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<String, String[]> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<key type='FilterCircuit'>"), OAuthAppProfile("<key type='OAuthAppProfile'>");
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -146,4 +152,31 @@ public void testDefaultValueRoute() throws AppException {
actualProfile.setRoutePolicy(null);
Assert.assertEquals(actualProfile.getRouteType(), "proxy", "The route type is proxy");
}
}

@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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public void updateRestrictions(List<QuotaRestriction> actualRestrictions, List<Q
}
// Load the entire current default quota
APIQuota currentDefaultQuota = quotaManager.getDefaultQuota(type);
LOG.debug("Default Quota : {}", currentDefaultQuota);
LOG.debug("API manager role : {}", APIManagerAdapter.getInstance().hasAdminAccount());
List<QuotaRestriction> mergedRestrictions = addOrMergeRestriction(actualRestrictions, desiredRestrictions);
populateMethodId(createdAPI, mergedRestrictions);
// If there is an actual API, remove the restrictions for the current actual API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"name":"additionalOutboundParam",
"required":false,
"type":"string",
"format": null,
"paramType":"header",
"value":"Test-Value",
"exclude":false,
Expand All @@ -43,4 +44,4 @@
"type":"http_basic"
}
]
}
}

0 comments on commit 35bbc2c

Please sign in to comment.