|
| 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 | +} |
0 commit comments