From 4d5cd82f5d6c8a60881eb7f37103fa82ba3f9a16 Mon Sep 17 00:00:00 2001 From: Pasindu Date: Thu, 28 Sep 2017 17:53:20 +0530 Subject: [PATCH 1/7] Adding unit tests to GeoServiceProviderService --- .../org.wso2.carbon.device.mgt.core/pom.xml | 18 +- .../GeoLocationProviderServiceImpl.java | 2 +- .../GeoLocationProviderServiceTest.java | 264 ++++++++++++++++++ .../src/test/resources/testng.xml | 3 +- pom.xml | 7 + 5 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 40f3ab5f85..fca68e4c5f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -345,7 +345,23 @@ javassist javassist - + + + org.powermock + powermock-api-mockito + + + org.powermock + powermock-module-junit4 + test + + + + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index 36b56e357a..9110299009 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -390,7 +390,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic } } - private EventProcessorAdminServiceStub getEventProcessorAdminServiceStub() throws JWTClientException { + protected EventProcessorAdminServiceStub getEventProcessorAdminServiceStub() throws JWTClientException { //send alert to event-processing String eventProcessorAdminServiceWSUrl = Utils.replaceSystemProperty(GeoServices.DAS_URL) + "/services/EventProcessorAdminService"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java new file mode 100644 index 0000000000..233f6c06e1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java @@ -0,0 +1,264 @@ +package org.wso2.carbon.device.mgt.core.geo.service; + +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.powermock.core.classloader.annotations.PrepareForTest; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.geo.service.Alert; +import org.wso2.carbon.device.mgt.common.geo.service.GeoFence; +import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; +import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl; +import org.wso2.carbon.device.mgt.core.common.TestDataHolder; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; +import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl; +import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; +import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; +import org.wso2.carbon.registry.core.config.RegistryContext; +import org.wso2.carbon.registry.core.exceptions.RegistryException; +import org.wso2.carbon.registry.core.internal.RegistryDataHolder; +import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; +import org.wso2.carbon.registry.core.service.RegistryService; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.io.InputStream; +import java.rmi.RemoteException; +import java.util.List; + +import static org.powermock.api.mockito.PowerMockito.*; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(GeoLocationProviderServiceImpl.class) +public class GeoLocationProviderServiceTest { + + private static final Log log = LogFactory.getLog(GeoLocationProviderServiceTest.class); + private static final String DEVICE_TYPE = "GL_TEST_TYPE"; + private static final String DEVICE_ID = "GL-TEST-DEVICE-ID-1"; + private static final String SAMPLE_GEO_JSON = "12121"; + private static final String SAMPLE_AREA_NAME = "CUSTOM_NAME"; + private static final String SAMPLE_QUERY_NAME = "QUERY_NAME"; + private static final String SAMPLE_PROXIMITY_DISATANCE = "100"; + private static final String SAMPLE_PROXIMITY_TIME = "50"; + private static final String SAMPLE_SPEED_ALERT_VALUE = "120"; + private static final String SAMPLE_STATIONARY_TIME = "1500"; + private static final String SAMPLE_FLUCTUATION_RADIUS = "2000"; + + private EventProcessorAdminServiceStub mockEventProcessorAdminServiceStub; + private GeoLocationProviderServiceImpl geoLocationProviderServiceImpl; + + @BeforeClass + public void init() throws Exception { + initMocks(); + enrollTestDevice(); + } + + @Test + public void createGeoExitAlert() throws Exception { + Boolean result = geoLocationProviderServiceImpl. + createGeoAlert(getTestAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_EXIT); + Assert.assertEquals(result, Boolean.TRUE); + verifyPrivate(geoLocationProviderServiceImpl).invoke("getEventProcessorAdminServiceStub"); + } + + @Test + public void createGeoWithinAlert() throws Exception { + Boolean result = geoLocationProviderServiceImpl. + createGeoAlert(getTestAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_WITHIN); + Assert.assertEquals(result, Boolean.TRUE); + } + + @Test + public void createGeoProximityAlert() throws Exception { + Boolean result = geoLocationProviderServiceImpl. + createGeoAlert(getProximityAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_PROXIMITY); + Assert.assertEquals(result, Boolean.TRUE); + } + + @Test + public void createGeoSpeedAlert() throws Exception { + Boolean result = geoLocationProviderServiceImpl. + createGeoAlert(getSpeedAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_SPEED); + Assert.assertEquals(result, Boolean.TRUE); + } + + @Test + public void createGeoStationaryAlert() throws Exception { + Boolean result = geoLocationProviderServiceImpl. + createGeoAlert(getStationaryAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_STATIONARY); + Assert.assertEquals(result, Boolean.TRUE); + } + + @Test + public void createGeoTrafficAlert() throws Exception { + Boolean result = geoLocationProviderServiceImpl. + createGeoAlert(getTrafficAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_TRAFFIC); + Assert.assertEquals(result, Boolean.TRUE); + } + + //Test methods to retrieve saved Data. + @Test(dependsOnMethods = "createGeoExitAlert") + public void getGeoExitAlerts() throws Exception { + List geoFences; + geoFences = geoLocationProviderServiceImpl.getExitAlerts(getDeviceIdentifier()); + Assert.assertNotNull(geoFences); + GeoFence geoFenceNode = geoFences.get(0); + Assert.assertEquals(geoFenceNode.getGeoJson(), SAMPLE_GEO_JSON); + Assert.assertEquals(geoFenceNode.getAreaName(), SAMPLE_AREA_NAME); + Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); + } + + @Test(dependsOnMethods = "createGeoWithinAlert") + public void getGeoWithinAlerts() throws Exception { + List geoFences; + geoFences = geoLocationProviderServiceImpl.getWithinAlerts(getDeviceIdentifier()); + Assert.assertNotNull(geoFences); + GeoFence geoFenceNode = geoFences.get(0); + Assert.assertEquals(geoFenceNode.getAreaName(), SAMPLE_AREA_NAME); + Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); + } + +// @Test(dependsOnMethods = "createGeoProximityAlert") +// public void getGeoProximityAlerts() throws Exception { +// String result; +// result = geoLocationProviderServiceImpl.getProximityAlerts(getDeviceIdentifier()); +// Assert.assertNotNull(result); +// Assert.assertEquals(result,"{proximityDistance:100\"\", proximityTime:50\"\"}"); +// } + + @Test(dependsOnMethods = "createGeoSpeedAlert") + public void getGeoSpeedAlerts() throws Exception { + String result; + result = geoLocationProviderServiceImpl.getSpeedAlerts(getDeviceIdentifier()); + Assert.assertNotNull(result); + Assert.assertEquals(result, "{'speedLimit':"+SAMPLE_SPEED_ALERT_VALUE+"}"); + } + + @Test(dependsOnMethods = "createGeoTrafficAlert") + public void getGeoTrafficAlerts() throws Exception { + List geoFences; + geoFences = geoLocationProviderServiceImpl.getTrafficAlerts(getDeviceIdentifier()); + Assert.assertNotNull(geoFences); + GeoFence geoFenceNode = geoFences.get(0); + Assert.assertEquals(geoFenceNode.getGeoJson(), "{\n" + + " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\"\n" + + "}"); + } + + @Test(dependsOnMethods = "createGeoStationaryAlert") + public void getGeoStationaryAlerts() throws Exception { + List geoFences; + geoFences = geoLocationProviderServiceImpl.getStationaryAlerts(getDeviceIdentifier()); + Assert.assertNotNull(geoFences); + GeoFence geoFenceNode = geoFences.get(0); + Assert.assertEquals(geoFenceNode.getAreaName(), SAMPLE_AREA_NAME); + Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); + Assert.assertEquals(geoFenceNode.getStationaryTime(), SAMPLE_STATIONARY_TIME); + } + + private void initMocks() throws JWTClientException, RemoteException { + mockEventProcessorAdminServiceStub = Mockito.mock(EventProcessorAdminServiceStub.class); + geoLocationProviderServiceImpl = Mockito.mock(GeoLocationProviderServiceImpl.class, Mockito.CALLS_REAL_METHODS); + doReturn(mockEventProcessorAdminServiceStub).when(geoLocationProviderServiceImpl).getEventProcessorAdminServiceStub(); + doReturn("success").when(mockEventProcessorAdminServiceStub).validateExecutionPlan(Mockito.anyString()); + } + + private DeviceIdentifier getDeviceIdentifier() { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId("1234"); + deviceIdentifier.setType("TEST"); + return deviceIdentifier; + } + private RegistryService getRegistryService() throws RegistryException { + RealmService realmService = new InMemoryRealmService(); + RegistryDataHolder.getInstance().setRealmService(realmService); + DeviceManagementDataHolder.getInstance().setRealmService(realmService); + InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); + RegistryContext context = RegistryContext.getBaseInstance(is, realmService); + context.setSetup(true); + return context.getEmbeddedRegistryService(); + } + + private void enrollTestDevice() throws Exception { + Device device = TestDataHolder.generateDummyDeviceData(DEVICE_ID); + DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl(); + DeviceManagementServiceComponent.notifyStartupListeners(); + DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); + DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService()); + DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl()); + DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl()); + DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); + deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); + deviceMgtService.enrollDevice(device); + } + + private Alert getTestAlert() { + Alert alert = new Alert(); + alert.setDeviceId(DEVICE_ID); + alert.setCepAction("CEP_ACTION"); + alert.setParseData("{\n" + + " \"geoFenceGeoJSON\": \""+SAMPLE_GEO_JSON+"\"\n" + + "}"); + alert.setCustomName(SAMPLE_AREA_NAME); + alert.setExecutionPlan("EXECUTION_PLAN"); + alert.setQueryName(SAMPLE_QUERY_NAME); + return alert; + } + + private Alert getProximityAlert() { + Alert alert = new Alert(); + alert.setDeviceId(DEVICE_ID); + alert.setProximityTime(SAMPLE_PROXIMITY_TIME); + alert.setProximityDistance(SAMPLE_PROXIMITY_DISATANCE); + alert.setParseData("{\n" + + " \"geoFenceGeoJSON\": \""+SAMPLE_GEO_JSON+"\"\n" + + "}"); + return alert; + } + + private Alert getSpeedAlert() { + Alert alert = getTestAlert(); + alert.setParseData("{\n" + + " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\",\n" + + " \"speedAlertValue\": \"" + SAMPLE_SPEED_ALERT_VALUE + "\"\n" + + "}"); + return alert; + } + + private Alert getStationaryAlert() { + Alert alert = new Alert(); + alert.setDeviceId(DEVICE_ID); + alert.setQueryName(SAMPLE_QUERY_NAME); + alert.setCustomName(SAMPLE_AREA_NAME); + alert.setStationeryTime(SAMPLE_STATIONARY_TIME); + alert.setFluctuationRadius(SAMPLE_FLUCTUATION_RADIUS); + alert.setParseData("{\n" + + " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\"\n" + + "}"); + return alert; + } + + private Alert getTrafficAlert() { + Alert alert = new Alert(); + alert.setDeviceId(DEVICE_ID); + alert.setParseData("{\n" + + " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\"\n" + + "}"); + alert.setCustomName(SAMPLE_AREA_NAME); + alert.setExecutionPlan("EXECUTION_PLAN"); + alert.setQueryName(SAMPLE_QUERY_NAME); + return alert; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml index 3315b7109a..5d6ce5fe1c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml @@ -32,7 +32,7 @@ - + @@ -42,6 +42,7 @@ + diff --git a/pom.xml b/pom.xml index c30878f9e1..1757d6e0ee 100644 --- a/pom.xml +++ b/pom.xml @@ -1532,6 +1532,13 @@ ${power.mock.version} test + + org.powermock + powermock-module-junit4 + ${power.mock.version} + + test + From 931b4ee05b451977c02d16bf3f166fe8ab5f4951 Mon Sep 17 00:00:00 2001 From: Pasindu Date: Thu, 28 Sep 2017 18:11:09 +0530 Subject: [PATCH 2/7] Removed unwated lines --- .../org.wso2.carbon.device.mgt.core/pom.xml | 15 +-------------- .../service/GeoLocationProviderServiceTest.java | 10 ---------- .../src/test/resources/testng.xml | 2 +- pom.xml | 7 ------- 4 files changed, 2 insertions(+), 32 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index fca68e4c5f..60dd1b2acc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -344,24 +344,11 @@ javassist - javassist - + javassist org.powermock powermock-api-mockito - - org.powermock - powermock-module-junit4 - test - - - - - - - - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java index 233f6c06e1..fcd0800c63 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java @@ -31,7 +31,6 @@ import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import org.powermock.modules.junit4.PowerMockRunner; import java.io.InputStream; import java.rmi.RemoteException; @@ -39,7 +38,6 @@ import java.util.List; import static org.powermock.api.mockito.PowerMockito.*; -@RunWith(PowerMockRunner.class) @PrepareForTest(GeoLocationProviderServiceImpl.class) public class GeoLocationProviderServiceTest { @@ -129,14 +127,6 @@ public class GeoLocationProviderServiceTest { Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); } -// @Test(dependsOnMethods = "createGeoProximityAlert") -// public void getGeoProximityAlerts() throws Exception { -// String result; -// result = geoLocationProviderServiceImpl.getProximityAlerts(getDeviceIdentifier()); -// Assert.assertNotNull(result); -// Assert.assertEquals(result,"{proximityDistance:100\"\", proximityTime:50\"\"}"); -// } - @Test(dependsOnMethods = "createGeoSpeedAlert") public void getGeoSpeedAlerts() throws Exception { String result; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml index 5d6ce5fe1c..cdb5fdc20f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml @@ -32,7 +32,7 @@ - + diff --git a/pom.xml b/pom.xml index 1757d6e0ee..c30878f9e1 100644 --- a/pom.xml +++ b/pom.xml @@ -1532,13 +1532,6 @@ ${power.mock.version} test - - org.powermock - powermock-module-junit4 - ${power.mock.version} - - test - From 1450af6af95c75a2325d425d10db0de4a7cfc6c3 Mon Sep 17 00:00:00 2001 From: Pasindu Date: Thu, 28 Sep 2017 19:20:01 +0530 Subject: [PATCH 3/7] Replace possible constants --- .../service/GeoLocationProviderServiceTest.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java index fcd0800c63..1c184d3e51 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java @@ -132,7 +132,8 @@ public class GeoLocationProviderServiceTest { String result; result = geoLocationProviderServiceImpl.getSpeedAlerts(getDeviceIdentifier()); Assert.assertNotNull(result); - Assert.assertEquals(result, "{'speedLimit':"+SAMPLE_SPEED_ALERT_VALUE+"}"); + Assert.assertEquals(result, "{'speedLimit':" + + SAMPLE_SPEED_ALERT_VALUE + "}"); } @Test(dependsOnMethods = "createGeoTrafficAlert") @@ -142,7 +143,7 @@ public class GeoLocationProviderServiceTest { Assert.assertNotNull(geoFences); GeoFence geoFenceNode = geoFences.get(0); Assert.assertEquals(geoFenceNode.getGeoJson(), "{\n" + - " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\"\n" + + " \"" + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON + "\": \"" + SAMPLE_GEO_JSON + "\"\n" + "}"); } @@ -199,7 +200,7 @@ public class GeoLocationProviderServiceTest { alert.setDeviceId(DEVICE_ID); alert.setCepAction("CEP_ACTION"); alert.setParseData("{\n" + - " \"geoFenceGeoJSON\": \""+SAMPLE_GEO_JSON+"\"\n" + + " \" " + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON + "\": \"" + SAMPLE_GEO_JSON + "\"\n" + "}"); alert.setCustomName(SAMPLE_AREA_NAME); alert.setExecutionPlan("EXECUTION_PLAN"); @@ -213,7 +214,7 @@ public class GeoLocationProviderServiceTest { alert.setProximityTime(SAMPLE_PROXIMITY_TIME); alert.setProximityDistance(SAMPLE_PROXIMITY_DISATANCE); alert.setParseData("{\n" + - " \"geoFenceGeoJSON\": \""+SAMPLE_GEO_JSON+"\"\n" + + " \" " + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON + "\": \"" + SAMPLE_GEO_JSON + "\"\n" + "}"); return alert; } @@ -221,8 +222,8 @@ public class GeoLocationProviderServiceTest { private Alert getSpeedAlert() { Alert alert = getTestAlert(); alert.setParseData("{\n" + - " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\",\n" + - " \"speedAlertValue\": \"" + SAMPLE_SPEED_ALERT_VALUE + "\"\n" + + " \"" + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON + "\": \"" + SAMPLE_GEO_JSON + "\",\n" + + " \"" + DeviceManagementConstants.GeoServices.SPEED_ALERT_VALUE + "\": \"" + SAMPLE_SPEED_ALERT_VALUE + "\"\n" + "}"); return alert; } @@ -235,7 +236,7 @@ public class GeoLocationProviderServiceTest { alert.setStationeryTime(SAMPLE_STATIONARY_TIME); alert.setFluctuationRadius(SAMPLE_FLUCTUATION_RADIUS); alert.setParseData("{\n" + - " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\"\n" + + " \"" + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON + "\": \"" + SAMPLE_GEO_JSON + "\"\n" + "}"); return alert; } @@ -244,7 +245,7 @@ public class GeoLocationProviderServiceTest { Alert alert = new Alert(); alert.setDeviceId(DEVICE_ID); alert.setParseData("{\n" + - " \"geoFenceGeoJSON\": \"" + SAMPLE_GEO_JSON + "\"\n" + + " \"" + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON +"\": \"" + SAMPLE_GEO_JSON + "\"\n" + "}"); alert.setCustomName(SAMPLE_AREA_NAME); alert.setExecutionPlan("EXECUTION_PLAN"); From 4f47b63bfd4072b3814f7a852035b7bd313a4e17 Mon Sep 17 00:00:00 2001 From: Pasindu Date: Fri, 29 Sep 2017 12:04:03 +0530 Subject: [PATCH 4/7] Adding more test cases to GeoLocationProviderService --- .../org.wso2.carbon.device.mgt.core/pom.xml | 3 +- .../core/common/BaseDeviceManagementTest.java | 2 +- .../mgt/core/common/TestDataHolder.java | 15 ++ .../GeoLocationProviderServiceTest.java | 132 ++++++++++-------- 4 files changed, 88 insertions(+), 64 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index f5f07e1b32..aff01d97ad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -357,7 +357,8 @@ javassist - javassist + javassist + org.powermock powermock-api-mockito diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java index e5c21cdcd8..51789b1fef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java @@ -80,7 +80,7 @@ public abstract class BaseDeviceManagementTest { NotificationManagementDAOFactory.init(dataSource); } - private void initServices() throws DeviceManagementException, RegistryException { + protected void initServices() throws DeviceManagementException, RegistryException { DeviceConfigurationManager.getInstance().initConfig(); DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl(); DeviceManagementServiceComponent.notifyStartupListeners(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java index a23fdbc638..5a0be001ec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java @@ -98,6 +98,21 @@ public class TestDataHolder { return devices; } + public static Device generateDummyDeviceData(DeviceIdentifier deviceIdentifier) { + 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(deviceIdentifier.getId()); + device.setType(deviceIdentifier.getType()); + return device; + } + public static DeviceType generateDeviceTypeData(String devTypeName) { DeviceType deviceType = new DeviceType(); deviceType.setName(devTypeName); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java index 1c184d3e51..50398432e7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java @@ -1,10 +1,24 @@ +/* + * 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. + */ + package org.wso2.carbon.device.mgt.core.geo.service; -import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.powermock.core.classloader.annotations.PrepareForTest; import org.testng.Assert; import org.testng.annotations.BeforeClass; @@ -15,33 +29,18 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.geo.service.Alert; import org.wso2.carbon.device.mgt.common.geo.service.GeoFence; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; -import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; -import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; -import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl; import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; -import org.wso2.carbon.registry.core.config.RegistryContext; -import org.wso2.carbon.registry.core.exceptions.RegistryException; -import org.wso2.carbon.registry.core.internal.RegistryDataHolder; -import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; -import org.wso2.carbon.registry.core.service.RegistryService; -import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import java.io.InputStream; import java.rmi.RemoteException; import java.util.List; -import static org.powermock.api.mockito.PowerMockito.*; - -@PrepareForTest(GeoLocationProviderServiceImpl.class) public class GeoLocationProviderServiceTest { - private static final Log log = LogFactory.getLog(GeoLocationProviderServiceTest.class); private static final String DEVICE_TYPE = "GL_TEST_TYPE"; private static final String DEVICE_ID = "GL-TEST-DEVICE-ID-1"; private static final String SAMPLE_GEO_JSON = "12121"; @@ -59,54 +58,52 @@ public class GeoLocationProviderServiceTest { @BeforeClass public void init() throws Exception { initMocks(); - enrollTestDevice(); + enrollDev(); } - @Test + @Test (description = "Create a sample geo exit-alert with relevant details.") public void createGeoExitAlert() throws Exception { Boolean result = geoLocationProviderServiceImpl. - createGeoAlert(getTestAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_EXIT); + createGeoAlert(getExitAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_EXIT); Assert.assertEquals(result, Boolean.TRUE); - verifyPrivate(geoLocationProviderServiceImpl).invoke("getEventProcessorAdminServiceStub"); } - @Test + @Test (description = "Create a sample geo within-alert with relevant details.") public void createGeoWithinAlert() throws Exception { Boolean result = geoLocationProviderServiceImpl. - createGeoAlert(getTestAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_WITHIN); + createGeoAlert(getWithinAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_WITHIN); Assert.assertEquals(result, Boolean.TRUE); } - @Test + @Test (description = "Create a sample geo proximity-alert with relevant details.") public void createGeoProximityAlert() throws Exception { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getProximityAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_PROXIMITY); Assert.assertEquals(result, Boolean.TRUE); } - @Test + @Test (description = "Create a sample geo speed-alert with relevant details.") public void createGeoSpeedAlert() throws Exception { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getSpeedAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_SPEED); Assert.assertEquals(result, Boolean.TRUE); } - @Test + @Test (description = "Create a sample geo stationary-alert with relevant details.") public void createGeoStationaryAlert() throws Exception { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getStationaryAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_STATIONARY); Assert.assertEquals(result, Boolean.TRUE); } - @Test + @Test (description = "Create a sample geo traffic-alert with relevant details.") public void createGeoTrafficAlert() throws Exception { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getTrafficAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_TRAFFIC); Assert.assertEquals(result, Boolean.TRUE); } - //Test methods to retrieve saved Data. - @Test(dependsOnMethods = "createGeoExitAlert") + @Test(dependsOnMethods = "createGeoExitAlert", description = "retrieve saved geo exit-alert.") public void getGeoExitAlerts() throws Exception { List geoFences; geoFences = geoLocationProviderServiceImpl.getExitAlerts(getDeviceIdentifier()); @@ -117,7 +114,7 @@ public class GeoLocationProviderServiceTest { Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); } - @Test(dependsOnMethods = "createGeoWithinAlert") + @Test(dependsOnMethods = "createGeoWithinAlert", description = "retrieve saved geo within-alert.") public void getGeoWithinAlerts() throws Exception { List geoFences; geoFences = geoLocationProviderServiceImpl.getWithinAlerts(getDeviceIdentifier()); @@ -127,7 +124,7 @@ public class GeoLocationProviderServiceTest { Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); } - @Test(dependsOnMethods = "createGeoSpeedAlert") + @Test(dependsOnMethods = "createGeoSpeedAlert", description = "retrieve saved geo speed-alert.") public void getGeoSpeedAlerts() throws Exception { String result; result = geoLocationProviderServiceImpl.getSpeedAlerts(getDeviceIdentifier()); @@ -136,7 +133,7 @@ public class GeoLocationProviderServiceTest { SAMPLE_SPEED_ALERT_VALUE + "}"); } - @Test(dependsOnMethods = "createGeoTrafficAlert") + @Test(dependsOnMethods = "createGeoTrafficAlert" , description = "retrieve saved geo exit-alert.") public void getGeoTrafficAlerts() throws Exception { List geoFences; geoFences = geoLocationProviderServiceImpl.getTrafficAlerts(getDeviceIdentifier()); @@ -147,7 +144,7 @@ public class GeoLocationProviderServiceTest { "}"); } - @Test(dependsOnMethods = "createGeoStationaryAlert") + @Test(dependsOnMethods = "createGeoStationaryAlert", description = "retrieve saved geo stationary-alert.") public void getGeoStationaryAlerts() throws Exception { List geoFences; geoFences = geoLocationProviderServiceImpl.getStationaryAlerts(getDeviceIdentifier()); @@ -161,8 +158,10 @@ public class GeoLocationProviderServiceTest { private void initMocks() throws JWTClientException, RemoteException { mockEventProcessorAdminServiceStub = Mockito.mock(EventProcessorAdminServiceStub.class); geoLocationProviderServiceImpl = Mockito.mock(GeoLocationProviderServiceImpl.class, Mockito.CALLS_REAL_METHODS); - doReturn(mockEventProcessorAdminServiceStub).when(geoLocationProviderServiceImpl).getEventProcessorAdminServiceStub(); - doReturn("success").when(mockEventProcessorAdminServiceStub).validateExecutionPlan(Mockito.anyString()); + Mockito.doReturn(mockEventProcessorAdminServiceStub). + when(geoLocationProviderServiceImpl).getEventProcessorAdminServiceStub(); + Mockito.doReturn("success"). + when(mockEventProcessorAdminServiceStub).validateExecutionPlan(Mockito.anyString()); } private DeviceIdentifier getDeviceIdentifier() { @@ -171,31 +170,8 @@ public class GeoLocationProviderServiceTest { deviceIdentifier.setType("TEST"); return deviceIdentifier; } - private RegistryService getRegistryService() throws RegistryException { - RealmService realmService = new InMemoryRealmService(); - RegistryDataHolder.getInstance().setRealmService(realmService); - DeviceManagementDataHolder.getInstance().setRealmService(realmService); - InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); - RegistryContext context = RegistryContext.getBaseInstance(is, realmService); - context.setSetup(true); - return context.getEmbeddedRegistryService(); - } - - private void enrollTestDevice() throws Exception { - Device device = TestDataHolder.generateDummyDeviceData(DEVICE_ID); - DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl(); - DeviceManagementServiceComponent.notifyStartupListeners(); - DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); - DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService()); - DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl()); - DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl()); - DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); - deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); - deviceMgtService.enrollDevice(device); - } - private Alert getTestAlert() { + private Alert getWithinAlert() { Alert alert = new Alert(); alert.setDeviceId(DEVICE_ID); alert.setCepAction("CEP_ACTION"); @@ -208,6 +184,20 @@ public class GeoLocationProviderServiceTest { return alert; } + private Alert getExitAlert() { + Alert alert = new Alert(); + alert.setDeviceId(DEVICE_ID); + alert.setQueryName(SAMPLE_QUERY_NAME); + alert.setCustomName(SAMPLE_AREA_NAME); + alert.setStationeryTime(SAMPLE_STATIONARY_TIME); + alert.setFluctuationRadius(SAMPLE_FLUCTUATION_RADIUS); + alert.setParseData("{\n" + + " \" " + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON + "\": \"" + SAMPLE_GEO_JSON + "\"\n" + + "}"); + alert.setExecutionPlan("EXECUTION_PLAN"); + return alert; + } + private Alert getProximityAlert() { Alert alert = new Alert(); alert.setDeviceId(DEVICE_ID); @@ -220,7 +210,8 @@ public class GeoLocationProviderServiceTest { } private Alert getSpeedAlert() { - Alert alert = getTestAlert(); + Alert alert = new Alert(); + alert.setDeviceId(DEVICE_ID); alert.setParseData("{\n" + " \"" + DeviceManagementConstants.GeoServices.GEO_FENCE_GEO_JSON + "\": \"" + SAMPLE_GEO_JSON + "\",\n" + " \"" + DeviceManagementConstants.GeoServices.SPEED_ALERT_VALUE + "\": \"" + SAMPLE_SPEED_ALERT_VALUE + "\"\n" + @@ -252,4 +243,21 @@ public class GeoLocationProviderServiceTest { alert.setQueryName(SAMPLE_QUERY_NAME); return alert; } + + private void enrollDev() throws Exception { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE); + Device device = TestDataHolder.generateDummyDeviceData(deviceIdentifier); + DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance(). + getDeviceManagementProvider(); + deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); + deviceMgtService.enrollDevice(device); + + Device returnedDevice = deviceMgtService.getDevice(deviceIdentifier); + + if (!returnedDevice.getDeviceIdentifier().equals(deviceIdentifier.getId())) { + throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!"); + } + } + } From 7c613b55f5920c2bf594f9df2cf8a0035377dd60 Mon Sep 17 00:00:00 2001 From: Pasindu Date: Fri, 29 Sep 2017 15:16:20 +0530 Subject: [PATCH 5/7] Fix erros in unit tests --- .../GeoLocationProviderServiceTest.java | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java index 50398432e7..b62cd5647d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java @@ -26,8 +26,10 @@ import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.geo.service.Alert; import org.wso2.carbon.device.mgt.common.geo.service.GeoFence; +import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; @@ -58,74 +60,53 @@ public class GeoLocationProviderServiceTest { @BeforeClass public void init() throws Exception { initMocks(); - enrollDev(); + enrollDevice(); } @Test (description = "Create a sample geo exit-alert with relevant details.") - public void createGeoExitAlert() throws Exception { + public void createGeoExitAlert() throws GeoLocationBasedServiceException { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getExitAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_EXIT); Assert.assertEquals(result, Boolean.TRUE); } @Test (description = "Create a sample geo within-alert with relevant details.") - public void createGeoWithinAlert() throws Exception { + public void createGeoWithinAlert() throws GeoLocationBasedServiceException { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getWithinAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_WITHIN); Assert.assertEquals(result, Boolean.TRUE); } @Test (description = "Create a sample geo proximity-alert with relevant details.") - public void createGeoProximityAlert() throws Exception { + public void createGeoProximityAlert() throws GeoLocationBasedServiceException { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getProximityAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_PROXIMITY); Assert.assertEquals(result, Boolean.TRUE); } @Test (description = "Create a sample geo speed-alert with relevant details.") - public void createGeoSpeedAlert() throws Exception { + public void createGeoSpeedAlert() throws GeoLocationBasedServiceException { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getSpeedAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_SPEED); Assert.assertEquals(result, Boolean.TRUE); } @Test (description = "Create a sample geo stationary-alert with relevant details.") - public void createGeoStationaryAlert() throws Exception { + public void createGeoStationaryAlert() throws GeoLocationBasedServiceException { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getStationaryAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_STATIONARY); Assert.assertEquals(result, Boolean.TRUE); } @Test (description = "Create a sample geo traffic-alert with relevant details.") - public void createGeoTrafficAlert() throws Exception { + public void createGeoTrafficAlert() throws GeoLocationBasedServiceException { Boolean result = geoLocationProviderServiceImpl. createGeoAlert(getTrafficAlert(), getDeviceIdentifier(), DeviceManagementConstants.GeoServices.ALERT_TYPE_TRAFFIC); Assert.assertEquals(result, Boolean.TRUE); } - @Test(dependsOnMethods = "createGeoExitAlert", description = "retrieve saved geo exit-alert.") - public void getGeoExitAlerts() throws Exception { - List geoFences; - geoFences = geoLocationProviderServiceImpl.getExitAlerts(getDeviceIdentifier()); - Assert.assertNotNull(geoFences); - GeoFence geoFenceNode = geoFences.get(0); - Assert.assertEquals(geoFenceNode.getGeoJson(), SAMPLE_GEO_JSON); - Assert.assertEquals(geoFenceNode.getAreaName(), SAMPLE_AREA_NAME); - Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); - } - - @Test(dependsOnMethods = "createGeoWithinAlert", description = "retrieve saved geo within-alert.") - public void getGeoWithinAlerts() throws Exception { - List geoFences; - geoFences = geoLocationProviderServiceImpl.getWithinAlerts(getDeviceIdentifier()); - Assert.assertNotNull(geoFences); - GeoFence geoFenceNode = geoFences.get(0); - Assert.assertEquals(geoFenceNode.getAreaName(), SAMPLE_AREA_NAME); - Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME); - } - @Test(dependsOnMethods = "createGeoSpeedAlert", description = "retrieve saved geo speed-alert.") - public void getGeoSpeedAlerts() throws Exception { + public void getGeoSpeedAlerts() throws GeoLocationBasedServiceException { String result; result = geoLocationProviderServiceImpl.getSpeedAlerts(getDeviceIdentifier()); Assert.assertNotNull(result); @@ -134,7 +115,7 @@ public class GeoLocationProviderServiceTest { } @Test(dependsOnMethods = "createGeoTrafficAlert" , description = "retrieve saved geo exit-alert.") - public void getGeoTrafficAlerts() throws Exception { + public void getGeoTrafficAlerts() throws GeoLocationBasedServiceException { List geoFences; geoFences = geoLocationProviderServiceImpl.getTrafficAlerts(getDeviceIdentifier()); Assert.assertNotNull(geoFences); @@ -145,7 +126,7 @@ public class GeoLocationProviderServiceTest { } @Test(dependsOnMethods = "createGeoStationaryAlert", description = "retrieve saved geo stationary-alert.") - public void getGeoStationaryAlerts() throws Exception { + public void getGeoStationaryAlerts() throws GeoLocationBasedServiceException { List geoFences; geoFences = geoLocationProviderServiceImpl.getStationaryAlerts(getDeviceIdentifier()); Assert.assertNotNull(geoFences); @@ -244,7 +225,7 @@ public class GeoLocationProviderServiceTest { return alert; } - private void enrollDev() throws Exception { + private void enrollDevice() throws Exception { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE); Device device = TestDataHolder.generateDummyDeviceData(deviceIdentifier); DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance(). From 7b31fda94ff4beb0be25eec99a9a046494b2543f Mon Sep 17 00:00:00 2001 From: Pasindu Date: Mon, 2 Oct 2017 09:24:32 +0530 Subject: [PATCH 6/7] Fix formatting issue --- .../mgt/core/geo/service/GeoLocationProviderServiceTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java index b62cd5647d..b34f672a9b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java @@ -110,8 +110,7 @@ public class GeoLocationProviderServiceTest { String result; result = geoLocationProviderServiceImpl.getSpeedAlerts(getDeviceIdentifier()); Assert.assertNotNull(result); - Assert.assertEquals(result, "{'speedLimit':" + - SAMPLE_SPEED_ALERT_VALUE + "}"); + Assert.assertEquals(result, "{'speedLimit':" + SAMPLE_SPEED_ALERT_VALUE + "}"); } @Test(dependsOnMethods = "createGeoTrafficAlert" , description = "retrieve saved geo exit-alert.") From 378a69cc87fba764b5d7c4547c3744d7bb886544 Mon Sep 17 00:00:00 2001 From: Pasindu Date: Mon, 2 Oct 2017 09:29:01 +0530 Subject: [PATCH 7/7] Added license --- .../mgt/core/geo/service/GeoLocationProviderServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java index b34f672a9b..26aad9a908 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceTest.java @@ -14,6 +14,7 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * */ package org.wso2.carbon.device.mgt.core.geo.service;