<commit_before>/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * Licensed 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.integration.test.outputflow;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.event.simulator.stub.types.EventDto;
import org.wso2.carbon.integration.test.client.WireMonitorServer;
import org.wso2.cep.integration.common.utils.CEPIntegrationTest;

public class SOAPTestCase extends CEPIntegrationTest{

    private static final Log log = LogFactory.getLog(SOAPTestCase.class);

    @BeforeClass(alwaysRun = true)
    public void init() throws Exception {
        super.init(TestUserMode.SUPER_TENANT_ADMIN);

        String loggedInSessionCookie = getSessionCookie();

        eventStreamManagerAdminServiceClient = configurationUtil.getEventStreamManagerAdminServiceClient(
                backendURL, loggedInSessionCookie);
        eventPublisherAdminServiceClient = configurationUtil.getEventPublisherAdminServiceClient(
                backendURL, loggedInSessionCookie);
        eventSimulatorAdminServiceClient = configurationUtil.getEventSimulatorAdminServiceClient(
                backendURL, loggedInSessionCookie);
        Thread.sleep(45000);

    }

    @Test(groups = {"wso2.cep"}, description = "Testing SOAP publisher with XML formatted event with default mapping")
    public void soapXMLTestWithDefaultMappingScenario() throws Exception {

        int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
        int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

        EventDto eventDto = new EventDto();
        eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
        eventDto.setAttributeValues(new String[]{"199008131245", "false", "100", "temperature", "23.45656", "7.12324",
                "100.34", "23.4545"});

        //Add StreamDefinition
        String streamDefinitionAsString = getJSONArtifactConfiguration("outputflows/sample0063",
                "org.wso2.event.sensor.stream_1.0.0.json");
        eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
        Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

        //Add ActiveMQ JMS EventPublisher
        String eventPublisherConfig = getXMLArtifactConfiguration("outputflows/sample0063", "soap.xml");
        eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
        Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

        Thread.sleep(10000);
        WireMonitorServer wireMonitorServer = new WireMonitorServer(9445);
        Thread wireMonitorServerThread = new Thread(wireMonitorServer);
        wireMonitorServerThread.start();
//        WireMonitorServer2 wireMonitorServer2 = new WireMonitorServer2(9445);
//        wireMonitorServer2.start();
        Thread.sleep(3000);

        eventSimulatorAdminServiceClient.sendEvent(eventDto);
        //wait while all stats are published
        Thread.sleep(30000);

        wireMonitorServer.shutdown();
        String receivedEvent = wireMonitorServer.getCapturedMessage().replaceAll("\\s+","");

        log.info(receivedEvent);

        String sentEvent = "<events><event><metaData><timestamp>199008131245</timestamp>" +
                "<isPowerSaverEnabled>false</isPowerSaverEnabled><sensorId>100</sensorId>" +
                "<sensorName>temperature</sensorName></metaData><correlationData><longitude>23.45656</longitude>" +
                "<latitude>7.12324</latitude></correlationData><payloadData><humidity>100.34</humidity>" +
                "<sensorValue>23.4545</sensorValue></payloadData></event></events>";

        eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
        eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("soap.xml");

        try {
            Assert.assertTrue(receivedEvent.contains(sentEvent), "Incorrect mapping has occurred!");
        } catch (Throwable e) {
            log.error("Exception thrown: " + e.getMessage(), e);
            Assert.fail("Exception: " + e.getMessage());
        }

    }

