From e57fe2bf37467da76f1d6ec80ccfaaeae2d6e182 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Wed, 27 Sep 2017 16:47:52 +0530 Subject: [PATCH] Adding more testcases. --- .../operation/OperationManagementTests.java | 25 ++++++++- .../operation/TestNotificationStrategy.java | 51 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/TestNotificationStrategy.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java index 2005268142..bcc4aa114e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java @@ -33,9 +33,11 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; 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.BaseDeviceManagementTest; 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; @@ -109,7 +111,8 @@ public class OperationManagementTests { throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!"); } } - this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE); + NotificationStrategy notificationStrategy = new TestNotificationStrategy(); + this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy); } private RegistryService getRegistryService() throws RegistryException { @@ -129,6 +132,21 @@ public class OperationManagementTests { validateOperationResponse(this.commandActivity); } + @Test (expectedExceptions = InvalidDeviceException.class) + public void addEmptyDevicesCommandOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE), + new ArrayList<>()); + } + + @Test (expectedExceptions = InvalidDeviceException.class) + public void addNonInitializedDevicesCommandOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + List deviceIdentifiers = new ArrayList<>(); + deviceIdentifiers.add(deviceIdentifier); + this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE), + deviceIdentifiers); + } + @Test(dependsOnMethods = "addCommandOperation") public void addPolicyOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { Activity activity = this.operationMgtService.addOperation(getOperation(new PolicyOperation(), Operation.Type.POLICY, POLICY_OPERATION_CODE), @@ -337,4 +355,9 @@ public class OperationManagementTests { "The activities updated after the created should be 1"); } + @Test + public void getNotificationStrategy(){ + Assert.assertTrue(this.operationMgtService.getNotificationStrategy() != null); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/TestNotificationStrategy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/TestNotificationStrategy.java new file mode 100644 index 0000000000..28afa2da1f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/TestNotificationStrategy.java @@ -0,0 +1,51 @@ +/* +* 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.operation; + +import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; +import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; +import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; +import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; + +public class TestNotificationStrategy implements NotificationStrategy { + + @Override + public void init() { + + } + + @Override + public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { + + } + + @Override + public NotificationContext buildContext() { + return null; + } + + @Override + public void undeploy() { + + } + + @Override + public PushNotificationConfig getConfig() { + return null; + } +}