|
|
@ -49,7 +49,6 @@ import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
import org.wso2.extension.siddhi.device.test.util.SiddhiTestHelper;
|
|
|
|
import org.wso2.extension.siddhi.device.test.util.SiddhiTestHelper;
|
|
|
|
import org.wso2.extension.siddhi.device.test.util.TestDataHolder;
|
|
|
|
import org.wso2.extension.siddhi.device.test.util.TestDataHolder;
|
|
|
|
import org.wso2.extension.siddhi.device.test.util.TestDeviceManagementService;
|
|
|
|
import org.wso2.extension.siddhi.device.test.util.TestDeviceManagementService;
|
|
|
|
import org.wso2.extension.siddhi.device.test.util.TestUtils;
|
|
|
|
|
|
|
|
import org.wso2.extension.siddhi.device.utils.DeviceUtils;
|
|
|
|
import org.wso2.extension.siddhi.device.utils.DeviceUtils;
|
|
|
|
import org.wso2.siddhi.core.ExecutionPlanRuntime;
|
|
|
|
import org.wso2.siddhi.core.ExecutionPlanRuntime;
|
|
|
|
import org.wso2.siddhi.core.SiddhiManager;
|
|
|
|
import org.wso2.siddhi.core.SiddhiManager;
|
|
|
@ -79,7 +78,7 @@ public class ExtensionTestCase extends BaseDeviceManagementTest {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
|
|
|
|
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
|
|
|
|
EventPrinter.print(timeStamp, inEvents, removeEvents);
|
|
|
|
EventPrinter.print(timeStamp, inEvents, removeEvents);
|
|
|
|
for (Event event : inEvents) {
|
|
|
|
for (Event ignored : inEvents) {
|
|
|
|
count.incrementAndGet();
|
|
|
|
count.incrementAndGet();
|
|
|
|
eventArrived = true;
|
|
|
|
eventArrived = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -127,8 +126,10 @@ public class ExtensionTestCase extends BaseDeviceManagementTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void createGroup() throws GroupManagementException, GroupAlreadyExistException {
|
|
|
|
public void createGroup() throws GroupManagementException, GroupAlreadyExistException {
|
|
|
|
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup1(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
|
|
|
groupManagementProviderService.createGroup(TestDataHolder.generateDummyGroupData(1),
|
|
|
|
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup2(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
|
|
|
DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
|
|
|
|
|
|
|
groupManagementProviderService.createGroup(TestDataHolder.generateDummyGroupData(2),
|
|
|
|
|
|
|
|
DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -149,13 +150,38 @@ public class ExtensionTestCase extends BaseDeviceManagementTest {
|
|
|
|
configuration.setEnabled(false);
|
|
|
|
configuration.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
|
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().setDeviceCacheConfiguration(configuration);
|
|
|
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().setDeviceCacheConfiguration(configuration);
|
|
|
|
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList(DEVICE_TYPE);
|
|
|
|
List<DeviceIdentifier> list = TestDataHolder.getDeviceIdentifiersList(DEVICE_TYPE);
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName());
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestDataHolder.generateDummyGroupData(1).getName());
|
|
|
|
Assert.assertNotNull(deviceGroup);
|
|
|
|
Assert.assertNotNull(deviceGroup);
|
|
|
|
groupManagementProviderService.addDevices(deviceGroup.getGroupId(), list);
|
|
|
|
groupManagementProviderService.addDevices(deviceGroup.getGroupId(), list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"addDevices"})
|
|
|
|
@Test(dependsOnMethods = {"addDevices"})
|
|
|
|
|
|
|
|
public void testIsEnrolledExtension() throws InterruptedException, GroupManagementException {
|
|
|
|
|
|
|
|
log.info("IsEnrolled TestCase");
|
|
|
|
|
|
|
|
SiddhiManager siddhiManager = new SiddhiManager();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
count.set(0);
|
|
|
|
|
|
|
|
eventArrived = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String inStreamDefinition = "define stream inputStream (deviceId string, deviceType string);";
|
|
|
|
|
|
|
|
String query = ("@info(name = 'query1') from inputStream[device:isEnrolled(deviceId, deviceType)] " +
|
|
|
|
|
|
|
|
"select deviceId insert into outputStream;");
|
|
|
|
|
|
|
|
ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(inStreamDefinition + query);
|
|
|
|
|
|
|
|
executionPlanRuntime.addCallback("query1", queryCallback);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream");
|
|
|
|
|
|
|
|
executionPlanRuntime.start();
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = TestDataHolder.getDeviceIdentifiersList(DEVICE_TYPE).get(0);
|
|
|
|
|
|
|
|
inputHandler.send(new Object[]{deviceIdentifier.getId(), deviceIdentifier.getType()});
|
|
|
|
|
|
|
|
inputHandler.send(new Object[]{"99999", deviceIdentifier.getType()});
|
|
|
|
|
|
|
|
SiddhiTestHelper.waitForEvents(100, 1, count, 10000);
|
|
|
|
|
|
|
|
Assert.assertTrue(eventArrived);
|
|
|
|
|
|
|
|
Assert.assertEquals(1, count.get());
|
|
|
|
|
|
|
|
executionPlanRuntime.shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testIsEnrolledExtension"})
|
|
|
|
public void testIsInGroupExtension() throws InterruptedException, GroupManagementException {
|
|
|
|
public void testIsInGroupExtension() throws InterruptedException, GroupManagementException {
|
|
|
|
log.info("IsInGroup TestCase");
|
|
|
|
log.info("IsInGroup TestCase");
|
|
|
|
SiddhiManager siddhiManager = new SiddhiManager();
|
|
|
|
SiddhiManager siddhiManager = new SiddhiManager();
|
|
|
@ -171,11 +197,11 @@ public class ExtensionTestCase extends BaseDeviceManagementTest {
|
|
|
|
|
|
|
|
|
|
|
|
InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream");
|
|
|
|
InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream");
|
|
|
|
executionPlanRuntime.start();
|
|
|
|
executionPlanRuntime.start();
|
|
|
|
DeviceIdentifier deviceIdentifier = TestUtils.getDeviceIdentifiersList(DEVICE_TYPE).get(0);
|
|
|
|
DeviceIdentifier deviceIdentifier = TestDataHolder.getDeviceIdentifiersList(DEVICE_TYPE).get(0);
|
|
|
|
inputHandler.send(new Object[]{groupManagementProviderService.getGroup(
|
|
|
|
inputHandler.send(new Object[]{groupManagementProviderService.getGroup(
|
|
|
|
TestUtils.createDeviceGroup1().getName()).getGroupId(), deviceIdentifier.getId(), deviceIdentifier.getType()});
|
|
|
|
TestDataHolder.generateDummyGroupData(1).getName()).getGroupId(), deviceIdentifier.getId(), deviceIdentifier.getType()});
|
|
|
|
inputHandler.send(new Object[]{groupManagementProviderService.getGroup(
|
|
|
|
inputHandler.send(new Object[]{groupManagementProviderService.getGroup(
|
|
|
|
TestUtils.createDeviceGroup2().getName()).getGroupId(), deviceIdentifier.getId(), deviceIdentifier.getType()});
|
|
|
|
TestDataHolder.generateDummyGroupData(2).getName()).getGroupId(), deviceIdentifier.getId(), deviceIdentifier.getType()});
|
|
|
|
SiddhiTestHelper.waitForEvents(100, 1, count, 10000);
|
|
|
|
SiddhiTestHelper.waitForEvents(100, 1, count, 10000);
|
|
|
|
Assert.assertTrue(eventArrived);
|
|
|
|
Assert.assertTrue(eventArrived);
|
|
|
|
Assert.assertEquals(1, count.get());
|
|
|
|
Assert.assertEquals(1, count.get());
|
|
|
|