Merge pull request #1181 from charithag/master

Fixed https://github.com/wso2/product-iots/issues/1671
merge-requests/1/head
Geeth 7 years ago committed by GitHub
commit ce8401361f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
@ -37,10 +39,13 @@ import java.util.List;
public class FCMNotificationStrategy implements NotificationStrategy { public class FCMNotificationStrategy implements NotificationStrategy {
private static final Log log = LogFactory.getLog(FCMNotificationStrategy.class);
private static final String NOTIFIER_TYPE_FCM = "FCM";
private static final String FCM_TOKEN = "FCM_TOKEN"; private static final String FCM_TOKEN = "FCM_TOKEN";
private static final String FCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send"; private static final String FCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send";
private static final String FCM_API_KEY = "fcmAPIKey"; private static final String FCM_API_KEY = "fcmAPIKey";
private static final int TIME_TO_LIVE = 60; private static final int TIME_TO_LIVE = 5 * 60; //Set FCM TTL to 5 minutes
private static final int HTTP_STATUS_CODE_OK = 200; private static final int HTTP_STATUS_CODE_OK = 200;
private final PushNotificationConfig config; private final PushNotificationConfig config;
@ -56,9 +61,16 @@ public class FCMNotificationStrategy implements NotificationStrategy {
@Override @Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
try { try {
Device device = if (NOTIFIER_TYPE_FCM.equals(config.getType())) {
FCMDataHolder.getInstance().getDeviceManagementProviderService().getDeviceWithTypeProperties(ctx.getDeviceId()); Device device = FCMDataHolder.getInstance().getDeviceManagementProviderService()
this.sendWakeUpCall(ctx.getOperation().getCode(), device); .getDeviceWithTypeProperties(ctx.getDeviceId());
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
} else {
if (log.isDebugEnabled()) {
log.debug("Not using FCM notifier as notifier type is set to " + config.getType() +
" in Platform Configurations.");
}
}
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e); throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e);
} catch (IOException e) { } catch (IOException e) {
@ -76,12 +88,12 @@ public class FCMNotificationStrategy implements NotificationStrategy {
} }
private void sendWakeUpCall(String message, private void sendWakeUpCall(String message, Device device) throws IOException,
Device device) throws IOException, PushNotificationExecutionFailedException { PushNotificationExecutionFailedException {
OutputStream os = null; OutputStream os = null;
byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes(); byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes();
HttpURLConnection conn = null; HttpURLConnection conn;
try { try {
conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection(); conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection();
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
@ -96,6 +108,9 @@ public class FCMNotificationStrategy implements NotificationStrategy {
} }
} }
int status = conn.getResponseCode(); int status = conn.getResponseCode();
if (log.isDebugEnabled()) {
log.debug("Result code: " + status + ", Message: " + conn.getResponseMessage());
}
if (status != HTTP_STATUS_CODE_OK) { if (status != HTTP_STATUS_CODE_OK) {
throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " + throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " +
"error code '" + status + "'"); "error code '" + status + "'");

@ -22,22 +22,20 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
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.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider; import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition; import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener; import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
@ -248,7 +246,6 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService) private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService)
throws DeviceManagementException { throws DeviceManagementException {
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true); deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
@ -261,22 +258,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId); deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
} }
operationManagerRepository.addOperationManager(deviceTypeIdentifier, new OperationManagerImpl(
if (pushNoteConfig != null) { deviceTypeIdentifier.getDeviceType(), deviceManagementService));
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
if (provider == null) {
throw new DeviceManagementException(
"No registered push notification provider found for the type: '" +
pushNoteConfig.getType() + "'.");
}
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(), notificationStrategy));
} else {
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
}
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }

@ -39,7 +39,10 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
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.NotificationContext; 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.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
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.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
@ -61,6 +64,7 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -73,6 +77,8 @@ import java.util.List;
public class OperationManagerImpl implements OperationManager { public class OperationManagerImpl implements OperationManager {
private static final Log log = LogFactory.getLog(OperationManagerImpl.class); private static final Log log = LogFactory.getLog(OperationManagerImpl.class);
private static final int CACHE_VALIDITY_PERIOD = 5 * 60 * 1000;
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
private OperationDAO commandOperationDAO; private OperationDAO commandOperationDAO;
private OperationDAO configOperationDAO; private OperationDAO configOperationDAO;
@ -84,6 +90,8 @@ public class OperationManagerImpl implements OperationManager {
private EnrollmentDAO enrollmentDAO; private EnrollmentDAO enrollmentDAO;
private NotificationStrategy notificationStrategy; private NotificationStrategy notificationStrategy;
private String deviceType; private String deviceType;
private DeviceManagementService deviceManagementService;
private long lastUpdatedTimeStamp = 0;
public OperationManagerImpl() { public OperationManagerImpl() {
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
@ -96,20 +104,32 @@ public class OperationManagerImpl implements OperationManager {
enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
} }
public OperationManagerImpl(String deviceType) { public OperationManagerImpl(String deviceType, DeviceManagementService deviceManagementService) {
this(); this();
this.deviceType = deviceType; this.deviceType = deviceType;
this.deviceManagementService = deviceManagementService;
} }
public NotificationStrategy getNotificationStrategy() { public NotificationStrategy getNotificationStrategy() {
if (Calendar.getInstance().getTimeInMillis() - lastUpdatedTimeStamp > CACHE_VALIDITY_PERIOD) {
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
if (pushNoteConfig != null && !NOTIFIER_TYPE_LOCAL.equals(pushNoteConfig.getType())) {
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
if (provider == null) {
log.error("No registered push notification provider found for the type: '" +
pushNoteConfig.getType() + "'.");
return null;
}
notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
} else {
notificationStrategy = null;
}
lastUpdatedTimeStamp = Calendar.getInstance().getTimeInMillis();
}
return notificationStrategy; return notificationStrategy;
} }
public OperationManagerImpl(String deviceType, NotificationStrategy notificationStrategy) {
this(deviceType);
this.notificationStrategy = notificationStrategy;
}
@Override @Override
public Activity addOperation(Operation operation, public Activity addOperation(Operation operation,
List<DeviceIdentifier> deviceIds) List<DeviceIdentifier> deviceIds)
@ -144,6 +164,7 @@ public class OperationManagerImpl implements OperationManager {
boolean isScheduledOperation = this.isTaskScheduledOperation(operation); boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
boolean isNotRepeated = false; boolean isNotRepeated = false;
boolean isScheduled = false; boolean isScheduled = false;
notificationStrategy = getNotificationStrategy();
// check whether device list is greater than batch size notification strategy has enable to send push // check whether device list is greater than batch size notification strategy has enable to send push
// notification using scheduler task // notification using scheduler task

@ -17,6 +17,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.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -28,7 +29,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
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.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;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
@ -39,10 +40,10 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.sql.DataSource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.sql.DataSource;
/** /**
* Negative test cases for {@link OperationManagerImpl} * Negative test cases for {@link OperationManagerImpl}
@ -83,8 +84,11 @@ public class OperationManagementNegativeDBOperationTest extends BaseDeviceManage
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!"); throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
} }
} }
NotificationStrategy notificationStrategy = new TestNotificationStrategy(); DeviceManagementService deviceManagementService
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy); = new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
this.operationMgtService = PowerMockito.spy(new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
PowerMockito.when(this.operationMgtService, "getNotificationStrategy")
.thenReturn(new TestNotificationStrategy());
this.setMockDataSource(); this.setMockDataSource();
} }

@ -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.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -30,7 +31,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
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;
@ -42,9 +43,9 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.sql.DataSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.sql.DataSource;
/** /**
* This is the testcase which covers the methods from {@link OperationManager} * This is the testcase which covers the methods from {@link OperationManager}
@ -82,8 +83,11 @@ public class OperationManagementNoDBSchemaTests extends BaseDeviceManagementTest
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!"); throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
} }
} }
NotificationStrategy notificationStrategy = new TestNotificationStrategy(); DeviceManagementService deviceManagementService
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy); = new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
this.operationMgtService = PowerMockito.spy(new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
PowerMockito.when(this.operationMgtService, "getNotificationStrategy")
.thenReturn(new TestNotificationStrategy());
} }
@Test(description = "add operation", expectedExceptions = OperationManagementException.class) @Test(description = "add operation", expectedExceptions = OperationManagementException.class)

@ -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",

@ -18,6 +18,7 @@
package org.wso2.carbon.device.mgt.core.operation; package org.wso2.carbon.device.mgt.core.operation;
import org.mockito.Mockito; import org.mockito.Mockito;
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;
@ -29,6 +30,7 @@ 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.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.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
import org.wso2.carbon.device.mgt.core.TestTaskServiceImpl; import org.wso2.carbon.device.mgt.core.TestTaskServiceImpl;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
@ -87,8 +89,11 @@ public class ScheduledTaskOperationTests extends BaseDeviceManagementTest {
} }
} }
DeviceConfigurationManager.getInstance().initConfig(CDM_CONFIG_LOCATION); DeviceConfigurationManager.getInstance().initConfig(CDM_CONFIG_LOCATION);
TestNotificationStrategy notificationStrategy = new TestNotificationStrategy(); DeviceManagementService deviceManagementService
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy); = new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
this.operationMgtService = PowerMockito.spy(new OperationManagerImpl(DEVICE_TYPE, deviceManagementService));
PowerMockito.when(this.operationMgtService, "getNotificationStrategy")
.thenReturn(new TestNotificationStrategy());
} }

@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.task;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.powermock.api.mockito.PowerMockito;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -29,23 +30,22 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
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.TestDeviceManagementService; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
import org.wso2.carbon.device.mgt.core.TestUtils; import org.wso2.carbon.device.mgt.core.TestUtils;
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl; import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.operation.TestNotificationStrategy; import org.wso2.carbon.device.mgt.core.operation.TestNotificationStrategy;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.task.impl.DeviceDetailsRetrieverTask; import org.wso2.carbon.device.mgt.core.task.impl.DeviceDetailsRetrieverTask;
import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl; import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl;
import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -84,8 +84,16 @@ public class DeviceTaskManagerTest extends BaseDeviceManagementTest {
DeviceManagementDataHolder.getInstance() DeviceManagementDataHolder.getInstance()
.setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl()); .setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
NotificationStrategy notificationStrategy = new TestNotificationStrategy(); DeviceManagementService deviceManagementService = new TestDeviceManagementService(
this.operationManager = new OperationManagerImpl(TestDataHolder.TEST_DEVICE_TYPE, notificationStrategy); TestDataHolder.TEST_DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
this.operationManager = PowerMockito.spy(
new OperationManagerImpl(TestDataHolder.TEST_DEVICE_TYPE, deviceManagementService));
try {
PowerMockito.when(this.operationManager, "getNotificationStrategy")
.thenReturn(new TestNotificationStrategy());
} catch (Exception e) {
throw new RuntimeException("Unable to mock getNotificationStrategy method", e);
}
this.deviceMgtProviderService.registerDeviceType( this.deviceMgtProviderService.registerDeviceType(
new TestDeviceManagementService(TestDataHolder.TEST_DEVICE_TYPE, TestDataHolder.SUPER_TENANT_DOMAIN)); new TestDeviceManagementService(TestDataHolder.TEST_DEVICE_TYPE, TestDataHolder.SUPER_TENANT_DOMAIN));
for (Device device : devices) { for (Device device : devices) {

@ -59,6 +59,8 @@ import java.util.Map;
public class DeviceTypeManagerService implements DeviceManagementService { public class DeviceTypeManagerService implements DeviceManagementService {
private static final Log log = LogFactory.getLog(DeviceTypeManagerService.class); private static final Log log = LogFactory.getLog(DeviceTypeManagerService.class);
private static final String NOTIFIER_PROPERTY = "notifierType";
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
private DeviceManager deviceManager; private DeviceManager deviceManager;
private PushNotificationConfig pushNotificationConfig; private PushNotificationConfig pushNotificationConfig;
@ -71,6 +73,9 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private PullNotificationSubscriber pullNotificationSubscriber; private PullNotificationSubscriber pullNotificationSubscriber;
private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig; private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig;
private GeneralConfig generalConfig; private GeneralConfig generalConfig;
private boolean isRegistryBasedConfigs = false;
private boolean isScheduled = false;
private String notifierType;
public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
DeviceTypeConfiguration deviceTypeConfiguration) { DeviceTypeConfiguration deviceTypeConfiguration) {
@ -126,6 +131,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private void populatePushNotificationConfig(PushNotificationProvider pushNotificationProvider) { private void populatePushNotificationConfig(PushNotificationProvider pushNotificationProvider) {
if (pushNotificationProvider != null) { if (pushNotificationProvider != null) {
if (pushNotificationProvider.isFileBasedProperties()) { if (pushNotificationProvider.isFileBasedProperties()) {
isRegistryBasedConfigs = false;
Map<String, String> staticProps = new HashMap<>(); Map<String, String> staticProps = new HashMap<>();
ConfigProperties configProperties = pushNotificationProvider.getConfigProperties(); ConfigProperties configProperties = pushNotificationProvider.getConfigProperties();
if (configProperties != null) { if (configProperties != null) {
@ -139,21 +145,30 @@ public class DeviceTypeManagerService implements DeviceManagementService {
pushNotificationConfig = new PushNotificationConfig(pushNotificationProvider.getType(), pushNotificationConfig = new PushNotificationConfig(pushNotificationProvider.getType(),
pushNotificationProvider.isScheduled(), staticProps); pushNotificationProvider.isScheduled(), staticProps);
} else { } else {
try { isRegistryBasedConfigs = true;
PlatformConfiguration deviceTypeConfig = deviceManager.getConfiguration(); isScheduled = pushNotificationProvider.isScheduled();
if (deviceTypeConfig != null) { notifierType = pushNotificationProvider.getType();
List<ConfigurationEntry> configuration = deviceTypeConfig.getConfiguration(); refreshPlatformConfigurations();
if (configuration.size() > 0) { }
Map<String, String> properties = this.getConfigProperty(configuration); }
pushNotificationConfig = new PushNotificationConfig( }
pushNotificationProvider.getType(), pushNotificationProvider.isScheduled(),
properties); private void refreshPlatformConfigurations() {
} try {
PlatformConfiguration deviceTypeConfig = deviceManager.getConfiguration();
if (deviceTypeConfig != null) {
List<ConfigurationEntry> configuration = deviceTypeConfig.getConfiguration();
if (!configuration.isEmpty()) {
Map<String, String> properties = this.getConfigProperty(configuration);
String notifierValue = properties.get(NOTIFIER_PROPERTY);
if (notifierValue != null && notifierValue.equals("1")) {
notifierType = NOTIFIER_TYPE_LOCAL;
} }
} catch (DeviceManagementException e) { pushNotificationConfig = new PushNotificationConfig(notifierType, isScheduled, properties);
log.error("Unable to get the " + type + " platform configuration from registry.");
} }
} }
} catch (DeviceManagementException e) {
log.error("Unable to get the " + type + " platform configuration from registry.");
} }
} }
@ -174,6 +189,9 @@ public class DeviceTypeManagerService implements DeviceManagementService {
@Override @Override
public PushNotificationConfig getPushNotificationConfig() { public PushNotificationConfig getPushNotificationConfig() {
if (isRegistryBasedConfigs) {
refreshPlatformConfigurations();
}
return pushNotificationConfig; return pushNotificationConfig;
} }

@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
@ -86,9 +87,9 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
public void addPolicy() throws DeviceManagementException, GroupManagementException, PolicyManagementException { public void addPolicy() throws DeviceManagementException, GroupManagementException, PolicyManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
policyManagerService = new PolicyManagerServiceImpl(); policyManagerService = new PolicyManagerServiceImpl();
DeviceManagementService deviceManagementService = new TypeXDeviceManagementService(DEVICE_TYPE_A);
deviceMgtService.registerDeviceType(new TypeXDeviceManagementService(DEVICE_TYPE_A)); deviceMgtService.registerDeviceType(deviceManagementService);
operationManager = new OperationManagerImpl(DEVICE_TYPE_A); operationManager = new OperationManagerImpl(DEVICE_TYPE_A, deviceManagementService);
enrollDevice(DEVICE1, DEVICE_TYPE_A); enrollDevice(DEVICE1, DEVICE_TYPE_A);
createDeviceGroup(GROUP1); createDeviceGroup(GROUP1);
DeviceGroup group1 = groupMgtService.getGroup(GROUP1); DeviceGroup group1 = groupMgtService.getGroup(GROUP1);

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
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.policy.mgt.Profile; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest; import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest;
@ -77,9 +78,9 @@ public class FeatureManagerImplTest extends BasePolicyManagementDAOTest {
super.initializeServices(); super.initializeServices();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManagementService deviceManagementService = new TypeXDeviceManagementService(DEVICE_TYPE_D);
deviceMgtService.registerDeviceType(new TypeXDeviceManagementService(DEVICE_TYPE_D)); deviceMgtService.registerDeviceType(deviceManagementService);
operationManager = new OperationManagerImpl(DEVICE_TYPE_D); operationManager = new OperationManagerImpl(DEVICE_TYPE_D, deviceManagementService);
featureManager = new FeatureManagerImpl(); featureManager = new FeatureManagerImpl();
enrollDevice(DEVICE4, DEVICE_TYPE_D); enrollDevice(DEVICE4, DEVICE_TYPE_D);

@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest; import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest;
@ -83,8 +84,9 @@ public class MonitoringManagerImplTest extends BasePolicyManagementDAOTest{
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
deviceMgtService.registerDeviceType(new TypeXDeviceManagementService(DEVICE_TYPE_E)); DeviceManagementService deviceManagementService = new TypeXDeviceManagementService(DEVICE_TYPE_E);
operationManager = new OperationManagerImpl(DEVICE_TYPE_E); deviceMgtService.registerDeviceType(deviceManagementService);
operationManager = new OperationManagerImpl(DEVICE_TYPE_E, deviceManagementService);
featureManager = new FeatureManagerImpl(); featureManager = new FeatureManagerImpl();
monitoringManager = new MonitoringManagerImpl(); monitoringManager = new MonitoringManagerImpl();
policyManager = new PolicyManagerImpl(); policyManager = new PolicyManagerImpl();

@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
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.policy.mgt.Profile; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException; import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest; import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest;
@ -71,8 +72,9 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void initialize() throws Exception { public void initialize() throws Exception {
log.info("Initializing policy manager tests"); log.info("Initializing policy manager tests");
super.initializeServices(); super.initializeServices();
deviceMgtService.registerDeviceType(new TypeXDeviceManagementService(DEVICE_TYPE_C)); DeviceManagementService deviceManagementService = new TypeXDeviceManagementService(DEVICE_TYPE_C);
operationManager = new OperationManagerImpl(DEVICE_TYPE_C); deviceMgtService.registerDeviceType(deviceManagementService);
operationManager = new OperationManagerImpl(DEVICE_TYPE_C, deviceManagementService);
enrollDevice(DEVICE3, DEVICE_TYPE_C); enrollDevice(DEVICE3, DEVICE_TYPE_C);
createDeviceGroup(GROUP3); createDeviceGroup(GROUP3);
DeviceGroup group1 = groupMgtService.getGroup(GROUP3); DeviceGroup group1 = groupMgtService.getGroup(GROUP3);

Loading…
Cancel
Save