Adding more testcases on operation management.

revert-70aa11f8
sinthuja 7 years ago
parent ce23e30403
commit 161d69850f

@ -128,7 +128,7 @@ public class OperationManagementTests {
public void addCommandOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void addCommandOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
this.commandActivity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE), this.commandActivity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
this.deviceIds); this.deviceIds);
validateOperationResponse(this.commandActivity); validateOperationResponse(this.commandActivity, ActivityStatus.Status.PENDING);
} }
@Test(expectedExceptions = InvalidDeviceException.class) @Test(expectedExceptions = InvalidDeviceException.class)
@ -146,25 +146,37 @@ public class OperationManagementTests {
deviceIdentifiers); deviceIdentifiers);
} }
@Test
public void addNonAdminUserDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_USER);
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
deviceIds);
PrivilegedCarbonContext.endTenantFlow();
validateOperationResponse(activity, ActivityStatus.Status.UNAUTHORIZED);
}
@Test(dependsOnMethods = "addCommandOperation") @Test(dependsOnMethods = "addCommandOperation")
public void addPolicyOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void addPolicyOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
Activity activity = this.operationMgtService.addOperation(getOperation(new PolicyOperation(), Operation.Type.POLICY, POLICY_OPERATION_CODE), Activity activity = this.operationMgtService.addOperation(getOperation(new PolicyOperation(), Operation.Type.POLICY, POLICY_OPERATION_CODE),
this.deviceIds); this.deviceIds);
validateOperationResponse(activity); validateOperationResponse(activity, ActivityStatus.Status.PENDING);
} }
@Test(dependsOnMethods = "addPolicyOperation") @Test(dependsOnMethods = "addPolicyOperation")
public void addConfigOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void addConfigOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
Activity activity = this.operationMgtService.addOperation(getOperation(new ConfigOperation(), Operation.Type.CONFIG, CONFIG_OPERATION_CODE), Activity activity = this.operationMgtService.addOperation(getOperation(new ConfigOperation(), Operation.Type.CONFIG, CONFIG_OPERATION_CODE),
this.deviceIds); this.deviceIds);
validateOperationResponse(activity); validateOperationResponse(activity, ActivityStatus.Status.PENDING);
} }
@Test(dependsOnMethods = "addConfigOperation") @Test(dependsOnMethods = "addConfigOperation")
public void addProfileOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void addProfileOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
Activity activity = this.operationMgtService.addOperation(getOperation(new ProfileOperation(), Operation.Type.PROFILE, PROFILE_OPERATION_CODE), Activity activity = this.operationMgtService.addOperation(getOperation(new ProfileOperation(), Operation.Type.PROFILE, PROFILE_OPERATION_CODE),
this.deviceIds); this.deviceIds);
validateOperationResponse(activity); validateOperationResponse(activity, ActivityStatus.Status.PENDING);
} }
private Operation getOperation(Operation operation, Operation.Type type, String code) { private Operation getOperation(Operation operation, Operation.Type type, String code) {
@ -175,11 +187,11 @@ public class OperationManagementTests {
return operation; return operation;
} }
private void validateOperationResponse(Activity activity) { private void validateOperationResponse(Activity activity, ActivityStatus.Status expectedStatus) {
Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation reponse for add operation only have - " + Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation reponse for add operation only have - " +
activity.getActivityStatus().size()); activity.getActivityStatus().size());
for (ActivityStatus status : activity.getActivityStatus()) { for (ActivityStatus status : activity.getActivityStatus()) {
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.PENDING); Assert.assertEquals(status.getStatus(), expectedStatus);
} }
} }

Loading…
Cancel
Save