Adding some testcases for the invalid devices, and parameters.

revert-70aa11f8
sinthuja 7 years ago
parent bd04e3d8b2
commit c5cfa23caa

@ -144,7 +144,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
} }
@Test(expectedExceptions = InvalidDeviceException.class) @Test(expectedExceptions = InvalidDeviceException.class)
public void addNonInitializedDevicesCommandOperation() throws DeviceManagementException, OperationManagementException, public void addNonInitializedDevicesCommandOperation() throws DeviceManagementException,
OperationManagementException,
InvalidDeviceException { InvalidDeviceException {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
@ -207,8 +208,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
} }
private void validateOperationResponse(Activity activity, ActivityStatus.Status expectedStatus) { private void validateOperationResponse(Activity activity, ActivityStatus.Status expectedStatus) {
Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation response for add operation only have - " + Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation response for add " +
activity.getActivityStatus().size()); "operation only have - " + activity.getActivityStatus().size());
for (ActivityStatus status : activity.getActivityStatus()) { for (ActivityStatus status : activity.getActivityStatus()) {
Assert.assertEquals(status.getStatus(), expectedStatus); Assert.assertEquals(status.getStatus(), expectedStatus);
} }
@ -223,7 +224,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
} }
@Test(dependsOnMethods = "addProfileOperation", expectedExceptions = OperationManagementException.class) @Test(dependsOnMethods = "addProfileOperation", expectedExceptions = OperationManagementException.class)
public void getOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void getOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
try { try {
startTenantFlowAsNonAdmin(); startTenantFlowAsNonAdmin();
for (DeviceIdentifier deviceIdentifier : deviceIds) { for (DeviceIdentifier deviceIdentifier : deviceIds) {
@ -235,15 +237,18 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
} }
@Test(dependsOnMethods = "getOperations") @Test(dependsOnMethods = "getOperations")
public void getPendingOperations() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void getPendingOperations() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
for (DeviceIdentifier deviceIdentifier : deviceIds) { for (DeviceIdentifier deviceIdentifier : deviceIds) {
List operations = this.operationMgtService.getPendingOperations(deviceIdentifier); 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) @Test(dependsOnMethods = "getOperations", expectedExceptions = OperationManagementException.class)
public void getPendingOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void getPendingOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
try { try {
startTenantFlowAsNonAdmin(); startTenantFlowAsNonAdmin();
for (DeviceIdentifier deviceIdentifier : deviceIds) { for (DeviceIdentifier deviceIdentifier : deviceIds) {
@ -384,12 +389,14 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
@Test(dependsOnMethods = "getOperationByDeviceAndOperationId") @Test(dependsOnMethods = "getOperationByDeviceAndOperationId")
public void getOperationsByDeviceAndStatus() throws OperationManagementException, DeviceManagementException { public void getOperationsByDeviceAndStatus() throws OperationManagementException, DeviceManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0); 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); Assert.assertEquals(operation.size(), 3);
} }
@Test(dependsOnMethods = "getOperationByDeviceAndOperationId", expectedExceptions = OperationManagementException.class) @Test(dependsOnMethods = "getOperationByDeviceAndOperationId", expectedExceptions = OperationManagementException.class)
public void getOperationsByDeviceAndStatusByNonAdmin() throws OperationManagementException, DeviceManagementException { public void getOperationsByDeviceAndStatusByNonAdmin() throws OperationManagementException,
DeviceManagementException {
startTenantFlowAsNonAdmin(); startTenantFlowAsNonAdmin();
try { try {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0); DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
@ -476,7 +483,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
} }
@Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class) @Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class)
public void getPaginatedOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException { public void getPaginatedOperationDeviceForInvalidDevice() throws DeviceManagementException,
OperationManagementException {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
@ -484,7 +492,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
PaginationRequest request = new PaginationRequest(1, 2); PaginationRequest request = new PaginationRequest(1, 2);
request.setDeviceType(DEVICE_TYPE); request.setDeviceType(DEVICE_TYPE);
request.setOwner(ADMIN_USER); 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.getRecordsFiltered(), 4);
Assert.assertEquals(result.getData().size(), 2); Assert.assertEquals(result.getData().size(), 2);
Assert.assertEquals(result.getRecordsTotal(), 4); Assert.assertEquals(result.getRecordsTotal(), 4);
@ -494,45 +503,58 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
} }
@Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class) @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)); this.operationMgtService.getPendingOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE));
} }
@Test(dependsOnMethods = "getPendingOperationDeviceForInvalidDevice", expectedExceptions = OperationManagementException.class) @Test(dependsOnMethods = "getPendingOperationDeviceForInvalidDevice",
public void getNextPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException { expectedExceptions = OperationManagementException.class)
public void getNextPendingOperationDeviceForInvalidDevice() throws DeviceManagementException,
OperationManagementException {
this.operationMgtService.getNextPendingOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); 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 { public void getUpdateOperationForInvalidDevice() throws DeviceManagementException, OperationManagementException {
this.operationMgtService.updateOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), getOperation(new CommandOperation(), this.operationMgtService.updateOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
Operation.Type.COMMAND, COMMAND_OPERATON_CODE)); getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE));
} }
@Test(dependsOnMethods = "getUpdateOperationForInvalidDevice", expectedExceptions = OperationManagementException.class) @Test(dependsOnMethods = "getUpdateOperationForInvalidDevice",
public void getOperationByDeviceAndOperationIdInvalidDevice() throws DeviceManagementException, OperationManagementException { expectedExceptions = OperationManagementException.class)
public void getOperationByDeviceAndOperationIdInvalidDevice() throws DeviceManagementException,
OperationManagementException {
this.operationMgtService.getOperationByDeviceAndOperationId(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), this.operationMgtService.getOperationByDeviceAndOperationId(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
getOperationId(this.commandActivity.getActivityId())); getOperationId(this.commandActivity.getActivityId()));
} }
@Test(dependsOnMethods = "getOperationByDeviceAndOperationIdInvalidDevice", expectedExceptions = OperationManagementException.class) @Test(dependsOnMethods = "getOperationByDeviceAndOperationIdInvalidDevice",
public void getOperationsByDeviceAndStatusInvalidDevice() throws DeviceManagementException, OperationManagementException { expectedExceptions = OperationManagementException.class)
public void getOperationsByDeviceAndStatusInvalidDevice() throws DeviceManagementException,
OperationManagementException {
this.operationMgtService.getOperationsByDeviceAndStatus(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), this.operationMgtService.getOperationsByDeviceAndStatus(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
Operation.Status.PENDING); Operation.Status.PENDING);
} }
@Test(dependsOnMethods = "getOperationsByDeviceAndStatusInvalidDevice", expectedExceptions = OperationManagementException.class) @Test(dependsOnMethods = "getOperationsByDeviceAndStatusInvalidDevice",
public void getOperationsInvalidOperationId() throws DeviceManagementException, OperationManagementException { expectedExceptions = OperationManagementException.class)
public void getOperationsInvalidOperationId() throws DeviceManagementException,
OperationManagementException {
this.operationMgtService.getOperation(123445); this.operationMgtService.getOperation(123445);
} }
@Test(dependsOnMethods = "getOperationsInvalidOperationId", expectedExceptions = IllegalArgumentException.class) @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); this.operationMgtService.getOperationByActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + 0);
} }
@Test(dependsOnMethods = "getOperationsByActivityIdInvalidActivityId", expectedExceptions = IllegalArgumentException.class) @Test(dependsOnMethods = "getOperationsByActivityIdInvalidActivityId",
public void getOperationByActivityIdAndDeviceInvalidActivityId() throws DeviceManagementException, OperationManagementException { expectedExceptions = IllegalArgumentException.class)
public void getOperationByActivityIdAndDeviceInvalidActivityId() throws DeviceManagementException,
OperationManagementException {
this.operationMgtService.getOperationByActivityIdAndDevice(DeviceManagementConstants.OperationAttributes.ACTIVITY + 0, this.operationMgtService.getOperationByActivityIdAndDevice(DeviceManagementConstants.OperationAttributes.ACTIVITY + 0,
new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE)); new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE));
} }

Loading…
Cancel
Save