Improve testing

revert-dabc3590
charitha 7 years ago
parent 0c89600af7
commit ae7d693e5c

@ -148,6 +148,32 @@
</suiteXmlFiles> </suiteXmlFiles>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

@ -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());

@ -30,13 +30,8 @@ import java.util.Properties;
public class TestDataHolder { public class TestDataHolder {
public final static String TEST_DEVICE_TYPE = "Test";
public final static Integer SUPER_TENANT_ID = -1234;
public final static String SUPER_TENANT_DOMAIN = "carbon.super";
public final static String initialDeviceIdentifier = "12345"; public final static String initialDeviceIdentifier = "12345";
public final static String OWNER = "admin"; public final static String OWNER = "admin";
public static Device initialTestDevice;
public static DeviceType initialTestDeviceType;
public static Device generateDummyDeviceData(String deviceType) { public static Device generateDummyDeviceData(String deviceType) {
Device device = new Device(); Device device = new Device();
@ -53,75 +48,23 @@ public class TestDataHolder {
return device; return device;
} }
public static Notification getNotification(int notificationId, String status, String deviceId, public static DeviceGroup generateDummyGroupData(int testId) {
String description, String deviceName, int operationId, DeviceGroup deviceGroup = new DeviceGroup();
String deviceType) { deviceGroup.setName("Test" + testId);
Notification notification = new Notification(); deviceGroup.setDescription("Test description " + testId);
notification.setNotificationId(notificationId); deviceGroup.setOwner(OWNER);
notification.setStatus(status); return deviceGroup;
notification.setDeviceIdentifier(deviceId);
notification.setDescription(description);
notification.setDeviceName(deviceName);
notification.setOperationId(operationId);
notification.setDeviceType(deviceType);
return notification;
}
public static Device generateDummyDeviceData(String deviceIdentifier, String deviceType,
EnrolmentInfo enrolmentInfo) {
Device device = new Device();
device.setEnrolmentInfo(enrolmentInfo);
device.setDescription("Test Description");
device.setDeviceIdentifier(deviceIdentifier);
device.setType(deviceType);
return device;
}
public static List<Device> generateDummyDeviceData(List<DeviceIdentifier> deviceIds) {
List<Device> devices = new ArrayList<>();
for (DeviceIdentifier deviceId : deviceIds) {
Device device = new Device();
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setOwner(OWNER);
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
device.setEnrolmentInfo(enrolmentInfo);
device.setDescription("Test Description");
device.setDeviceIdentifier(deviceId.getId());
device.setType(deviceId.getType());
devices.add(device);
}
return devices;
} }
public static DeviceType generateDeviceTypeData(String devTypeName) { public static List<DeviceIdentifier> getDeviceIdentifiersList(String deviceType){
DeviceType deviceType = new DeviceType(); Device device = generateDummyDeviceData(deviceType);
deviceType.setName(devTypeName); DeviceIdentifier identifier = new DeviceIdentifier();
return deviceType; identifier.setId(device.getDeviceIdentifier());
} identifier.setType(deviceType);
public static Application generateApplicationDummyData(String appIdentifier) { List<DeviceIdentifier> list = new ArrayList<>();
Application application = new Application(); list.add(identifier);
Properties properties = new Properties();
properties.setProperty("test1", "testVal");
application.setName("SimpleCalculator");
application.setCategory("TestCategory");
application.setApplicationIdentifier(appIdentifier);
application.setType("TestType");
application.setVersion("1.0.0");
application.setImageUrl("http://test.org/image/");
application.setLocationUrl("http://test.org/location/");
application.setAppProperties(properties);
return application;
}
public static DeviceGroup generateDummyGroupData() { return list;
DeviceGroup deviceGroup = new DeviceGroup();
deviceGroup.setName("Test device group");
deviceGroup.setDescription("Test description");
deviceGroup.setOwner(OWNER);
return deviceGroup;
} }
} }

@ -58,35 +58,4 @@ public class TestUtils {
} }
} }
} }
public static DeviceGroup createDeviceGroup1(){
DeviceGroup group = new DeviceGroup();
group.setName("TEST_GROUP_01");
group.setDescription("TEST_GROUP_01 - Description");
group.setOwner("admin");
return group;
}
public static DeviceGroup createDeviceGroup2(){
DeviceGroup group = new DeviceGroup();
group.setName("TEST_GROUP_02");
group.setDescription("TEST_GROUP_02 - Description");
group.setOwner("admin");
return group;
}
public static List<DeviceIdentifier> getDeviceIdentifiersList(String deviceType){
Device device = TestDataHolder.generateDummyDeviceData(deviceType);
DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setId(device.getDeviceIdentifier());
identifier.setType(deviceType);
List<DeviceIdentifier> list = new ArrayList<>();
list.add(identifier);
return list;
}
} }

