Skip to content

Commit

Permalink
Merge pull request #13310 from CrowleyRajapakse/mynewmaster
Browse files Browse the repository at this point in the history
Adding AddHeader v2 policy with regular expression fix
  • Loading branch information
CrowleyRajapakse authored Jan 10, 2024
2 parents b0e9aed + aa6317d commit b0a5888
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"category": "Mediation",
"name": "addHeader",
"version": "v1",
"version": "v2",
"displayName": "Add Header",
"description": "This policy allows you to add a new header to the request",
"policyAttributes": [
{
"name": "headerName",
"displayName": "Header Name",
"description": "Name of the header to be added",
"validationRegex": "^([a-zA-Z_][a-zA-Z\\d_\\-\\ ]*)$",
"validationRegex": "^.+$",
"type": "String",
"required": true
},
{
"name": "headerValue",
"displayName": "Header Value",
"description": "Value of the header",
"validationRegex": "^([a-zA-Z\\d_][a-zA-Z\\d_\\-\\ ]*)$",
"validationRegex": "^.+$",
"type": "String",
"required": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,12 @@ public void testAPIInvocationAfterAddingNewOperationPolicy() throws Exception {
attributeMap.put("headerName", "TestHeader");
attributeMap.put("headerValue", "TestValue");

List<OperationPolicyDTO> opList = getPolicyList(policyName, policyMap, attributeMap);
opList.get(0).setPolicyVersion("v2");

APIOperationPoliciesDTO apiOperationPoliciesDTO = new APIOperationPoliciesDTO();
apiOperationPoliciesDTO.setRequest(getPolicyList(policyName, policyMap, attributeMap));
apiOperationPoliciesDTO.setResponse(getPolicyList(policyName, policyMap, attributeMap));
apiOperationPoliciesDTO.setRequest(opList);
apiOperationPoliciesDTO.setResponse(opList);

apidto.getOperations().get(0).setOperationPolicies(apiOperationPoliciesDTO);
restAPIPublisher.updateAPI(apidto);
Expand Down Expand Up @@ -596,9 +599,11 @@ public void testAPIInvocationAfterAddingNewMultipleOperationPolicies() throws Ex
requestPolicyList.add(getPolicyList(policyList[i], policyMap, null).get(0));
responsePolicyList.add(getPolicyList(policyList[i], policyMap, null).get(0));
}
List<OperationPolicyDTO> opList = getPolicyList(policyName, policyMap, attributeMap);
opList.get(0).setPolicyVersion("v2");

requestPolicyList.add(getPolicyList(policyName, policyMap, attributeMap).get(0));
responsePolicyList.add(getPolicyList(policyName, policyMap, attributeMap).get(0));
requestPolicyList.add(opList.get(0));
responsePolicyList.add(opList.get(0));
apiOperationPoliciesDTO.setRequest(requestPolicyList);
apiOperationPoliciesDTO.setResponse(responsePolicyList);
apidto.getOperations().get(0).setOperationPolicies(apiOperationPoliciesDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,17 @@ public void testGatewayRestAPI() throws Exception {
faultAttributeMap.put("headerName", "FaultTestHeader");
faultAttributeMap.put("headerValue", "FaultTestValue");

List<OperationPolicyDTO> requestOpList = getPolicyList(policyName, commonPolicyMap, requestAttributeMap);
requestOpList.get(0).setPolicyVersion("v2");
List<OperationPolicyDTO> responseOpList = getPolicyList(policyName, commonPolicyMap, responseAttributeMap);
responseOpList.get(0).setPolicyVersion("v2");
List<OperationPolicyDTO> faultOpList = getPolicyList(policyName, commonPolicyMap, faultAttributeMap);
faultOpList.get(0).setPolicyVersion("v2");

APIOperationPoliciesDTO apiOperationPoliciesDTO = new APIOperationPoliciesDTO();
apiOperationPoliciesDTO.setRequest(getPolicyList(policyName, commonPolicyMap, requestAttributeMap));
apiOperationPoliciesDTO.setResponse(getPolicyList(policyName, commonPolicyMap, responseAttributeMap));
apiOperationPoliciesDTO.setFault(getPolicyList(policyName, commonPolicyMap, faultAttributeMap));
apiOperationPoliciesDTO.setRequest(requestOpList);
apiOperationPoliciesDTO.setResponse(responseOpList);
apiOperationPoliciesDTO.setFault(faultOpList);

APIDTO api = restAPIPublisher.getAPIByID(apiId);
api.getOperations().get(0).setOperationPolicies(apiOperationPoliciesDTO);
Expand Down

0 comments on commit b0a5888

Please sign in to comment.