From c5cfa23caa4ffaa24ed38da88ab998d3943896fc Mon Sep 17 00:00:00 2001 From: sinthuja Date: Fri, 29 Sep 2017 14:21:02 +0530 Subject: [PATCH] Adding some testcases for the invalid devices, and parameters. --- .../operation/OperationManagementTests.java | 74 ++++++++++++------- 1 file changed, 48 insertions(+), 26 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 afb4fbe8dc..c861e2fb75 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 @@ -144,7 +144,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest { } @Test(expectedExceptions = InvalidDeviceException.class) - public void addNonInitializedDevicesCommandOperation() throws DeviceManagementException, OperationManagementException, + public void addNonInitializedDevicesCommandOperation() throws DeviceManagementException, + OperationManagementException, InvalidDeviceException { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); List deviceIdentifiers = new ArrayList<>(); @@ -207,8 +208,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest { } private void validateOperationResponse(Activity activity, ActivityStatus.Status expectedStatus) { - Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation response for add operation only have - " + - activity.getActivityStatus().size()); + Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation response for add " + + "operation only have - " + activity.getActivityStatus().size()); for (ActivityStatus status : activity.getActivityStatus()) { Assert.assertEquals(status.getStatus(), expectedStatus); } @@ -223,7 +224,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest { } @Test(dependsOnMethods = "addProfileOperation", expectedExceptions = OperationManagementException.class) - public void getOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + public void getOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, + InvalidDeviceException { try { startTenantFlowAsNonAdmin(); for (DeviceIdentifier deviceIdentifier : deviceIds) { @@ -235,15 +237,18 @@ public class OperationManagementTests extends BaseDeviceManagementTest { } @Test(dependsOnMethods = "getOperations") - public void getPendingOperations() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + public void getPendingOperations() throws DeviceManagementException, OperationManagementException, + InvalidDeviceException { for (DeviceIdentifier deviceIdentifier : deviceIds) { List operations = this.operationMgtService.getPendingOperations(deviceIdentifier); - Assert.assertEquals(operations.size(), 4, "The pending operations should be 4, but found only " + operations.size()); + Assert.assertEquals(operations.size(), 4, "The pending operations should be 4, but found only " + + operations.size()); } } @Test(dependsOnMethods = "getOperations", expectedExceptions = OperationManagementException.class) - public void getPendingOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + public void getPendingOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, + InvalidDeviceException { try { startTenantFlowAsNonAdmin(); for (DeviceIdentifier deviceIdentifier : deviceIds) { @@ -384,12 +389,14 @@ public class OperationManagementTests extends BaseDeviceManagementTest { @Test(dependsOnMethods = "getOperationByDeviceAndOperationId") public void getOperationsByDeviceAndStatus() throws OperationManagementException, DeviceManagementException { DeviceIdentifier deviceIdentifier = this.deviceIds.get(0); - List operation = this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING); + List operation = this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier, + Operation.Status.PENDING); Assert.assertEquals(operation.size(), 3); } @Test(dependsOnMethods = "getOperationByDeviceAndOperationId", expectedExceptions = OperationManagementException.class) - public void getOperationsByDeviceAndStatusByNonAdmin() throws OperationManagementException, DeviceManagementException { + public void getOperationsByDeviceAndStatusByNonAdmin() throws OperationManagementException, + DeviceManagementException { startTenantFlowAsNonAdmin(); try { DeviceIdentifier deviceIdentifier = this.deviceIds.get(0); @@ -476,7 +483,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest { } @Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class) - public void getPaginatedOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException { + public void getPaginatedOperationDeviceForInvalidDevice() throws DeviceManagementException, + OperationManagementException { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER); @@ -484,7 +492,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest { PaginationRequest request = new PaginationRequest(1, 2); request.setDeviceType(DEVICE_TYPE); request.setOwner(ADMIN_USER); - PaginationResult result = this.operationMgtService.getOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), request); + PaginationResult result = this.operationMgtService.getOperations + (new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), request); Assert.assertEquals(result.getRecordsFiltered(), 4); Assert.assertEquals(result.getData().size(), 2); Assert.assertEquals(result.getRecordsTotal(), 4); @@ -494,45 +503,58 @@ public class OperationManagementTests extends BaseDeviceManagementTest { } @Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class) - public void getPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException { + public void getPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, + OperationManagementException { this.operationMgtService.getPendingOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); } - @Test(dependsOnMethods = "getPendingOperationDeviceForInvalidDevice", expectedExceptions = OperationManagementException.class) - public void getNextPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException { + @Test(dependsOnMethods = "getPendingOperationDeviceForInvalidDevice", + expectedExceptions = OperationManagementException.class) + public void getNextPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, + OperationManagementException { this.operationMgtService.getNextPendingOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); } - @Test(dependsOnMethods = "getNextPendingOperationDeviceForInvalidDevice", expectedExceptions = OperationManagementException.class) + @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)); + 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 { + @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 { + @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 { + @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 { + 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 { + @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)); }