mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
NotificationManagemet testcase
This commit is contained in:
parent
fc6af884f6
commit
a6eb95e2e8
@ -50,11 +50,9 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
|||||||
private static final Log log = LogFactory.getLog(NotificationManagementServiceImpl.class);
|
private static final Log log = LogFactory.getLog(NotificationManagementServiceImpl.class);
|
||||||
|
|
||||||
private NotificationDAO notificationDAO;
|
private NotificationDAO notificationDAO;
|
||||||
private DeviceDAO deviceDAO;
|
|
||||||
|
|
||||||
public NotificationManagementServiceImpl() {
|
public NotificationManagementServiceImpl() {
|
||||||
this.notificationDAO = NotificationManagementDAOFactory.getNotificationDAO();
|
this.notificationDAO = NotificationManagementDAOFactory.getNotificationDAO();
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -279,4 +279,4 @@ public abstract class AbstractNotificationDAOImpl implements NotificationDAO {
|
|||||||
}
|
}
|
||||||
return notificationCountByStatus;
|
return notificationCountByStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.core.TestUtils;
|
import org.wso2.carbon.device.mgt.core.TestUtils;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ public abstract class BaseDeviceManagementTest {
|
|||||||
DeviceManagementDAOFactory.init(dataSource);
|
DeviceManagementDAOFactory.init(dataSource);
|
||||||
GroupManagementDAOFactory.init(dataSource);
|
GroupManagementDAOFactory.init(dataSource);
|
||||||
OperationManagementDAOFactory.init(dataSource);
|
OperationManagementDAOFactory.init(dataSource);
|
||||||
|
NotificationManagementDAOFactory.init(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@ -131,7 +133,7 @@ public abstract class BaseDeviceManagementTest {
|
|||||||
try {
|
try {
|
||||||
conn = getDataSource().getConnection();
|
conn = getDataSource().getConnection();
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
String[] cleanupTables = new String[]{"DM_DEVICE_OPERATION_RESPONSE","DM_ENROLMENT_OP_MAPPING", "DM_CONFIG_OPERATION",
|
String[] cleanupTables = new String[]{"DM_NOTIFICATION","DM_DEVICE_OPERATION_RESPONSE","DM_ENROLMENT_OP_MAPPING", "DM_CONFIG_OPERATION",
|
||||||
"DM_POLICY_OPERATION", "DM_COMMAND_OPERATION", "DM_PROFILE_OPERATION", "DM_DEVICE_GROUP_MAP",
|
"DM_POLICY_OPERATION", "DM_COMMAND_OPERATION", "DM_PROFILE_OPERATION", "DM_DEVICE_GROUP_MAP",
|
||||||
"DM_GROUP", "DM_ENROLMENT", "DM_DEVICE_APPLICATION_MAPPING",
|
"DM_GROUP", "DM_ENROLMENT", "DM_DEVICE_APPLICATION_MAPPING",
|
||||||
"DM_APPLICATION", "DM_DEVICE", "DM_DEVICE_TYPE"};
|
"DM_APPLICATION", "DM_DEVICE", "DM_DEVICE_TYPE"};
|
||||||
|
|||||||
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* 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.notification.mgt;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
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.notification.mgt.Notification;
|
||||||
|
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.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;
|
||||||
|
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.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NotificationManagementTests {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(NotificationManagementTests.class);
|
||||||
|
private static final String DEVICE_TYPE = "NOTIFICATION_TEST_DEVICE";
|
||||||
|
private static final String DEVICE_ID_PREFIX = "NOTIFICATION-TEST-DEVICE-ID-";
|
||||||
|
private static final int NO_OF_DEVICES = 10;
|
||||||
|
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||||
|
private MockNotification mockNotification = new MockNotification();
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() throws Exception {
|
||||||
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
|
log.info("Initializing");
|
||||||
|
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
||||||
|
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||||
|
}
|
||||||
|
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
||||||
|
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));
|
||||||
|
for (Device device : devices) {
|
||||||
|
deviceMgtService.enrollDevice(device);
|
||||||
|
}
|
||||||
|
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
|
||||||
|
|
||||||
|
for (Device device : returnedDevices) {
|
||||||
|
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||||
|
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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",
|
||||||
|
testDeviceIdentifier.toString(), DEVICE_ID_PREFIX + i, 1, DEVICE_TYPE);
|
||||||
|
NotificationManagementServiceImpl notificationManagementService = new NotificationManagementServiceImpl();
|
||||||
|
Assert.assertTrue(notificationManagementService.addNotification(testDeviceIdentifier, notification));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -43,6 +43,7 @@
|
|||||||
<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>
|
<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>
|
||||||
<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>
|
<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>
|
||||||
<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest" />
|
<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest" />
|
||||||
|
<class name="org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementTests"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user