From bd04e3d8b2b308aaafdffad8df191fc2c9a194e9 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Fri, 29 Sep 2017 13:05:26 +0530 Subject: [PATCH] Adding some testcases for the invalid devices, and parameters. --- .../operation/OperationManagementTests.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) 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 9ba56c160a..afb4fbe8dc 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 @@ -357,14 +357,16 @@ public class OperationManagementTests extends BaseDeviceManagementTest { @Test(dependsOnMethods = "getNextPendingOperation") public void getOperationByDeviceAndOperationId() throws OperationManagementException { DeviceIdentifier deviceIdentifier = this.deviceIds.get(0); - String operationId = this.commandActivity.getActivityId(). - replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""); Operation operation = this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier, - Integer.parseInt(operationId)); + getOperationId(this.commandActivity.getActivityId())); Assert.assertTrue(operation.getStatus().equals(Operation.Status.COMPLETED)); Assert.assertTrue(operation.getType().equals(Operation.Type.COMMAND)); } + private int getOperationId(String activityId) { + return Integer.parseInt(activityId.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); + } + @Test(dependsOnMethods = "getNextPendingOperation", expectedExceptions = OperationManagementException.class) public void getOperationByDeviceAndOperationIdNonAdmin() throws OperationManagementException { startTenantFlowAsNonAdmin(); @@ -493,7 +495,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest { @Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class) public void getPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException { - this.operationMgtService.getPendingOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); + this.operationMgtService.getPendingOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); } @Test(dependsOnMethods = "getPendingOperationDeviceForInvalidDevice", expectedExceptions = OperationManagementException.class) @@ -501,4 +503,38 @@ public class OperationManagementTests extends BaseDeviceManagementTest { this.operationMgtService.getNextPendingOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); } + @Test(dependsOnMethods = "getNextPendingOperationDeviceForInvalidDevice", expectedExceptions = OperationManagementException.class) + public void getUpdateOperationForInvalidDevice() throws DeviceManagementException, OperationManagementException { + this.operationMgtService.updateOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), getOperation(new CommandOperation(), + Operation.Type.COMMAND, COMMAND_OPERATON_CODE)); + } + + @Test(dependsOnMethods = "getUpdateOperationForInvalidDevice", expectedExceptions = OperationManagementException.class) + public void getOperationByDeviceAndOperationIdInvalidDevice() throws DeviceManagementException, OperationManagementException { + this.operationMgtService.getOperationByDeviceAndOperationId(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), + getOperationId(this.commandActivity.getActivityId())); + } + + @Test(dependsOnMethods = "getOperationByDeviceAndOperationIdInvalidDevice", expectedExceptions = OperationManagementException.class) + public void getOperationsByDeviceAndStatusInvalidDevice() throws DeviceManagementException, OperationManagementException { + this.operationMgtService.getOperationsByDeviceAndStatus(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), + Operation.Status.PENDING); + } + + @Test(dependsOnMethods = "getOperationsByDeviceAndStatusInvalidDevice", expectedExceptions = OperationManagementException.class) + public void getOperationsInvalidOperationId() throws DeviceManagementException, OperationManagementException { + this.operationMgtService.getOperation(123445); + } + + @Test(dependsOnMethods = "getOperationsInvalidOperationId", expectedExceptions = IllegalArgumentException.class) + public void getOperationsByActivityIdInvalidActivityId() throws DeviceManagementException, OperationManagementException { + this.operationMgtService.getOperationByActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + 0); + } + + @Test(dependsOnMethods = "getOperationsByActivityIdInvalidActivityId", expectedExceptions = IllegalArgumentException.class) + public void getOperationByActivityIdAndDeviceInvalidActivityId() throws DeviceManagementException, OperationManagementException { + this.operationMgtService.getOperationByActivityIdAndDevice(DeviceManagementConstants.OperationAttributes.ACTIVITY + 0, + new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); + } + }