|
|
@ -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) {
|
|
|
@ -357,14 +362,16 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
@Test(dependsOnMethods = "getNextPendingOperation")
|
|
|
|
@Test(dependsOnMethods = "getNextPendingOperation")
|
|
|
|
public void getOperationByDeviceAndOperationId() throws OperationManagementException {
|
|
|
|
public void getOperationByDeviceAndOperationId() throws OperationManagementException {
|
|
|
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
|
|
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
|
|
|
String operationId = this.commandActivity.getActivityId().
|
|
|
|
|
|
|
|
replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "");
|
|
|
|
|
|
|
|
Operation operation = this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier,
|
|
|
|
Operation operation = this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier,
|
|
|
|
Integer.parseInt(operationId));
|
|
|
|
getOperationId(this.commandActivity.getActivityId()));
|
|
|
|
Assert.assertTrue(operation.getStatus().equals(Operation.Status.COMPLETED));
|
|
|
|
Assert.assertTrue(operation.getStatus().equals(Operation.Status.COMPLETED));
|
|
|
|
Assert.assertTrue(operation.getType().equals(Operation.Type.COMMAND));
|
|
|
|
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)
|
|
|
|
@Test(dependsOnMethods = "getNextPendingOperation", expectedExceptions = OperationManagementException.class)
|
|
|
|
public void getOperationByDeviceAndOperationIdNonAdmin() throws OperationManagementException {
|
|
|
|
public void getOperationByDeviceAndOperationIdNonAdmin() throws OperationManagementException {
|
|
|
|
startTenantFlowAsNonAdmin();
|
|
|
|
startTenantFlowAsNonAdmin();
|
|
|
@ -382,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);
|
|
|
@ -474,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);
|
|
|
@ -482,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);
|
|
|
@ -492,13 +503,60 @@ 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)
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|