    @Test(groups = {"wso2.cep"}, description = "Testing SOAP publisher with XML formatted event with custom mapping",
            dependsOnMethods = {"soapXMLTestWithDefaultMappingScenario"})
    public void soapXMLTestWithCustomMappingScenario() throws Exception {

        int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
        int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

        EventDto eventDto = new EventDto();
        eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
        eventDto.setAttributeValues(new String[]{"199008131245", "false", "100", "temperature", "23.45656", "7.12324",
                "100.34", "23.4545"});

        //Add StreamDefinition
        String streamDefinitionAsString = getJSONArtifactConfiguration("outputflows/sample0063",
                "org.wso2.event.sensor.stream_1.0.0.json");
        eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
        Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

        //Add ActiveMQ JMS EventPublisher
        String eventPublisherConfig = getXMLArtifactConfiguration("outputflows/sample0063", "soapCustomXML.xml");
        eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
        Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

        Thread.sleep(10000);
        WireMonitorServer wireMonitorServer = new WireMonitorServer(9445);
        Thread wireMonitorServerThread = new Thread(wireMonitorServer);
        wireMonitorServerThread.start();

        Thread.sleep(3000);

        eventSimulatorAdminServiceClient.sendEvent(eventDto);
        //wait while all stats are published
        Thread.sleep(30000);
        wireMonitorServer.shutdown();
        String receivedEvent = wireMonitorServer.getCapturedMessage().replaceAll("\\s+","");
        log.info(receivedEvent);

        String sentEvent = "<SensorData>" +
                "<equipmentRelatedData>" +
                "<timestamp>199008131245</timestamp>" +
                "<isPowerSaverEnabled>false</isPowerSaverEnabled>" +
                "<sensorId>100</sensorId>" +
                "<sensorName>temperature</sensorName>" +
                "</equipmentRelatedData>" +
                "<locationData>" +
                "<longitude>23.45656</longitude>" +
                "<latitude>7.12324</latitude>" +
                "</locationData>" +
                "<sensorData>" +
                "<humidity>100.34</humidity>" +
                "<sensorValue>23.4545</sensorValue>" +
                "</sensorData>" +
                "</SensorData>";

        eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
        eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("soapCustomXML.xml");

        try {
            Assert.assertTrue(receivedEvent.contains(sentEvent), "Incorrect mapping has occurred!");
        } catch (Throwable e) {
            log.error("Exception thrown: " + e.getMessage(), e);
            Assert.fail("Exception: " + e.getMessage());
        }

    }
}


<commit_msg>Changes in SOAP testcase<commit_after>/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * Licensed 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.integration.test.outputflow;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.event.simulator.stub.types.EventDto;
import org.wso2.carbon.integration.test.client.WireMonitorServer;
import org.wso2.cep.integration.common.utils.CEPIntegrationTest;

public class SOAPTestCase extends CEPIntegrationTest{

    private static final Log log = LogFactory.getLog(SOAPTestCase.class);

    @BeforeClass(alwaysRun = true)
    public void init() throws Exception {
        super.init(TestUserMode.SUPER_TENANT_ADMIN);

        String loggedInSessionCookie = getSessionCookie();

        eventStreamManagerAdminServiceClient = configurationUtil.getEventStreamManagerAdminServiceClient(
                backendURL, loggedInSessionCookie);
        eventPublisherAdminServiceClient = configurationUtil.getEventPublisherAdminServiceClient(
                backendURL, loggedInSessionCookie);
        eventSimulatorAdminServiceClient = configurationUtil.getEventSimulatorAdminServiceClient(
                backendURL, loggedInSessionCookie);
        Thread.sleep(45000);

    }

