From 046fad6bdb7ffed1afa8bb5fd3563a21021d0faf Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Wed, 27 Sep 2017 15:49:11 +0530 Subject: [PATCH] making required changes --- .../mgt/core/common/TestDataHolder.java | 14 +++++++ .../mgt/NotificationManagementTests.java | 10 +++-- .../core/search/util/MockNotification.java | 37 ------------------- 3 files changed, 20 insertions(+), 41 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/MockNotification.java 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 180fae6b1b..356efb2426 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 @@ -20,6 +20,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; 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; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.ArrayList; @@ -52,6 +53,19 @@ public class TestDataHolder { return device; } + public static Notification getNotification(int notificationId, String status, String deviceId, String deviceName, + int operationId, String deviceType){ + Notification notification = new Notification(); + notification.setNotificationId(notificationId); + notification.setStatus(status); + notification.setDeviceIdentifier(deviceId); + notification.setDescription("test description"); + notification.setDeviceName(deviceName); + notification.setOperationId(operationId); + notification.setDeviceType(deviceType); + return notification; + } + public static List generateDummyDeviceData(List deviceIds) { List devices = new ArrayList<>(); for (DeviceIdentifier deviceId : deviceIds) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementTests.java index 7f70461a14..8257785fc1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementTests.java @@ -31,7 +31,6 @@ import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; 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.search.util.MockNotification; 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; @@ -47,6 +46,9 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +/** + * This class is used to test NotificationManagementServiceImpl. + */ public class NotificationManagementTests { private static final Log log = LogFactory.getLog(NotificationManagementTests.class); @@ -54,7 +56,6 @@ public class NotificationManagementTests { private static final String DEVICE_ID_PREFIX = "NOTIFICATION-TEST-DEVICE-ID-"; private static final int NO_OF_DEVICES = 10; private List deviceIds = new ArrayList<>(); - private MockNotification mockNotification = new MockNotification(); @BeforeClass public void init() throws Exception { @@ -95,14 +96,15 @@ public class NotificationManagementTests { return context.getEmbeddedRegistryService(); } - @Test + @Test(description = "Add notifications using addNotification method and check whether it returns true.") public void addNotification() throws Exception { for (int i = 0; i < NO_OF_DEVICES; i++) { DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE); - Notification notification = mockNotification.getNotification(i, "CHECKED", + Notification notification = TestDataHolder.getNotification(i, "CHECKED", testDeviceIdentifier.toString(), DEVICE_ID_PREFIX + i, 1, DEVICE_TYPE); NotificationManagementServiceImpl notificationManagementService = new NotificationManagementServiceImpl(); Assert.assertTrue(notificationManagementService.addNotification(testDeviceIdentifier, notification)); } } } + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/MockNotification.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/MockNotification.java deleted file mode 100644 index d6787defbe..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/MockNotification.java +++ /dev/null @@ -1,37 +0,0 @@ -/* -* 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.search.util; - -import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; - -public class MockNotification { - - public Notification getNotification(int notificationId,String status,String deviceId,String deviceName, - int operationId, String deviceType){ - Notification notification = new Notification(); - notification.setNotificationId(notificationId); - notification.setStatus(status); - notification.setDeviceIdentifier(deviceId); - notification.setDescription("test description"); - notification.setDeviceName(deviceName); - notification.setOperationId(operationId); - notification.setDeviceType(deviceType); - return notification; - } -} -