Skip to content

Commit 90e9ca5

Browse files
committed
Add test cases for ThrowError mediator
Add test cases for ThrowError mediator Related to wso2/issues/3843
1 parent 2fb7ef2 commit 90e9ca5

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
package org.wso2.carbon.esb.mediator.test.v2;
19+
20+
import org.apache.http.HttpResponse;
21+
import org.apache.http.util.EntityUtils;
22+
import org.testng.Assert;
23+
import org.testng.annotations.AfterClass;
24+
import org.testng.annotations.BeforeClass;
25+
import org.testng.annotations.Test;
26+
import org.wso2.esb.integration.common.utils.CarbonLogReader;
27+
import org.wso2.esb.integration.common.utils.ESBIntegrationTest;
28+
import org.wso2.esb.integration.common.utils.clients.SimpleHttpClient;
29+
30+
import java.io.IOException;
31+
32+
/**
33+
* Test case for the Throw mediator.
34+
*/
35+
public class ThrowMediatorTestCase extends ESBIntegrationTest {
36+
37+
SimpleHttpClient httpClient = new SimpleHttpClient();
38+
39+
@BeforeClass(alwaysRun = true)
40+
public void init() throws Exception {
41+
super.init();
42+
}
43+
44+
@Test(groups = {"wso2.esb"}, description = "Testing ThrowError mediator")
45+
public void testThrowErrorMediator() throws IOException, InterruptedException {
46+
47+
CarbonLogReader carbonLogReader = new CarbonLogReader();
48+
carbonLogReader.start();
49+
50+
String serviceURL = getMainSequenceURL() + "testThrowError";
51+
HttpResponse httpResponse = httpClient.doGet(serviceURL, null);
52+
Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), 202, "Response code mismatched");
53+
EntityUtils.consumeQuietly(httpResponse.getEntity());
54+
55+
boolean logLine = carbonLogReader
56+
.checkForLog("ERROR_CODE = ERROR_TYPE, ERROR_MESSAGE = Error message from expression", DEFAULT_TIMEOUT);
57+
Assert.assertTrue(logLine, "ThrowError mediator log not found in the log");
58+
59+
carbonLogReader.stop();
60+
}
61+
62+
@AfterClass(alwaysRun = true)
63+
private void destroy() throws Exception {
64+
super.cleanup();
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
4+
~
5+
~ WSO2 LLC. licenses this file to you under the Apache License,
6+
~ Version 2.0 (the "License"); you may not use this file except
7+
~ in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing,
13+
~ software distributed under the License is distributed on an
14+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
~ KIND, either express or implied. See the License for the
16+
~ specific language governing permissions and limitations
17+
~ under the License.
18+
~
19+
-->
20+
<api context="/testThrowError" name="TestThrowErrorMediatorAPI" xmlns="http://ws.apache.org/ns/synapse">
21+
<resource methods="GET">
22+
<inSequence>
23+
<variable name="ERROR_MSG" value="Error message from expression"/>
24+
<throwError type="ERROR_TYPE" errorMessage="{${var.ERROR_MSG}}"/>
25+
</inSequence>
26+
<faultSequence>
27+
<log level="full">
28+
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
29+
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
30+
</log>
31+
<drop/>
32+
</faultSequence>
33+
</resource>
34+
</api>

0 commit comments

Comments
 (0)