|
|
@ -18,6 +18,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.mgt.core.operation;
|
|
|
|
package org.wso2.carbon.device.mgt.core.operation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.powermock.api.mockito.PowerMockito;
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
@ -34,7 +35,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
|
|
@ -62,7 +63,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String DEVICE_TYPE = "OP_TEST_TYPE";
|
|
|
|
private static final String DEVICE_TYPE = "OP_TEST_TYPE";
|
|
|
|
private static final String DEVICE_ID_PREFIX = "OP-TEST-DEVICE-ID-";
|
|
|
|
private static final String DEVICE_ID_PREFIX = "OP-TEST-DEVICE-ID-";
|
|
|
|
private static final String COMMAND_OPERATON_CODE = "COMMAND-TEST";
|
|
|
|
private static final String COMMAND_OPERATION_CODE = "COMMAND-TEST";
|
|
|
|
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";
|
|
|
@ -75,6 +76,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
|
|
|
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
|
|
|
private OperationManager operationMgtService;
|
|
|
|
private OperationManager operationMgtService;
|
|
|
|
private DeviceManagementProviderService deviceMgmtProvider;
|
|
|
|
private DeviceManagementProviderService deviceMgmtProvider;
|
|
|
|
|
|
|
|
private DeviceManagementService deviceManagementService;
|
|
|
|
private Activity commandActivity;
|
|
|
|
private Activity commandActivity;
|
|
|
|
private long commandActivityBeforeUpdatedTimestamp;
|
|
|
|
private long commandActivityBeforeUpdatedTimestamp;
|
|
|
|
|
|
|
|
|
|
|
@ -98,18 +100,25 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.deviceMgmtProvider = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
|
|
|
|
this.deviceMgmtProvider = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
|
|
|
|
NotificationStrategy notificationStrategy = new TestNotificationStrategy();
|
|
|
|
deviceManagementService = new TestDeviceManagementService(DEVICE_TYPE,
|
|
|
|
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
|
|
|
|
this.operationMgtService = PowerMockito.spy(new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
|
|
|
|
|
|
|
|
PowerMockito.when(this.operationMgtService, "getNotificationStrategy").thenReturn(new TestNotificationStrategy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
InvalidDeviceException {
|
|
|
|
InvalidDeviceException {
|
|
|
|
NotificationStrategy notificationStrategy = new TestNotificationStrategy(true);
|
|
|
|
OperationManager operationManager = PowerMockito.spy(
|
|
|
|
OperationManager operationManager = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
|
|
|
|
new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
PowerMockito.when(operationManager, "getNotificationStrategy")
|
|
|
|
|
|
|
|
.thenReturn(new TestNotificationStrategy(true));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new RuntimeException("Unable to mock getNotificationStrategy method", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
this.commandActivity = operationManager.addOperation(
|
|
|
|
this.commandActivity = operationManager.addOperation(
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATION_CODE), this.deviceIds);
|
|
|
|
this.deviceIds);
|
|
|
|
|
|
|
|
validateOperationResponse(this.commandActivity, ActivityStatus.Status.PENDING);
|
|
|
|
validateOperationResponse(this.commandActivity, ActivityStatus.Status.PENDING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -123,8 +132,8 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
invalidDevices.add(new DeviceIdentifier(INVALID_DEVICE + i, DEVICE_TYPE));
|
|
|
|
invalidDevices.add(new DeviceIdentifier(INVALID_DEVICE + i, DEVICE_TYPE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
invalidDevices.addAll(this.deviceIds);
|
|
|
|
invalidDevices.addAll(this.deviceIds);
|
|
|
|
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
|
|
|
|
Activity activity = this.operationMgtService.addOperation(
|
|
|
|
Operation.Type.COMMAND, COMMAND_OPERATON_CODE), invalidDevices);
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATION_CODE), invalidDevices);
|
|
|
|
Assert.assertEquals(activity.getActivityStatus().size(), invalidDevices.size(),
|
|
|
|
Assert.assertEquals(activity.getActivityStatus().size(), invalidDevices.size(),
|
|
|
|
"The operation response for add operation only have - " + activity.getActivityStatus().size());
|
|
|
|
"The operation response for add operation only have - " + activity.getActivityStatus().size());
|
|
|
|
for (int i = 0; i < activity.getActivityStatus().size(); i++) {
|
|
|
|
for (int i = 0; i < activity.getActivityStatus().size(); i++) {
|
|
|
@ -145,8 +154,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_OPERATON_CODE),
|
|
|
|
COMMAND_OPERATION_CODE), new ArrayList<>());
|
|
|
|
new ArrayList<>());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expectedExceptions = InvalidDeviceException.class)
|
|
|
|
@Test(expectedExceptions = InvalidDeviceException.class)
|
|
|
@ -156,18 +164,16 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
deviceIdentifiers.add(deviceIdentifier);
|
|
|
|
deviceIdentifiers.add(deviceIdentifier);
|
|
|
|
this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND,
|
|
|
|
this.operationMgtService.addOperation(
|
|
|
|
COMMAND_OPERATON_CODE),
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATION_CODE), deviceIdentifiers);
|
|
|
|
deviceIdentifiers);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void addNonAdminUserDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
public void addNonAdminUserDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
|
|
|
|
InvalidDeviceException {
|
|
|
|
InvalidDeviceException {
|
|
|
|
startTenantFlowAsNonAdmin();
|
|
|
|
startTenantFlowAsNonAdmin();
|
|
|
|
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
|
|
|
|
Activity activity = this.operationMgtService.addOperation(
|
|
|
|
Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATION_CODE), deviceIds);
|
|
|
|
deviceIds);
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
validateOperationResponse(activity, ActivityStatus.Status.UNAUTHORIZED);
|
|
|
|
validateOperationResponse(activity, ActivityStatus.Status.UNAUTHORIZED);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -525,7 +531,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_OPERATON_CODE));
|
|
|
|
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATION_CODE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = "getUpdateOperationForInvalidDevice",
|
|
|
|
@Test(dependsOnMethods = "getUpdateOperationForInvalidDevice",
|
|
|
|