From b33289a81b44e0d51d79f784fc92e0f6b5719e32 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 28 Sep 2017 11:51:13 +0530 Subject: [PATCH 1/5] adding test cases for NotificationManagementServiceImpl --- .../mgt/core/common/TestDataHolder.java | 1 + ...otificationManagementServiceImplTests.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) 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 a6af04fad7a..d063c9594da 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 @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.common; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java index 87de3578308..50e98971ca9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java @@ -25,6 +25,8 @@ 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.EntityDoesNotExistException; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; @@ -170,5 +172,22 @@ public class NotificationManagementServiceImplTests { Assert.assertEquals(returnedNotifications.size(), NO_OF_NOTIFICATIONS); } + @Test(dependsOnMethods = "addNotification", description = "this tests for getAllNotification method by passing " + + "pagination request and validates the no. of total records and filtered records. ") + public void getAllNotificationsWithPaginationRequest() throws NotificationManagementException { + PaginationRequest request = new PaginationRequest(1, 2); + PaginationResult result = notificationManagementService.getAllNotifications(request); + Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS); + Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS); + } + + @Test(dependsOnMethods = "updateNotificationStatus", description = "this tests for getAllNotification method by" + + " passing pagination request & status and validates the no. of total records and filtered records. ") + public void getAllNotificationsWithPaginationRequestAndStatus() throws NotificationManagementException { + PaginationRequest request = new PaginationRequest(1, 2); + PaginationResult result = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED, request); + Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS); + Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS); + } } From 768e39fecfe8ad48560f377c99d542109e093acb Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 28 Sep 2017 14:00:50 +0530 Subject: [PATCH 2/5] adding more tests for notificationmanagementserviceImpl --- ...otificationManagementServiceImplTests.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java index 50e98971ca9..c381d73e357 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java @@ -83,7 +83,8 @@ public class NotificationManagementServiceImplTests { deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); for (Device device : devices) { - deviceMgtService.enrollDevice(device); + Assert.assertTrue(deviceMgtService.enrollDevice(device), "Device with Identifier - " + + device.getDeviceIdentifier() + " is not enrolled."); } List returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE); @@ -127,14 +128,24 @@ public class NotificationManagementServiceImplTests { DEVICE_TYPE), notification); } + @Test(expectedExceptions = NotificationManagementException.class, description = "This tests the method getDevice which" + + " is called internally in addNotification fot DeviceManagementException exception passing null device Id.") + public void getDevice() throws NotificationManagementException { + DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + 123, DEVICE_TYPE); + Notification notification = TestDataHolder.getNotification(1, Notification.Status.NEW.toString(), + testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + 123, + NOTIFICATION_OPERATION_ID, DEVICE_TYPE); + notificationManagementService.addNotification(null, notification); + } + @Test(dependsOnMethods = "addNotification", description = "This tests the updateNotification Method" + " and check whether it returns true ( got updated )") public void updateNotification() throws NotificationManagementException { for (int i = 1; i <= NO_OF_DEVICES; i++) { DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE); Notification notification = TestDataHolder.getNotification(i, Notification.Status.CHECKED.toString(), - testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i, NOTIFICATION_OPERATION_ID, - DEVICE_TYPE); + testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i, + NOTIFICATION_OPERATION_ID, DEVICE_TYPE); Assert.assertTrue(notificationManagementService.updateNotification(notification)); } } @@ -185,9 +196,11 @@ public class NotificationManagementServiceImplTests { " passing pagination request & status and validates the no. of total records and filtered records. ") public void getAllNotificationsWithPaginationRequestAndStatus() throws NotificationManagementException { PaginationRequest request = new PaginationRequest(1, 2); - PaginationResult result = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED, request); + PaginationResult result = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED, + request); Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS); Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS); } + } From b6d7c0dc0ab70756efe448be950b17c5f0abf3f6 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 28 Sep 2017 14:05:46 +0530 Subject: [PATCH 3/5] correcting minor spelling mistake --- .../mgt/NotificationManagementServiceImplTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java index c381d73e357..a1cb11d843d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java @@ -129,7 +129,7 @@ public class NotificationManagementServiceImplTests { } @Test(expectedExceptions = NotificationManagementException.class, description = "This tests the method getDevice which" + - " is called internally in addNotification fot DeviceManagementException exception passing null device Id.") + " is called internally in addNotification for DeviceManagementException exception passing null device Id.") public void getDevice() throws NotificationManagementException { DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + 123, DEVICE_TYPE); Notification notification = TestDataHolder.getNotification(1, Notification.Status.NEW.toString(), From 042cf027885a3d0aa0d446070edffeb746cbb31d Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 28 Sep 2017 14:19:11 +0530 Subject: [PATCH 4/5] making required changes --- ...otificationManagementServiceImplTests.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java index a1cb11d843d..9ce16e386bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java @@ -113,7 +113,8 @@ public class NotificationManagementServiceImplTests { Notification notification = TestDataHolder.getNotification(i, Notification.Status.NEW.toString(), testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i, NOTIFICATION_OPERATION_ID, DEVICE_TYPE); - Assert.assertTrue(notificationManagementService.addNotification(testDeviceIdentifier, notification)); + Assert.assertTrue(notificationManagementService.addNotification(testDeviceIdentifier, notification), + "Adding notification failed for [" + notification.toString() + "]"); } } @@ -146,7 +147,7 @@ public class NotificationManagementServiceImplTests { Notification notification = TestDataHolder.getNotification(i, Notification.Status.CHECKED.toString(), testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i, NOTIFICATION_OPERATION_ID, DEVICE_TYPE); - Assert.assertTrue(notificationManagementService.updateNotification(notification)); + Assert.assertTrue(notificationManagementService.updateNotification(notification), "Notification update failed for [" + notification.toString() + "]"); } } @@ -154,7 +155,8 @@ public class NotificationManagementServiceImplTests { "and check whether it got updated") public void updateNotificationStatus() throws NotificationManagementException { for (int i = 1; i <= NO_OF_DEVICES; i++) { - Assert.assertTrue(notificationManagementService.updateNotificationStatus(i, Notification.Status.CHECKED)); + Assert.assertTrue(notificationManagementService.updateNotificationStatus(i, Notification.Status.CHECKED), + "Notification update status failed for notification id:- " + i); } } @@ -162,7 +164,8 @@ public class NotificationManagementServiceImplTests { " method by listing down all the notifications.") public void getAllNotifications() throws NotificationManagementException { List returnedNotifications = notificationManagementService.getAllNotifications(); - Assert.assertEquals(returnedNotifications.size(), NO_OF_DEVICES); + Assert.assertEquals(returnedNotifications.size(), NO_OF_DEVICES, "No. of notifications added is not " + + "equal to no. of notifications retrieved."); } @Test(dependsOnMethods = "updateNotificationStatus", description = "this method retries notification by id" + @@ -170,17 +173,22 @@ public class NotificationManagementServiceImplTests { public void getNotification() throws NotificationManagementException { for (int i = 1; i <= NO_OF_DEVICES; i++) { Notification returnedNotification = notificationManagementService.getNotification(i); - Assert.assertEquals(returnedNotification.getNotificationId(), i); - Assert.assertEquals(returnedNotification.getStatus(), Notification.Status.CHECKED); - Assert.assertEquals(returnedNotification.getDescription(), TEST_NOTIFICATION_DESCRIPTION); - Assert.assertEquals(returnedNotification.getOperationId(), NOTIFICATION_OPERATION_ID); + Assert.assertEquals(returnedNotification.getNotificationId(), i, "Returned notification ID is not " + + "same as added notification Id."); + Assert.assertEquals(returnedNotification.getStatus(), Notification.Status.CHECKED, "Returned " + + "notification status is not same as added notification status."); + Assert.assertEquals(returnedNotification.getDescription(), TEST_NOTIFICATION_DESCRIPTION, "Returned" + + " notification description is not same as added notification description."); + Assert.assertEquals(returnedNotification.getOperationId(), NOTIFICATION_OPERATION_ID, "Returned " + + "notification operation ID is not same as added notification operation Id."); } } @Test(dependsOnMethods = "updateNotificationStatus", description = "this method gets all notification by status checked") public void getNotificationsByStatus() throws NotificationManagementException { List returnedNotifications = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED); - Assert.assertEquals(returnedNotifications.size(), NO_OF_NOTIFICATIONS); + Assert.assertEquals(returnedNotifications.size(), NO_OF_NOTIFICATIONS, "Returned no. of notification is " + + "not same as added no. of notifications."); } @Test(dependsOnMethods = "addNotification", description = "this tests for getAllNotification method by passing " + @@ -188,8 +196,10 @@ public class NotificationManagementServiceImplTests { public void getAllNotificationsWithPaginationRequest() throws NotificationManagementException { PaginationRequest request = new PaginationRequest(1, 2); PaginationResult result = notificationManagementService.getAllNotifications(request); - Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS); - Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS); + Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS, "Returned filtered records is " + + "not same as added filtered records."); + Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS, "Returned no. of records is not " + + "same as added no. of records."); } @Test(dependsOnMethods = "updateNotificationStatus", description = "this tests for getAllNotification method by" + @@ -198,8 +208,10 @@ public class NotificationManagementServiceImplTests { PaginationRequest request = new PaginationRequest(1, 2); PaginationResult result = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED, request); - Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS); - Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS); + Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS, "Returned filtered records is not " + + "same as added filtered records."); + Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS, "Returned no. of records is not same" + + " as added no. of records."); } } From 3b475a53052cdbf272dd52cc01f28ef79b3b5984 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 28 Sep 2017 14:20:46 +0530 Subject: [PATCH 5/5] making required changes --- .../mgt/NotificationManagementServiceImplTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java index 9ce16e386bb..21e729293da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java @@ -147,7 +147,8 @@ public class NotificationManagementServiceImplTests { Notification notification = TestDataHolder.getNotification(i, Notification.Status.CHECKED.toString(), testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i, NOTIFICATION_OPERATION_ID, DEVICE_TYPE); - Assert.assertTrue(notificationManagementService.updateNotification(notification), "Notification update failed for [" + notification.toString() + "]"); + Assert.assertTrue(notificationManagementService.updateNotification(notification), "Notification " + + "update failed for [" + notification.toString() + "]"); } } @@ -186,7 +187,8 @@ public class NotificationManagementServiceImplTests { @Test(dependsOnMethods = "updateNotificationStatus", description = "this method gets all notification by status checked") public void getNotificationsByStatus() throws NotificationManagementException { - List returnedNotifications = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED); + List returnedNotifications = notificationManagementService.getNotificationsByStatus(Notification. + Status.CHECKED); Assert.assertEquals(returnedNotifications.size(), NO_OF_NOTIFICATIONS, "Returned no. of notification is " + "not same as added no. of notifications."); }