@ -19,7 +19,7 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="CheckDeviceInGroup"> <suite name="DeviceExtensionTestSuite">
<parameter name="useDefaultListeners" value="false"/> <parameter name="useDefaultListeners" value="false"/>
<test name="Extension Unit Tests" preserve-order="true"> <test name="Extension Unit Tests" preserve-order="true">

@ -84,6 +84,18 @@
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>

@ -0,0 +1,30 @@
<!--
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="JsonExtensionTestSuite">
<parameter name="useDefaultListeners" value="false"/>
<test name="Extension Unit Tests" preserve-order="true">
<classes>
<class name="org.wso2.extension.siddhi.execution.json.ExtensionTestCase"/>
</classes>
</test>
</suite>

@ -103,9 +103,13 @@
${basedir}/../${extensions}/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener ${basedir}/../${extensions}/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener
</pull.notification.listener> </pull.notification.listener>
<siddhi.extensions> <siddhi.extensions>${extensions}/siddhi-extensions</siddhi.extensions>
${basedir}/../${extensions}/siddhi-extensions/org.wso2.extension.siddhi.execution.json <siddhi.json.extensions>
</siddhi.extensions> ${basedir}/../${siddhi.extensions}/org.wso2.extension.siddhi.execution.json
</siddhi.json.extensions>
<siddhi.device.extensions>
${basedir}/../${siddhi.extensions}/org.wso2.extension.siddhi.device
</siddhi.device.extensions>
<!-- mobile-plugins component --> <!-- mobile-plugins component -->
<mobile.plugins>mobile-plugins</mobile.plugins> <mobile.plugins>mobile-plugins</mobile.plugins>
@ -134,8 +138,9 @@
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath" /> <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath" />
<if> <if>
<and> <and>
<available file="${siddhi.extensions}/${target}/${coverge-report}/${individual.test.report.name}" /> <available file="${siddhi.json.extensions}/${target}/${coverge-report}/${individual.test.report.name}" />
<available file="${siddhi.device.extensions}/${target}/${coverge-report}/${individual.test.report.name}" />
<available file="${android.api}/${target}/${coverge-report}/${individual.test.report.name}" />
</and> </and>
<then> <then>
<taskdef name="report" classname="org.jacoco.ant.ReportTask"> <taskdef name="report" classname="org.jacoco.ant.ReportTask">
@ -144,8 +149,11 @@
<mkdir dir="${basedir}/target/coverage-report" /> <mkdir dir="${basedir}/target/coverage-report" />
<report> <report>
<executiondata> <executiondata>
<fileset dir="${siddhi.extensions}/${target}/${coverge-report}"> <fileset dir="${siddhi.device.extensions}/${target}/${coverge-report}">
<include name="${individual.test.report.name}" /> <include name="${individual.test.report.name}"/>
</fileset>
<fileset dir="${siddhi.json.extensions}/${target}/${coverge-report}">
<include name="${individual.test.report.name}"/>
</fileset> </fileset>
<fileset dir="${android.api}/${target}/${coverge-report}"> <fileset dir="${android.api}/${target}/${coverge-report}">
<include name="${individual.test.report.name}" /> <include name="${individual.test.report.name}" />
@ -308,13 +316,23 @@
</sourcefiles> </sourcefiles>
</group> </group>
<group name="siddhi-extensions"> <group name="siddhi-extensions">
<group name="org.wso2.extension.siddhi.execution.json">
<classfiles> <classfiles>
<fileset dir="${siddhi.extensions}/${target}/${classes}" /> <fileset dir="${siddhi.json.extensions}/${target}/${classes}" />
</classfiles> </classfiles>
<sourcefiles encoding="UTF-8"> <sourcefiles encoding="UTF-8">
<fileset dir="${siddhi.extensions}/${source}" /> <fileset dir="${siddhi.json.extensions}/${source}" />
</sourcefiles> </sourcefiles>
</group> </group>
<group name="org.wso2.extension.siddhi.device">
<classfiles>
<fileset dir="${siddhi.device.extensions}/${target}/${classes}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${siddhi.device.extensions}/${source}" />
</sourcefiles>
</group>
</group>
</group> </group>
<group name="mobile-plugins"> <group name="mobile-plugins">
<group name="android-plugin"> <group name="android-plugin">

Loading…
Cancel
Save