    @Test(groups = {"wso2.cep"}, description = "Testing SOAP publisher with XML formatted event with default mapping")
    public void soapXMLTestWithDefaultMappingScenario() throws Exception {

        int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
        int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

        EventDto eventDto = new EventDto();
        eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
        eventDto.setAttributeValues(new String[]{"199008131245", "false", "100", "temperature", "23.45656", "7.12324",
                "100.34", "23.4545"});

        //Add StreamDefinition
        String streamDefinitionAsString = getJSONArtifactConfiguration("outputflows/sample0063",
                "org.wso2.event.sensor.stream_1.0.0.json");
        eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
        Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

        //Add ActiveMQ JMS EventPublisher
        String eventPublisherConfig = getXMLArtifactConfiguration("outputflows/sample0063", "soap.xml");
        eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
        Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

        Thread.sleep(10000);
        WireMonitorServer wireMonitorServer = new WireMonitorServer(9445);
        Thread wireMonitorServerThread = new Thread(wireMonitorServer);
        wireMonitorServerThread.start();
        Thread.sleep(3000);

        eventSimulatorAdminServiceClient.sendEvent(eventDto);
        //wait while all stats are published
        Thread.sleep(30000);

        wireMonitorServer.shutdown();
        String receivedEvent = wireMonitorServer.getCapturedMessage().replaceAll("\\s+","");

        log.info(receivedEvent);

        String sentEvent = "<events><event><metaData><timestamp>199008131245</timestamp>" +
                "<isPowerSaverEnabled>false</isPowerSaverEnabled><sensorId>100</sensorId>" +
                "<sensorName>temperature</sensorName></metaData><correlationData><longitude>23.45656</longitude>" +
                "<latitude>7.12324</latitude></correlationData><payloadData><humidity>100.34</humidity>" +
                "<sensorValue>23.4545</sensorValue></payloadData></event></events>";

        eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
        eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("soap.xml");

        try {
            Assert.assertTrue(receivedEvent.contains(sentEvent), "Incorrect mapping has occurred!");
        } catch (Throwable e) {
            log.error("Exception thrown: " + e.getMessage(), e);
            Assert.fail("Exception: " + e.getMessage());
        }

    }

    @Test(groups = {"wso2.cep"}, description = "Testing SOAP publisher with XML formatted event with custom mapping",
            dependsOnMethods = {"soapXMLTestWithDefaultMappingScenario"})
    public void soapXMLTestWithCustomMappingScenario() throws Exception {

        int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
        int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

        EventDto eventDto = new EventDto();
        eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
        eventDto.setAttributeValues(new String[]{"199008131245", "false", "100", "temperature", "23.45656", "7.12324",
                "100.34", "23.4545"});

        //Add StreamDefinition
        String streamDefinitionAsString = getJSONArtifactConfiguration("outputflows/sample0063",
                "org.wso2.event.sensor.stream_1.0.0.json");
        eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
        Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

        //Add ActiveMQ JMS EventPublisher
        String eventPublisherConfig = getXMLArtifactConfiguration("outputflows/sample0063", "soapCustomXML.xml");
        eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
        Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

        Thread.sleep(10000);
        WireMonitorServer wireMonitorServer = new WireMonitorServer(9445);
        Thread wireMonitorServerThread = new Thread(wireMonitorServer);
        wireMonitorServerThread.start();

        Thread.sleep(3000);

        eventSimulatorAdminServiceClient.sendEvent(eventDto);
        //wait while all stats are published
        Thread.sleep(30000);
        wireMonitorServer.shutdown();
        String receivedEvent = wireMonitorServer.getCapturedMessage().replaceAll("\\s+","");
        log.info(receivedEvent);

        String sentEvent = "<SensorData>" +
                "<equipmentRelatedData>" +
                "<timestamp>199008131245</timestamp>" +
                "<isPowerSaverEnabled>false</isPowerSaverEnabled>" +
                "<sensorId>100</sensorId>" +
                "<sensorName>temperature</sensorName>" +
                "</equipmentRelatedData>" +
                "<locationData>" +
                "<longitude>23.45656</longitude>" +
                "<latitude>7.12324</latitude>" +
                "</locationData>" +
                "<sensorData>" +
                "<humidity>100.34</humidity>" +
                "<sensorValue>23.4545</sensorValue>" +
                "</sensorData>" +
                "</SensorData>";

        eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
        eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("soapCustomXML.xml");

        try {
            Assert.assertTrue(receivedEvent.contains(sentEvent), "Incorrect mapping has occurred!");
        } catch (Throwable e) {
            log.error("Exception thrown: " + e.getMessage(), e);
            Assert.fail("Exception: " + e.getMessage());
        }

    }
}



{'fraction_non_alphanumeric': 0.10620865448807429, 'fraction_numerical': 0.031801905686714815, 'mean_word_length': 3.496043656207367, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3116345', 'n_tokens_mistral': 4673, 'n_tokens_neox': 4225, 'n_words': 756}