Skip to content

Commit

Permalink
Add integration tests for synapse expressions
Browse files Browse the repository at this point in the history
Add integration tests for synapse expressions
Related to /issues/3749
  • Loading branch information
GDLMadushanka committed Dec 3, 2024
1 parent 7671dd3 commit 8c52729
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public void setId(int i) {
public String getId() {
return null;
}

@Override
public boolean reInitialize() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public boolean reInitialize() {
public String getId() {
return null;
}

@Override
public boolean reInitialize() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.synapse.expression.test;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.esb.integration.common.utils.CarbonLogReader;
import org.wso2.esb.integration.common.utils.ESBIntegrationTest;
import org.wso2.esb.integration.common.utils.clients.SimpleHttpClient;

import java.util.HashMap;
import java.util.Map;

import static org.testng.Assert.assertTrue;

/**
* Testcase to test Synapse Expressions to fetch registry, registry property, path query and function params
*/
public class SynapseExpressionTestCase extends ESBIntegrationTest {

private CarbonLogReader carbonLogReader;
private static final String targetApiName = "synapseexpression_api";

@BeforeClass(alwaysRun = true)
public void uploadSynapseConfig() throws Exception {
super.init();
verifyAPIExistence(targetApiName);
carbonLogReader = new CarbonLogReader();
carbonLogReader.start();
}

@Test(groups = "wso2.esb", description = "Testcase to test Synapse Expressions to fetch registry, registry " +
"property, path query and function params")
public void testSynapseExpressions() throws Exception {
String contentType = "application/json";
String payload = "{\"hello\": \"world\"}";
String url = getApiInvocationURL(targetApiName);
url = url + "/abc/hello/pqr?qparam1=zxc&qparam2=uio";

Map<String, String> headers = new HashMap<>(1);
headers.put("Content-Type", contentType);

SimpleHttpClient httpClient = new SimpleHttpClient();
httpClient.doPost(url, headers, payload, contentType);

carbonLogReader.checkForLog("pathParam1 = abc, pathParam2 = pqr, queryParam1 = zxc, queryParam2 = uio," +
" regProp = hello world, regValue = John", DEFAULT_TIMEOUT);
String logs = carbonLogReader.getLogs();
assertTrue(logs.contains("pathParam1 = abc"));
assertTrue(logs.contains("pathParam2 = pqr"));
assertTrue(logs.contains("queryParam1 = zxc"));
assertTrue(logs.contains("queryParam2 = uio"));
assertTrue(logs.contains("regProp = hello world"));
assertTrue(logs.contains("regValue = John"));
assertTrue(logs.contains("funcParam1 = hello"));
assertTrue(logs.contains("funcParam2 = world"));
carbonLogReader.stop();
}

@AfterClass(alwaysRun = true)
public void destroy() throws Exception {
super.cleanup();
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
</packages>
</test>

<test name="Synapse-expressions-Test" preserve-order="true" verbose="2">
<packages>
<package name="org.wso2.carbon.esb.synapse.expression.test"/>
</packages>
</test>

<!-- Disabled due to jenkins failure with "no space left on device" -->
<!--<test name="Test-Multiple-servers" preserve-order="true" verbose="2">-->
<!--<classes>-->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@
<version.jaxb.api>2.4.0-b180830.0359</version.jaxb.api>
<com.sun.jaxb.version>2.3.0</com.sun.jaxb.version>
<com.sun.jaxb.impl.version>2.3.1</com.sun.jaxb.impl.version>
<synapse.version>4.0.0-wso2v143</synapse.version>
<synapse.version>4.0.0-wso2v144</synapse.version>
<imp.pkg.version.synapse>[4.0.0, 4.0.1)</imp.pkg.version.synapse>
<carbon.mediation.version>4.7.215</carbon.mediation.version>
<carbon.crypto.version>1.1.3</carbon.crypto.version>
Expand Down

0 comments on commit 8c52729

Please sign in to comment.