Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Committing the automation test for Event Simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanvive committed Feb 1, 2016
1 parent d7c7da3 commit db33259
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<eventPublisher name="tempEventPublisher" statistics="disable"
trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
<from streamName="TempStream" version="1.0.0"/>
<mapping customMapping="disable" type="wso2event"/>
<to eventAdapterType="wso2event">
<property name="username">admin</property>
<property name="protocol">thrift</property>
<property name="publishingMode">blocking</property>
<property name="publishTimeout">0</property>
<property name="receiverURL">tcp://localhost:8461</property>
<property encrypted="true" name="password">kuv2MubUUveMyv6GeHrXr9il59ajJIqUI4eoYHcgGKf/BBFOWn96NTjJQI+wYbWjKW6r79S7L7ZzgYeWx7DlGbff5X3pBN2Gh9yV0BHP1E93QtFqR7uTWi141Tr7V7ZwScwNqJbiNoV+vyLbsqKJE7T3nP8Ih9Y6omygbcLcHzg=</property>
</to>
</eventPublisher>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
<!-- Adding HA test case-->
<class name="org.wso2.carbon.integration.test.ha.HATestCase"/>

<!-- Adding Event Simulator File Test -->
<class name="org.wso2.carbon.integration.test.inputflow.EventSimulatorTestCase"/>

</classes>

</test>
Expand Down

0 comments on commit db33259

Please sign in to comment.