|
|
@ -18,6 +18,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.mgt.core.operation;
|
|
|
|
package org.wso2.carbon.device.mgt.core.operation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.powermock.api.mockito.PowerMockito;
|
|
|
|
import org.powermock.api.mockito.PowerMockito;
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
@ -67,6 +69,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
private static final String POLICY_OPERATION_CODE = "POLICY-TEST";
|
|
|
|
private static final String POLICY_OPERATION_CODE = "POLICY-TEST";
|
|
|
|
private static final String CONFIG_OPERATION_CODE = "CONFIG-TEST";
|
|
|
|
private static final String CONFIG_OPERATION_CODE = "CONFIG-TEST";
|
|
|
|
private static final String PROFILE_OPERATION_CODE = "PROFILE-TEST";
|
|
|
|
private static final String PROFILE_OPERATION_CODE = "PROFILE-TEST";
|
|
|
|
|
|
|
|
private static final String PROFILE_NOTIFICATION_CODE = "NOTIFICATION";
|
|
|
|
private static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
private static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
private static final int NO_OF_DEVICES = 5;
|
|
|
|
private static final int NO_OF_DEVICES = 5;
|
|
|
|
private static final String ADMIN_USER = "admin";
|
|
|
|
private static final String ADMIN_USER = "admin";
|
|
|
@ -80,6 +83,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
private Activity commandActivity;
|
|
|
|
private Activity commandActivity;
|
|
|
|
private long commandActivityBeforeUpdatedTimestamp;
|
|
|
|
private long commandActivityBeforeUpdatedTimestamp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(OperationManagementTests.class);
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
@BeforeClass
|
|
|
|
public void init() throws Exception {
|
|
|
|
public void init() throws Exception {
|
|
|
|
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
|
|
|
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
|
|
@ -101,14 +106,14 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.deviceMgmtProvider = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
|
|
|
|
this.deviceMgmtProvider = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
|
|
|
|
deviceManagementService = new TestDeviceManagementService(DEVICE_TYPE,
|
|
|
|
deviceManagementService = new TestDeviceManagementService(DEVICE_TYPE,
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
this.operationMgtService = PowerMockito.spy(new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
|
|
|
|
this.operationMgtService = PowerMockito.spy(new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
|
|
|
|
PowerMockito.when(this.operationMgtService, "getNotificationStrategy").thenReturn(new TestNotificationStrategy());
|
|
|
|
PowerMockito.when(this.operationMgtService, "getNotificationStrategy").thenReturn(new TestNotificationStrategy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
InvalidDeviceException {
|
|
|
|
InvalidDeviceException {
|
|
|
|
OperationManager operationManager = PowerMockito.spy(
|
|
|
|
OperationManager operationManager = PowerMockito.spy(
|
|
|
|
new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
|
|
|
|
new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -154,7 +159,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
public void addEmptyDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
public void addEmptyDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
InvalidDeviceException {
|
|
|
|
InvalidDeviceException {
|
|
|
|
this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND,
|
|
|
|
this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND,
|
|
|
|
COMMAND_OPERATION_CODE), new ArrayList<>());
|
|
|
|
COMMAND_OPERATION_CODE), new ArrayList<>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expectedExceptions = InvalidDeviceException.class)
|
|
|
|
@Test(expectedExceptions = InvalidDeviceException.class)
|
|
|
@ -205,8 +210,10 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
@Test(dependsOnMethods = "addConfigOperation")
|
|
|
|
@Test(dependsOnMethods = "addConfigOperation")
|
|
|
|
public void addProfileOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
public void addProfileOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
InvalidDeviceException {
|
|
|
|
InvalidDeviceException {
|
|
|
|
Activity activity = this.operationMgtService.addOperation(getOperation(new ProfileOperation(),
|
|
|
|
Operation opp = getOperation(new ProfileOperation(),
|
|
|
|
Operation.Type.PROFILE, PROFILE_OPERATION_CODE),
|
|
|
|
Operation.Type.PROFILE, PROFILE_NOTIFICATION_CODE);
|
|
|
|
|
|
|
|
opp.setPayLoad("{\"messageText\":\"xyz\",\"messageTitle\":\"abc\"}");
|
|
|
|
|
|
|
|
Activity activity = this.operationMgtService.addOperation(opp ,
|
|
|
|
this.deviceIds);
|
|
|
|
this.deviceIds);
|
|
|
|
validateOperationResponse(activity, ActivityStatus.Status.PENDING);
|
|
|
|
validateOperationResponse(activity, ActivityStatus.Status.PENDING);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -360,6 +367,35 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
Assert.assertTrue(operation.getType().equals(Operation.Type.POLICY));
|
|
|
|
Assert.assertTrue(operation.getType().equals(Operation.Type.POLICY));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = "getNextPendingOperation")
|
|
|
|
|
|
|
|
public void getNextNotNowOperation() throws OperationManagementException {
|
|
|
|
|
|
|
|
//This is required to introduce a delay for the update operation of the device.
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(2000);
|
|
|
|
|
|
|
|
} catch (InterruptedException ignored) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
|
|
|
|
|
|
|
Operation operation = this.operationMgtService.getNextPendingOperation(deviceIdentifier);
|
|
|
|
|
|
|
|
int operationId = operation.getId();
|
|
|
|
|
|
|
|
operation.setStatus(Operation.Status.NOTNOW);
|
|
|
|
|
|
|
|
operation.setOperationResponse("The operation is successfully completed");
|
|
|
|
|
|
|
|
this.operationMgtService.updateOperation(deviceIdentifier, operation);
|
|
|
|
|
|
|
|
//This is required to introduce a delay for the update operation of the device.
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(2000);
|
|
|
|
|
|
|
|
} catch (InterruptedException ignored) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
operation = this.operationMgtService.getNextPendingOperation(deviceIdentifier);
|
|
|
|
|
|
|
|
Assert.assertTrue(operation.getId() != operationId, "Fetched the incorrect operation");
|
|
|
|
|
|
|
|
log.info("Waiting 10000ms for NotNow operation to be fetched");
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(10000);
|
|
|
|
|
|
|
|
} catch (InterruptedException ignored) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
operation = this.operationMgtService.getNextPendingOperation(deviceIdentifier, 7000);
|
|
|
|
|
|
|
|
Assert.assertTrue(operation.getId() == operationId, "Fetched the incorrect NotNow operation");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = "updateOperation", expectedExceptions = OperationManagementException.class)
|
|
|
|
@Test(dependsOnMethods = "updateOperation", expectedExceptions = OperationManagementException.class)
|
|
|
|
public void getNextPendingOperationAsNonAdmin() throws OperationManagementException {
|
|
|
|
public void getNextPendingOperationAsNonAdmin() throws OperationManagementException {
|
|
|
|
startTenantFlowAsNonAdmin();
|
|
|
|
startTenantFlowAsNonAdmin();
|
|
|
@ -403,7 +439,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
|
|
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
|
|
|
List operation = this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier,
|
|
|
|
List operation = this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier,
|
|
|
|
Operation.Status.PENDING);
|
|
|
|
Operation.Status.PENDING);
|
|
|
|
Assert.assertEquals(operation.size(), 3);
|
|
|
|
Assert.assertEquals(operation.size(), 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = "getOperationByDeviceAndOperationId", expectedExceptions = OperationManagementException.class)
|
|
|
|
@Test(dependsOnMethods = "getOperationByDeviceAndOperationId", expectedExceptions = OperationManagementException.class)
|
|
|
@ -476,8 +512,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
public void getActivityCountUpdatedAfter() throws OperationManagementException, ParseException {
|
|
|
|
public void getActivityCountUpdatedAfter() throws OperationManagementException, ParseException {
|
|
|
|
int activityCount = this.operationMgtService.getActivityCountUpdatedAfter
|
|
|
|
int activityCount = this.operationMgtService.getActivityCountUpdatedAfter
|
|
|
|
(this.commandActivityBeforeUpdatedTimestamp / 1000);
|
|
|
|
(this.commandActivityBeforeUpdatedTimestamp / 1000);
|
|
|
|
Assert.assertTrue(activityCount == 1,
|
|
|
|
Assert.assertTrue(activityCount == 2,
|
|
|
|
"The activities updated after the created should be 1");
|
|
|
|
"The activities updated after the created should be 2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -531,7 +567,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
expectedExceptions = OperationManagementException.class)
|
|
|
|
expectedExceptions = OperationManagementException.class)
|
|
|
|
public void getUpdateOperationForInvalidDevice() throws DeviceManagementException, OperationManagementException {
|
|
|
|
public void getUpdateOperationForInvalidDevice() throws DeviceManagementException, OperationManagementException {
|
|
|
|
this.operationMgtService.updateOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
|
|
|
|
this.operationMgtService.updateOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATION_CODE));
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATION_CODE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = "getUpdateOperationForInvalidDevice",
|
|
|
|
@Test(dependsOnMethods = "getUpdateOperationForInvalidDevice",
|
|
|
|