Skip to content

Commit

Permalink
Merge pull request #3277 from SanojPunchihewa/enrich-test
Browse files Browse the repository at this point in the history
Add testcase to validate Enrich mediator behaviour
  • Loading branch information
SanojPunchihewa authored Mar 20, 2024
2 parents 5fbbe26 + def5aa2 commit e28ec3c
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.esb.mediators.enrich;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
import org.wso2.esb.integration.common.utils.ESBIntegrationTest;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
* Tests Enrich mediator behaviour when invalid JSON request is proceeded with a valid JSON request
* Public issue https://github.com/wso2/micro-integrator/issues/3272
*/
public class EnrichInvalidAndValidJSONTestCase extends ESBIntegrationTest {

@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

super.init();
}

@Test(groups = "wso2.esb", description = "Tests enrich mediator with invalid JSON proceeded with valid JSON")
public void testEnrichInvalidAndValidJSON() throws Exception {

URL serviceUrl = new URL(getProxyServiceURLHttp("EnrichInvalidJSONProxy"));
String invalidPayload = "{\n" +
" \"minAmount\": [\n" +
" \"3000.00\"\n" +
" ],\n" +
" \"payPlan\": []\n" +
"}";

String validPayload = "{\n" +
" \"minAmount\": [\n" +
" \"3000.00\"\n" +
" ],\n" +
" \"payPlan\": [\n" +
" \"3\"\n" +
" ]\n" +
"}";

Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");

// Send invalid JSON payload
HttpResponse response = HttpRequestUtil.doPost(serviceUrl, invalidPayload, headers);
Assert.assertEquals(response.getResponseCode(), 202, "Expected response code didn't match for invalid JSON payload");

// Send valid JSON payload
HttpResponse response2 = HttpRequestUtil.doPost(serviceUrl, validPayload, headers);
Assert.assertEquals(response2.getResponseCode(), 200, "Expected response code didn't match for valid JSON payload");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 LCC. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="EnrichInvalidJSONProxy"
transports="http https"
startOnLoad="true">
<description/>
<target>
<inSequence>
<property expression="json-eval($.payPlan[0])" name="payPlan" scope="default" type="STRING"/>
<enrich>
<source clone="true" type="inline">
{"payPlan" :"{$ctx:payPlan}"}
</source>
<target action="child" xpath="json-eval($)"/>
</enrich>
<respond/>
</inSequence>
</target>
</proxy>
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<class name="org.wso2.carbon.esb.mediators.enrich.ESBJAVA4892EnrichPropertyTestCase"/>
<class name="org.wso2.carbon.esb.mediators.enrich.EI2084EnrichNamespaceAdditionTestCase"/>
<class name="org.wso2.carbon.esb.mediators.enrich.MI2479TargetTypeKeyWithoutActionTestCase"/>
<class name="org.wso2.carbon.esb.mediators.enrich.EnrichInvalidAndValidJSONTestCase"/>
<class name="org.wso2.carbon.esb.mediators.callout.CARBON15119DuplicateSOAPActionHeader"/>
<class name="org.wso2.carbon.esb.mediators.callout.ESBJAVA_4118_SOAPHeaderHandlingTest"/>
<class name="org.wso2.carbon.esb.mediators.callout.ESBJAVA_4239_HTTP_SC_HandlingTests"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@
<!-- Debezium Orbit version -->
<debezium.version>2.1.4.Final.wso2v1</debezium.version>

<synapse.version>4.0.0-wso2v90</synapse.version>
<synapse.version>4.0.0-wso2v97</synapse.version>
<imp.pkg.version.synapse>[4.0.0, 4.0.1)</imp.pkg.version.synapse>
<carbon.mediation.version>4.7.197</carbon.mediation.version>
<carbon.crypto.version>1.1.3</carbon.crypto.version>
Expand Down

0 comments on commit e28ec3c

Please sign in to comment.