From 044b233a3fafd0fcd28406dbaccfdbd22412bcbf Mon Sep 17 00:00:00 2001 From: Nuwan Wimalasekara Date: Tue, 9 Aug 2016 13:09:51 +0530 Subject: [PATCH] adding test case for ESBJAVA-4821 --- ...821WSDLProxyServiceDeploymentTestCase.java | 104 ++++++ .../proxy/wsdlBasedProxy/delay-wsdl.xml | 337 ++++++++++++++++++ .../proxy/wsdlBasedProxy/wsdl-fault-proxy.xml | 16 + 3 files changed, 457 insertions(+) create mode 100644 modules/integration/tests-integration/tests-service/src/test/java/org/wso2/carbon/esb/proxyservice/test/wsdlBasedProxy/ESBJAVA4821WSDLProxyServiceDeploymentTestCase.java create mode 100644 modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/delay-wsdl.xml create mode 100644 modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/wsdl-fault-proxy.xml diff --git a/modules/integration/tests-integration/tests-service/src/test/java/org/wso2/carbon/esb/proxyservice/test/wsdlBasedProxy/ESBJAVA4821WSDLProxyServiceDeploymentTestCase.java b/modules/integration/tests-integration/tests-service/src/test/java/org/wso2/carbon/esb/proxyservice/test/wsdlBasedProxy/ESBJAVA4821WSDLProxyServiceDeploymentTestCase.java new file mode 100644 index 000000000..5100e252a --- /dev/null +++ b/modules/integration/tests-integration/tests-service/src/test/java/org/wso2/carbon/esb/proxyservice/test/wsdlBasedProxy/ESBJAVA4821WSDLProxyServiceDeploymentTestCase.java @@ -0,0 +1,104 @@ +/* +* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. 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.proxyservice.test.wsdlBasedProxy; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.base.CarbonBaseUtils; +import org.wso2.carbon.integration.common.admin.client.LogViewerClient; +import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent; +import org.wso2.esb.integration.common.utils.ESBIntegrationTest; +import org.wso2.esb.integration.common.utils.common.FileManager; + +import java.io.File; +import java.util.Calendar; + +/** + * https://wso2.org/jira/browse/ESBJAVA-4821 + * When ESB proxy service deployment, if proxy service is having an WSDL URI., ESB try to get the + * WSDL from a server and if the server failed to respond with the wsdl content, ESB wait till that + * server close the connection. This test class make sure the connection will be closed with read timeout + */ + +public class ESBJAVA4821WSDLProxyServiceDeploymentTestCase extends ESBIntegrationTest { + + private final String targetProxyPath = CarbonBaseUtils.getCarbonHome() + File.separator + "repository" + File.separator + + "deployment" + File.separator + "server" + File.separator + "synapse-configs" + + File.separator + "default" + File.separator + "proxy-services" + + File.separator + "wsdl-fault-proxy.xml"; + + @BeforeClass(alwaysRun = true) + public void deployAPI() throws Exception { + super.init(); + loadESBConfigurationFromClasspath( + "/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/delay-wsdl.xml"); + + } + + @Test(groups = "wso2.esb", description = "Test the deployment of WSDL proxy which wsdl does not respond until timeout") + public void testWSDLBasedProxyDeployment() throws Exception { + + LogViewerClient logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie()); + logViewerClient.clearLogs(); + File source = new File(getESBResourceLocation() + File.separator + "proxyconfig" + File.separator + + "proxy" + File.separator + "wsdlBasedProxy" + File.separator + "wsdl-fault-proxy.xml"); + FileManager.copyFile(source, targetProxyPath); + + long startTime = Calendar.getInstance().getTimeInMillis(); + boolean logFound = false; + while (!logFound && (Calendar.getInstance().getTimeInMillis() - startTime) < 200000) { + + LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs(); + + if (logEvents != null) { + for (LogEvent log : logEvents) { + if (log == null) { + continue; + } + if (log.getMessage().contains("IOError when getting a stream from given url")) { + logFound = true; + } + } + } + Thread.sleep(3000); + + } + Assert.assertTrue(logFound, "Error message not found. Deployment not failed due to read timeout of wsdl"); + } + + + @AfterClass(alwaysRun = true) + public void destroy() throws Exception { + try { + File target = new File(targetProxyPath); + File targetBackup = new File(targetProxyPath + ".back"); + if (target.exists()) { + target.delete(); + } + + if (targetBackup.exists()) { + targetBackup.delete(); + } + + } finally { + super.cleanup(); + } + } +} diff --git a/modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/delay-wsdl.xml b/modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/delay-wsdl.xml new file mode 100644 index 000000000..f4da299f1 --- /dev/null +++ b/modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/delay-wsdl.xml @@ -0,0 +1,337 @@ + + + + + + + + + + + + + + + echo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/wsdl-fault-proxy.xml b/modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/wsdl-fault-proxy.xml new file mode 100644 index 000000000..db55966b1 --- /dev/null +++ b/modules/integration/tests-integration/tests-service/src/test/resources/artifacts/ESB/proxyconfig/proxy/wsdlBasedProxy/wsdl-fault-proxy.xml @@ -0,0 +1,16 @@ + + + + + + + + + + +