This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Committing the automation test for Event Simulator
- Loading branch information
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...ests/src/test/java/org/wso2/carbon/integration/test/inputflow/EventSimulatorTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...egration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/TempStream_1.0.0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
...n/tests-integration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/events.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
...gration/tests/src/test/resources/artifacts/CEP/eventsimulatorFiles/tempEventPublisher.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters