mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding more testcases for the operation management.
This commit is contained in:
parent
e4a732dbc6
commit
dc58a388d6
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.operation.mgt;
|
||||
|
||||
public interface OperationManagementServiceProvider {
|
||||
}
|
||||
@ -26,8 +26,6 @@ public class OperationMgtConstants {
|
||||
}
|
||||
|
||||
public static final String DEVICE_ID_NOT_FOUND = "Device not found for device id: %s";
|
||||
public static final String DEVICE_ID_SERVICE_NOT_FOUND =
|
||||
"Issue in retrieving device management service instance for device found at %s";
|
||||
}
|
||||
|
||||
public final class OperationCodes {
|
||||
|
||||
@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.push.notification.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
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.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PushNotificationBasedOperationManager implements OperationManager {
|
||||
|
||||
private OperationManager operationManager;
|
||||
private NotificationStrategy notificationProvider;
|
||||
|
||||
public PushNotificationBasedOperationManager(
|
||||
OperationManager operationManager, NotificationStrategy notificationProvider) {
|
||||
this.operationManager = operationManager;
|
||||
this.notificationProvider = notificationProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity addOperation(Operation operation,
|
||||
List<DeviceIdentifier> devices) throws OperationManagementException, InvalidDeviceException {
|
||||
Activity activity = this.operationManager.addOperation(operation, devices);
|
||||
for (DeviceIdentifier deviceId : devices) {
|
||||
try {
|
||||
this.notificationProvider.execute(new NotificationContext(deviceId, operation));
|
||||
} catch (PushNotificationExecutionFailedException e) {
|
||||
throw new OperationManagementException("Error occurred while sending push notification to device", e);
|
||||
}
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperations(
|
||||
DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult getOperations(DeviceIdentifier deviceId,
|
||||
PaginationRequest request) throws OperationManagementException {
|
||||
return this.operationManager.getOperations(deviceId, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getPendingOperations(
|
||||
DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getPendingOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getNextPendingOperation(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOperation(DeviceIdentifier deviceId,
|
||||
Operation operation) throws OperationManagementException {
|
||||
this.operationManager.updateOperation(deviceId, operation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperationByDeviceAndOperationId(
|
||||
DeviceIdentifier deviceId, int operationId) throws OperationManagementException {
|
||||
return this.operationManager.getOperationByDeviceAndOperationId(deviceId, operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(
|
||||
DeviceIdentifier deviceId,
|
||||
Operation.Status status) throws OperationManagementException {
|
||||
try {
|
||||
return this.operationManager.getOperationsByDeviceAndStatus(deviceId, status);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while retrieving the list of operations by " +
|
||||
"device and status", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int operationId) throws OperationManagementException {
|
||||
return this.operationManager.getOperation(operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getOperationByActivityId(String activity) throws OperationManagementException {
|
||||
return this.operationManager.getOperationByActivityId(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getOperationByActivityIdAndDevice(String activity, DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getOperationByActivityIdAndDevice(activity, deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException {
|
||||
return this.operationManager.getActivitiesUpdatedAfter(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException {
|
||||
return this.operationManager.getActivitiesUpdatedAfter(timestamp, limit, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException {
|
||||
return this.operationManager.getActivityCountUpdatedAfter(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotificationStrategy getNotificationStrategy() {
|
||||
return notificationProvider;
|
||||
}
|
||||
|
||||
}
|
||||
@ -18,8 +18,6 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.operation;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
@ -66,8 +64,10 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* This is the testcase which covers the methods from {@link OperationManager}
|
||||
*/
|
||||
public class OperationManagementTests {
|
||||
private static final Log log = LogFactory.getLog(OperationManagementTests.class);
|
||||
|
||||
private static final String DEVICE_TYPE = "OP_TEST_TYPE";
|
||||
private static final String DEVICE_ID_PREFIX = "OP-TEST-DEVICE-ID-";
|
||||
@ -87,7 +87,6 @@ public class OperationManagementTests {
|
||||
@BeforeClass
|
||||
public void init() throws Exception {
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
log.info("Initializing");
|
||||
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
||||
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||
}
|
||||
@ -222,6 +221,11 @@ public class OperationManagementTests {
|
||||
|
||||
@Test(dependsOnMethods = "getPaginatedRequestAsAdmin")
|
||||
public void updateOperation() 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);
|
||||
List operations = this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||
Assert.assertTrue(operations != null && operations.size() == 4);
|
||||
@ -286,15 +290,51 @@ public class OperationManagementTests {
|
||||
Assert.assertEquals(activity.getActivityStatus().get(0).getStatus(), ActivityStatus.Status.COMPLETED);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateOperation", enabled = false)
|
||||
@Test(dependsOnMethods = "updateOperation")
|
||||
public void getOperationUpdatedAfterWithLimitAndOffet() throws OperationManagementException, ParseException {
|
||||
String timestamp = this.commandActivity.getCreatedTimeStamp();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd hh:mm:ss Z yyyy");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
|
||||
Date date = dateFormat.parse(timestamp);
|
||||
List<Activity> operations = this.operationMgtService.getActivitiesUpdatedAfter(date.getTime() / 1000, 10, 0);
|
||||
Assert.assertTrue(operations != null && operations.size() == 1,
|
||||
"The operations updated after the created should be 1");
|
||||
Activity operation = operations.get(0);
|
||||
Assert.assertTrue(operation.getActivityStatus() != null && operation.getActivityStatus().size() == 1,
|
||||
"The operation should be having the activity status of atleast one device");
|
||||
Assert.assertEquals(operation.getActivityStatus().get(0).getDeviceIdentifier().getId(),
|
||||
deviceIds.get(0).getId());
|
||||
Assert.assertEquals(operation.getActivityStatus().get(0).getDeviceIdentifier().getType(),
|
||||
deviceIds.get(0).getType());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateOperation")
|
||||
public void getOperationUpdatedAfter() throws OperationManagementException, ParseException {
|
||||
String timestamp = this.commandActivity.getCreatedTimeStamp();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd hh:mm:ss Z yyyy");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
|
||||
Date date = dateFormat.parse(timestamp);
|
||||
List operations = this.operationMgtService.getActivitiesUpdatedAfter(date.getTime());
|
||||
List<Activity> operations = this.operationMgtService.getActivitiesUpdatedAfter(date.getTime() / 1000);
|
||||
Assert.assertTrue(operations != null && operations.size() == 1,
|
||||
"The operations updated after the created should be 1");
|
||||
Activity operation = operations.get(0);
|
||||
Assert.assertTrue(operation.getActivityStatus() != null && operation.getActivityStatus().size() == 1,
|
||||
"The operation should be having the activity status of atleast one device");
|
||||
Assert.assertEquals(operation.getActivityStatus().get(0).getDeviceIdentifier().getId(),
|
||||
deviceIds.get(0).getId());
|
||||
Assert.assertEquals(operation.getActivityStatus().get(0).getDeviceIdentifier().getType(),
|
||||
deviceIds.get(0).getType());
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = "getOperationUpdatedAfter")
|
||||
public void getActivityCountUpdatedAfter() throws OperationManagementException, ParseException {
|
||||
String timestamp = this.commandActivity.getCreatedTimeStamp();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd hh:mm:ss Z yyyy");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
|
||||
Date date = dateFormat.parse(timestamp);
|
||||
int activityCount = this.operationMgtService.getActivityCountUpdatedAfter(date.getTime() / 1000);
|
||||
Assert.assertTrue(activityCount == 1,
|
||||
"The activities updated after the created should be 1");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user