diff --git a/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/appserver/integration/common/clients/EventSimulatorAdminServiceClient.java b/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/appserver/integration/common/clients/EventSimulatorAdminServiceClient.java index 15bd2e85..62570df0 100644 --- a/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/appserver/integration/common/clients/EventSimulatorAdminServiceClient.java +++ b/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/appserver/integration/common/clients/EventSimulatorAdminServiceClient.java @@ -39,6 +39,7 @@ public EventSimulatorAdminServiceClient(String backEndUrl, String sessionCookie) executionSimulatorAdminServiceStub = new EventSimulatorAdminServiceStub(endPoint); AuthenticateStubUtil.authenticateStub(sessionCookie, executionSimulatorAdminServiceStub); } + public EventSimulatorAdminServiceClient(String backEndUrl, String userName, String password) throws AxisFault { this.endPoint = backEndUrl + serviceName; @@ -118,4 +119,51 @@ public boolean deleteDBConfigFile(String fileName) throw new RemoteException(); } } + + public boolean sendConfigDetails(String fileName, String streamId, String separateChar, long delayBetweenEventsInMilies) throws RemoteException { + try { + executionSimulatorAdminServiceStub.sendConfigDetails(fileName, streamId, separateChar, delayBetweenEventsInMilies); + return true; + } catch (RemoteException e) { + log.error("RemoteException", e); + throw new RemoteException(); + } + } + + public void sendEventsViaFile(String fileName) throws RemoteException{ + try { + executionSimulatorAdminServiceStub.sendEventsViaFile(fileName); + } catch (RemoteException e) { + log.error("RemoteException", e); + throw new RemoteException(); + } + } + + public void pauseEventsViaFile(String fileName) throws RemoteException{ + try { + executionSimulatorAdminServiceStub.pauseEventsViaFile(fileName); + } catch (RemoteException e) { + log.error("RemoteException", e); + throw new RemoteException(); + } + } + + public void resumeEventsViaFile(String fileName) throws RemoteException{ + try { + executionSimulatorAdminServiceStub.resumeEventsViaFile(fileName); + } catch (RemoteException e) { + log.error("RemoteException", e); + throw new RemoteException(); + } + } + + + public boolean deleteFile(String fileName) throws RemoteException{ + try { + return executionSimulatorAdminServiceStub.deleteFile(fileName); + } catch (RemoteException e) { + log.error("RemoteException", e); + throw new RemoteException(); + } + } } \ No newline at end of file diff --git a/modules/integration/tests-integration/tests/src/test/java/org/wso2/carbon/integration/test/inputflow/EventSimulatorTestCase.java b/modules/integration/tests-integration/tests/src/test/java/org/wso2/carbon/integration/test/inputflow/EventSimulatorTestCase.java new file mode 100644 index 00000000..4dbbc509 --- /dev/null +++ b/modules/integration/tests-integration/tests/src/test/java/org/wso2/carbon/integration/test/inputflow/EventSimulatorTestCase.java @@ -0,0 +1,120 @@ +/* + * 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.inputflow; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil; +import org.wso2.carbon.automation.test.utils.common.FileManager; +import org.wso2.carbon.integration.test.client.Wso2EventServer; +import org.wso2.cep.integration.common.utils.CEPIntegrationTest; +import org.wso2.cep.integration.common.utils.CEPIntegrationTestConstants; + +import java.io.File; +import java.rmi.RemoteException; + +/** + * Testing Logger publisher in different formats (text, xml, json) + */ +public class EventSimulatorTestCase extends CEPIntegrationTest { + + private static final Log log = LogFactory.getLog(EventSimulatorTestCase.class); + + @BeforeClass(alwaysRun = true) + public void init() + throws Exception { + + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String loggedInSessionCookie = getSessionCookie(); + + eventSimulatorAdminServiceClient = configurationUtil.getEventSimulatorAdminServiceClient( + backendURL, loggedInSessionCookie); + eventStreamManagerAdminServiceClient = configurationUtil.getEventStreamManagerAdminServiceClient( + backendURL, loggedInSessionCookie); + eventPublisherAdminServiceClient = configurationUtil.getEventPublisherAdminServiceClient( + backendURL, loggedInSessionCookie); + + } + + + @Test(groups = {"wso2.cep"}, description = "Testing Event Simulation (Play, Pause and Resume)") + public void EventSimulatorTestScenario() throws Exception { + int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); + int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); + Wso2EventServer wso2EventServer = new Wso2EventServer("eventsimulatorFiles", CEPIntegrationTestConstants.TCP_PORT, true); + + + //Add StreamDefinition + String streamDefinitionAsString = getJSONArtifactConfiguration("eventsimulatorFiles", + "TempStream_1.0.0.json"); + eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); + Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); + + //Add Text Logger + String eventPublisherConfig = getXMLArtifactConfiguration("eventsimulatorFiles", "tempEventPublisher.xml"); + eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); + Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); + + //Copy Event Simulator File + String eventSimulatorFilePath = FrameworkPathUtil.getSystemResourceLocation() + + "artifacts" + File.separator + "CEP" + File.separator + "eventsimulatorFiles" + + File.separator; + + String eventSimulatorDirectoryPath = FrameworkPathUtil.getCarbonHome() + File.separator + + "repository" + File.separator + "deployment" + File.separator + "server" + + File.separator + "eventsimulatorfiles" + File.separator; + try { + FileManager.copyResourceToFileSystem(eventSimulatorFilePath + "events.csv", eventSimulatorDirectoryPath, "events.csv"); + } catch (Exception e) { + throw new RemoteException("Exception caught when deploying the car file into CEP server", e); + } + log.info("deploying Event Simulator File..."); + Thread.sleep(35000); + + wso2EventServer.startServer(); + + eventSimulatorAdminServiceClient.sendConfigDetails("events.csv", "TempStream:1.0.0", ",", 1000); + Thread.sleep(10000); + eventSimulatorAdminServiceClient.sendEventsViaFile("events.csv"); + Thread.sleep(3000); + eventSimulatorAdminServiceClient.pauseEventsViaFile("events.csv"); + Thread.sleep(3000); + eventSimulatorAdminServiceClient.resumeEventsViaFile("events.csv"); + Thread.sleep(10000); + + Assert.assertEquals(wso2EventServer.getMsgCount(), 13, "Incorrect number of messages consumed!"); + Thread.sleep(2000); + + eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); + eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("logger.xml"); + eventSimulatorAdminServiceClient.deleteFile("events.csv"); + wso2EventServer.stop(); + + Thread.sleep(2000); + + } + + @AfterClass(alwaysRun = true) + public void destroy() throws Exception { + super.cleanup(); + } +} diff --git a/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/TempStream_1.0.0.json b/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/TempStream_1.0.0.json new file mode 100644 index 00000000..d313576e --- /dev/null +++ b/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/TempStream_1.0.0.json @@ -0,0 +1,20 @@ +{ + "name": "TempStream", + "version": "1.0.0", + "nickName": "Temperature Stream", + "description": "Temperature Event Stream", + "payloadData": [ + { + "name": "deviceID", + "type": "LONG" + }, + { + "name": "roomNo", + "type": "INT" + }, + { + "name": "temp", + "type": "DOUBLE" + } + ] +} \ No newline at end of file diff --git a/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/events.csv b/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/events.csv new file mode 100644 index 00000000..9a3c48a3 --- /dev/null +++ b/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/events.csv @@ -0,0 +1,13 @@ +1259283,275,25.67 +2458199,972,26.3 +9872343,175,29.3 +9812232,276,19.3 +2083739,294,40.2 +28213,321,24.2 +9877214,723,28.3 +3794266,469,27.7 +9309662,477,24.9 +4988222,665,25.0 +5758083,237,30.0 +157676,501,24.1 +4815418,418,23.0 diff --git a/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/tempEventPublisher.xml b/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/tempEventPublisher.xml new file mode 100644 index 00000000..850a752f --- /dev/null +++ b/modules/integration/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/tempEventPublisher.xml @@ -0,0 +1,14 @@ + + + + + + admin + thrift + blocking + 0 + tcp://localhost:8461 + kuv2MubUUveMyv6GeHrXr9il59ajJIqUI4eoYHcgGKf/BBFOWn96NTjJQI+wYbWjKW6r79S7L7ZzgYeWx7DlGbff5X3pBN2Gh9yV0BHP1E93QtFqR7uTWi141Tr7V7ZwScwNqJbiNoV+vyLbsqKJE7T3nP8Ih9Y6omygbcLcHzg= + + diff --git a/modules/integration/tests-integration/tests/src/test/resources/testng.xml b/modules/integration/tests-integration/tests/src/test/resources/testng.xml index 422ceff0..3efcc1a2 100644 --- a/modules/integration/tests-integration/tests/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests/src/test/resources/testng.xml @@ -88,6 +88,9 @@ + + +