diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml
index d5c2766a43..c75fb70d2c 100644
--- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml
+++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml
@@ -22,13 +22,13 @@
apimgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.annotations
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - API Management Annotations
WSO2 Carbon - API Management Custom Annotation Module
diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml
index 051ac32205..8522b19e36 100644
--- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml
+++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml
@@ -21,12 +21,12 @@
apimgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
org.wso2.carbon.apimgt.application.extension.api
war
WSO2 Carbon - API Application Management API
diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml
index 5f3e19d568..dabdd90c68 100644
--- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml
+++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml
@@ -22,12 +22,12 @@
apimgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
org.wso2.carbon.apimgt.application.extension
bundle
WSO2 Carbon - API Application Management
diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml
index e3e7eef722..71573df31e 100644
--- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml
+++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml
@@ -21,13 +21,13 @@
apimgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.handlers
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - API Security Handler Component
WSO2 Carbon - API Management Security Handler Module
diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml
index 6749f7ff0e..16853fb499 100644
--- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml
+++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml
@@ -13,13 +13,13 @@
apimgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.integration.client
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - API Management Integration Client
WSO2 Carbon - API Management Integration Client
diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml
index ef3584f53a..1d16ce0e6f 100644
--- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml
+++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml
@@ -13,13 +13,13 @@
apimgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.integration.generated.client
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - API Management Integration Generated Client
WSO2 Carbon - API Management Integration Client
diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml
index b21008f191..f62b0531fa 100644
--- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml
+++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml
@@ -22,13 +22,13 @@
apimgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.webapp.publisher
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - API Management Webapp Publisher
WSO2 Carbon - API Management Webapp Publisher
diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml
index 6d26a0450e..c200196a7e 100644
--- a/components/apimgt-extensions/pom.xml
+++ b/components/apimgt-extensions/pom.xml
@@ -22,13 +22,13 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
apimgt-extensions
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - API Management Extensions Component
http://wso2.org
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml
index f25b0669d5..1ede515b3d 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml
@@ -22,7 +22,7 @@
certificate-mgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml
index a4f4e15a56..5f7c50502e 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml
@@ -22,7 +22,7 @@
certificate-mgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml
index 33ef9a193b..ada4fe362d 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml
@@ -21,13 +21,13 @@
org.wso2.carbon.devicemgt
certificate-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.certificate.mgt.core
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - Certificate Management Core
WSO2 Carbon - Certificate Management Core
diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml
index 28792d3b75..0028490274 100644
--- a/components/certificate-mgt/pom.xml
+++ b/components/certificate-mgt/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
certificate-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Certificate Management Component
http://wso2.org
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml
index 68ceec0503..d3559bb643 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml
index 911ccdbb22..a5c0e5cb8c 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
index 33bbb6e9d1..30cb89eb3a 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
index ae334ca5b2..16b18feba0 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
index c7aa8f7e20..c2d0eb0f3f 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
index 23d2d23bd8..b7f5907d14 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml
index 1c82894448..9b7815013b 100644
--- a/components/device-mgt-extensions/pom.xml
+++ b/components/device-mgt-extensions/pom.xml
@@ -22,7 +22,7 @@
carbon-devicemgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
index 1ba5791914..ec5684b5ec 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
@@ -3,7 +3,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
index a6cc75e8bd..7ff4f72267 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
index e1a252787f..3961bb8aaa 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
@@ -22,7 +22,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java
index 2b39044d17..a6751024e0 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java
@@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
+import org.wso2.carbon.user.api.UserStoreException;
import javax.validation.constraints.Size;
import javax.ws.rs.*;
@@ -54,22 +55,27 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
Activity activity;
DeviceManagementProviderService dmService;
- try {
- RequestValidationUtil.validateActivityId(id);
-
- dmService = DeviceMgtAPIUtils.getDeviceManagementService();
- activity = dmService.getOperationByActivityId(id);
- if (activity == null) {
- return Response.status(404).entity(
- new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " +
- "found upon the provided activity id '" + id + "'").build()).build();
+ Response response = validateAdminUser();
+ if (response == null) {
+ try {
+ RequestValidationUtil.validateActivityId(id);
+
+ dmService = DeviceMgtAPIUtils.getDeviceManagementService();
+ activity = dmService.getOperationByActivityId(id);
+ if (activity == null) {
+ return Response.status(404).entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " +
+ "found upon the provided activity id '" + id + "'").build()).build();
+ }
+ return Response.status(Response.Status.OK).entity(activity).build();
+ } catch (OperationManagementException e) {
+ String msg = "ErrorResponse occurred while fetching the activity for the supplied id.";
+ log.error(msg, e);
+ return Response.serverError().entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
- return Response.status(Response.Status.OK).entity(activity).build();
- } catch (OperationManagementException e) {
- String msg = "ErrorResponse occurred while fetching the activity for the supplied id.";
- log.error(msg, e);
- return Response.serverError().entity(
- new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
+ } else {
+ return response;
}
}
@@ -120,7 +126,6 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
long sinceTimestamp;
long timestamp = 0;
boolean isIfModifiedSinceSet = false;
- boolean isSinceSet = false;
if (log.isDebugEnabled()) {
log.debug("getActivities since: " + since + " , offset: " + offset + " ,limit: " + limit + " ," +
"ifModifiedSince: " + ifModifiedSince);
@@ -150,7 +155,6 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
"Invalid date string is provided in 'since' filter").build()).build();
}
sinceTimestamp = sinceDate.getTime();
- isSinceSet = true;
timestamp = sinceTimestamp / 1000;
}
@@ -162,38 +166,57 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (log.isDebugEnabled()) {
log.debug("getActivities final timestamp " + timestamp);
}
+ Response response = validateAdminUser();
+ if (response == null) {
+ List activities;
+ ActivityList activityList = new ActivityList();
+ DeviceManagementProviderService dmService;
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Calling database to get activities.");
+ }
+ dmService = DeviceMgtAPIUtils.getDeviceManagementService();
+ activities = dmService.getActivitiesUpdatedAfter(timestamp, limit, offset);
+ activityList.setList(activities);
+ if (log.isDebugEnabled()) {
+ log.debug("Calling database to get activity count.");
+ }
+ int count = dmService.getActivityCountUpdatedAfter(timestamp);
+ if (log.isDebugEnabled()) {
+ log.debug("Activity count: " + count);
+ }
+ activityList.setCount(count);
+ if (activities == null || activities.size() == 0) {
+ if (isIfModifiedSinceSet) {
+ return Response.notModified().build();
+ }
+ }
+ return Response.ok().entity(activityList).build();
+ } catch (OperationManagementException e) {
+ String msg
+ = "ErrorResponse occurred while fetching the activities updated after given time stamp.";
+ log.error(msg, e);
+ return Response.serverError().entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
+ }
+ } else {
+ return response;
+ }
+ }
- List activities;
- ActivityList activityList = new ActivityList();
- DeviceManagementProviderService dmService;
+ private Response validateAdminUser(){
try {
- if (log.isDebugEnabled()) {
- log.debug("Calling database to get activities.");
- }
- dmService = DeviceMgtAPIUtils.getDeviceManagementService();
- activities = dmService.getActivitiesUpdatedAfter(timestamp, limit, offset);
- activityList.setList(activities);
- if (log.isDebugEnabled()) {
- log.debug("Calling database to get activity count.");
- }
- int count = dmService.getActivityCountUpdatedAfter(timestamp);
- if (log.isDebugEnabled()) {
- log.debug("Activity count: " + count);
+ if (!DeviceMgtAPIUtils.isAdmin()) {
+ return Response.status(Response.Status.UNAUTHORIZED).entity("Unauthorized operation! Only admin role can perform " +
+ "this operation.").build();
}
- activityList.setCount(count);
- if (activities == null || activities.size() == 0) {
- if (isIfModifiedSinceSet) {
- return Response.notModified().build();
- }
- }
- return Response.ok().entity(activityList).build();
- } catch (OperationManagementException e) {
+ return null;
+ } catch (UserStoreException e) {
String msg
- = "ErrorResponse occurred while fetching the activities updated after given time stamp.";
+ = "Error occurred while validating the user have admin role!";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
-
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
index 7ff6953a1d..d719e90e00 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
@@ -702,4 +702,18 @@ public class DeviceMgtAPIUtils {
SSLContext.setDefault(sslContext);
}
+
+ public static boolean isAdmin() throws UserStoreException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
+ UserRealm realmService = DeviceMgtAPIUtils.getRealmService().getTenantUserRealm(tenantId);
+ String adminRoleName = realmService.getRealmConfiguration().getAdminRoleName();
+ String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
+ String[] roles = realmService.getUserStoreManager().getRoleListOfUser(userName);
+ for (String role: roles){
+ if (role != null && role.equals(adminRoleName)){
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml
index 44aea9f224..d553723077 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml
@@ -21,7 +21,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java
index 8de9f3199e..72fe612f0e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java
@@ -63,7 +63,8 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
* operation list.
*/
- PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request) throws OperationManagementException;
+ PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request)
+ throws OperationManagementException;
/**
* Method to retrieve the list of available operations to a device.
@@ -73,15 +74,12 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
* operation list.
*/
- List extends Operation> getPendingOperations(
- DeviceIdentifier deviceId) throws OperationManagementException;
+ List extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException;
Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException;
void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException;
- void deleteOperation(int operationId) throws OperationManagementException;
-
Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
throws OperationManagementException;
@@ -93,22 +91,13 @@ public interface OperationManager {
Activity getOperationByActivityId(String activity) throws OperationManagementException;
- Activity getOperationByActivityIdAndDevice(String activity, DeviceIdentifier deviceId) throws OperationManagementException;
-
- List getOperationUpdatedAfter(long timestamp) throws OperationManagementException;
-
- List getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException;
+ Activity getOperationByActivityIdAndDevice(String activity, DeviceIdentifier deviceId)
+ throws OperationManagementException;
List getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException;
int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException;
- /**
- * Operation manger implementation can have a push notification stratergy
- * @param notificationStrategy eg: mqtt/xmpp
- */
- void setNotificationStrategy(NotificationStrategy notificationStrategy);
-
/**
* retrive the push notification strategy.
* @return NotificationStrategy
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
index 60dd1b2acc..f5f07e1b32 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
@@ -163,6 +163,11 @@
org.wso2.carbon.devicemgt
org.wso2.carbon.device.mgt.common
+
+ org.powermock
+ powermock-api-mockito
+ test
+
org.wso2.carbon.devicemgt
org.wso2.carbon.device.mgt.analytics.data.publisher
@@ -221,6 +226,14 @@
org.testng
testng
+
+ org.powermock
+ powermock-module-testng
+
+
+ org.powermock
+ powermock-api-mockito
+
org.wso2.carbon
org.wso2.carbon.user.core
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java
index 51b6b63f2e..47b6caa11f 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java
@@ -57,9 +57,9 @@ public class DeviceConfigurationManager {
return deviceConfigManager;
}
- public synchronized void initConfig() throws DeviceManagementException {
+ public synchronized void initConfig(String configLocation) throws DeviceManagementException {
try {
- File deviceMgtConfig = new File(DeviceConfigurationManager.DEVICE_MGT_CONFIG_PATH);
+ File deviceMgtConfig = new File(configLocation);
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
/* Un-marshaling Device Management configuration */
@@ -72,15 +72,8 @@ public class DeviceConfigurationManager {
}
}
- private static Schema getSchema() throws DeviceManagementException {
- try {
- File deviceManagementSchemaConfig = new File(DeviceConfigurationManager.DEVICE_MGT_CONFIG_SCHEMA_PATH);
- SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- return factory.newSchema(deviceManagementSchemaConfig);
- } catch (SAXException e) {
- throw new DeviceManagementException("Error occurred while initializing the schema of " +
- "device-mgt-config.xml", e);
- }
+ public void initConfig() throws DeviceManagementException {
+ this.initConfig(DEVICE_MGT_CONFIG_PATH);
}
public DeviceManagementConfig getDeviceManagementConfig() {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java
index 90867dbc3d..09e1eca4f9 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java
@@ -50,11 +50,9 @@ public class NotificationManagementServiceImpl implements NotificationManagement
private static final Log log = LogFactory.getLog(NotificationManagementServiceImpl.class);
private NotificationDAO notificationDAO;
- private DeviceDAO deviceDAO;
public NotificationManagementServiceImpl() {
this.notificationDAO = NotificationManagementDAOFactory.getNotificationDAO();
- this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
}
@Override
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java
index bf80177509..9ae0a693f4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java
@@ -279,4 +279,4 @@ public abstract class AbstractNotificationDAOImpl implements NotificationDAO {
}
return notificationCountByStatus;
}
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementServiceProvider.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementServiceProvider.java
deleted file mode 100644
index 844abe6801..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementServiceProvider.java
+++ /dev/null
@@ -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 {
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
index c22f3de950..ccb69a1e0b 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
@@ -105,10 +105,6 @@ public class OperationManagerImpl implements OperationManager {
return notificationStrategy;
}
- public void setNotificationStrategy(NotificationStrategy notificationStrategy) {
- this.notificationStrategy = notificationStrategy;
- }
-
public OperationManagerImpl(String deviceType, NotificationStrategy notificationStrategy) {
this(deviceType);
this.notificationStrategy = notificationStrategy;
@@ -122,7 +118,7 @@ public class OperationManagerImpl implements OperationManager {
log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : deviceIds) {
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" +
- deviceIdentifier.getType() + "]");
+ deviceIdentifier.getType() + "]");
}
}
try {
@@ -137,7 +133,7 @@ public class OperationManagerImpl implements OperationManager {
//Send the operation statuses only for admin triggered operations
String deviceType = validDeviceIds.get(0).getType();
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult,
- deviceType));
+ deviceType));
return activity;
}
@@ -145,7 +141,7 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
- boolean isScheduledOperation = this.isTaskScheduledOperation(operation, deviceIds);
+ boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
boolean isNotRepeated = false;
boolean isScheduled = false;
@@ -160,7 +156,7 @@ public class OperationManagerImpl implements OperationManager {
boolean hasExistingTaskOperation;
int enrolmentId;
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT == operationDto.
- getControl()) {
+ getControl()) {
isNotRepeated = true;
}
@@ -177,10 +173,10 @@ public class OperationManagerImpl implements OperationManager {
}
} else if (isNotRepeated) {
operationDAO.updateEnrollmentOperationsStatus(enrolmentId, operationCode,
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.
- Operation.Status.PENDING,
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.
- Operation.Status.REPEATED);
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.
+ Operation.Status.PENDING,
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.
+ Operation.Status.REPEATED);
operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled);
} else {
operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled);
@@ -200,8 +196,8 @@ public class OperationManagerImpl implements OperationManager {
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED);
} catch (PushNotificationExecutionFailedException e) {
log.error("Error occurred while sending push notifications to " +
- deviceId.getType() + " device carrying id '" +
- deviceId + "'", e);
+ deviceId.getType() + " device carrying id '" +
+ deviceId + "'", e);
// Reschedule if push notification failed.
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
}
@@ -219,7 +215,7 @@ public class OperationManagerImpl implements OperationManager {
//Get the device-type from 1st valid DeviceIdentifier. We know the 1st element is definitely there.
String deviceType = validDeviceIds.get(0).getType();
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult,
- deviceType));
+ deviceType));
}
return activity;
} else {
@@ -242,7 +238,7 @@ public class OperationManagerImpl implements OperationManager {
//Add the invalid DeviceIds
for (String id : deviceIdValidationResult.getErrorDeviceIdList()) {
activityStatus = new ActivityStatus();
- activityStatus.setDeviceIdentifier(new DeviceIdentifier(id,deviceType));
+ activityStatus.setDeviceIdentifier(new DeviceIdentifier(id, deviceType));
activityStatus.setStatus(ActivityStatus.Status.INVALID);
activityStatuses.add(activityStatus);
}
@@ -288,7 +284,7 @@ public class OperationManagerImpl implements OperationManager {
}
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
- this.getUser(), e);
+ this.getUser(), e);
}
deviceIDHolder.setValidDeviceIDList(authorizedDeviceList);
deviceIDHolder.setErrorDeviceIdList(unAuthorizedDeviceList);
@@ -310,8 +306,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
- deviceId.getType() + "' device, which carries the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "'");
}
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
@@ -331,8 +327,8 @@ public class OperationManagerImpl implements OperationManager {
}
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -348,18 +344,22 @@ public class OperationManagerImpl implements OperationManager {
PaginationResult paginationResult = null;
List operations = new ArrayList<>();
String owner = request.getOwner();
+ try {
+ if (!DeviceManagerUtil.isDeviceExists(deviceId)) {
+ throw new OperationManagementException("Device not found for given device " +
+ "Identifier:" + deviceId.getId() + " and given type : " +
+ deviceId.getType());
+ }
+ } catch (DeviceManagementException e) {
+ throw new OperationManagementException("Error while checking the existence of the device identifier - "
+ + deviceId.getId() + " of the device type - " + deviceId.getType(), e);
+ }
if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
- deviceId.getType() + "' device, which carries the identifier '" +
- deviceId.getId() + "' of owner '" + owner + "'" );
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "' of owner '" + owner + "'");
}
-
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId, owner);
- if (enrolmentInfo == null) {
- throw new OperationManagementException("Device not found for given device " +
- "Identifier:" + deviceId.getId() + " and given type" +
- deviceId.getType());
- }
int enrolmentId = enrolmentInfo.getId();
try {
OperationManagementDAOFactory.openConnection();
@@ -376,8 +376,8 @@ public class OperationManagerImpl implements OperationManager {
paginationResult.setRecordsFiltered(count);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -390,7 +390,7 @@ public class OperationManagerImpl implements OperationManager {
@Override
public List extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws
- OperationManagementException {
+ OperationManagementException {
if (log.isDebugEnabled()) {
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
}
@@ -399,16 +399,16 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
- deviceId.getType() + "' device, which carries the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "'");
}
//
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for the given device Identifier:" +
- deviceId.getId() + " and given type:" +
- deviceId.getType());
+ deviceId.getId() + " and given type:" +
+ deviceId.getType());
}
int enrolmentId = enrolmentInfo.getId();
//Changing the enrollment status & attempt count if the device is marked as inactive or unreachable
@@ -437,8 +437,8 @@ public class OperationManagerImpl implements OperationManager {
Collections.sort(operations, new OperationCreateTimeComparator());
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "pending operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "pending operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -457,15 +457,15 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
- deviceId.getType() + "' device, which carries the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "'");
}
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for given device " +
- "Identifier:" + deviceId.getId() + " and given type" +
- deviceId.getType());
+ "Identifier:" + deviceId.getId() + " and given type" +
+ deviceId.getType());
}
int enrolmentId = enrolmentInfo.getId();
//Changing the enrollment status & attempt count if the device is marked as inactive or unreachable
@@ -479,23 +479,23 @@ public class OperationManagerImpl implements OperationManager {
try {
OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getNextOperation(
- enrolmentInfo.getId());
+ enrolmentInfo.getId());
if (dtoOperation != null) {
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.equals(dtoOperation.getType()
)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
- getOperation(dtoOperation.getId());
+ getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.equals(dtoOperation.
- getType())) {
+ getType())) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.equals(dtoOperation.
- getType())) {
+ getType())) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.equals(dtoOperation.
- getType())) {
+ getType())) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
@@ -520,26 +520,25 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
- deviceId.getType() + "' device, which carries the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "'");
}
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) {
throw new OperationManagementException(
"Device not found for device id:" + deviceId.getId() + " " + "type:" +
- deviceId.getType());
+ deviceId.getType());
}
try {
int enrolmentId = enrolmentInfo.getId();
OperationManagementDAOFactory.beginTransaction();
- boolean isUpdated = false;
if (operation.getStatus() != null) {
- isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId,
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.
- Operation.Status.valueOf(operation.getStatus().
- toString()));
+ operationDAO.updateOperationStatus(enrolmentId, operationId,
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.
+ Operation.Status.valueOf(operation.getStatus().
+ toString()));
}
if (operation.getOperationResponse() != null) {
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
@@ -549,28 +548,7 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException(
"Error occurred while updating the operation: " + operationId + " status:" +
- operation.getStatus(), e);
- } catch (TransactionManagementException e) {
- throw new OperationManagementException("Error occurred while initiating a transaction", e);
- } finally {
- OperationManagementDAOFactory.closeConnection();
- }
- }
-
- @Override
- public void deleteOperation(int operationId) throws OperationManagementException {
- try {
- OperationManagementDAOFactory.beginTransaction();
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation =
- operationDAO.getOperation(operationId);
- if (operation == null) {
- throw new OperationManagementException("Operation not found for operation id : " + operationId);
- }
- lookupOperationDAO(operation).deleteOperation(operationId);
- OperationManagementDAOFactory.commitTransaction();
- } catch (OperationManagementDAOException e) {
- OperationManagementDAOFactory.rollbackTransaction();
- throw new OperationManagementException("Error occurred while deleting the operation: " + operationId, e);
+ operation.getStatus(), e);
} catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating a transaction", e);
} finally {
@@ -584,56 +562,57 @@ public class OperationManagerImpl implements OperationManager {
Operation operation = null;
if (log.isDebugEnabled()) {
log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " +
- deviceId.getId());
+ deviceId.getId());
}
if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
- deviceId.getType() + "' device, which carries the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "'");
}
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for given device identifier: " +
- deviceId.getId() + " type: " + deviceId.getType());
+ deviceId.getId() + " type: " + deviceId.getType());
}
try {
OperationManagementDAOFactory.openConnection();
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
- getOperationByDeviceAndId(enrolmentInfo.getId(),
- operationId);
- if (dtoOperation.getType().
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation deviceSpecificOperation = operationDAO.
+ getOperationByDeviceAndId(enrolmentInfo.getId(),
+ operationId);
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = deviceSpecificOperation;
+ if (deviceSpecificOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
- getOperation(dtoOperation.getId());
+ getOperation(deviceSpecificOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
- } else if (dtoOperation.getType().
+ } else if (deviceSpecificOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
- dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
- } else if (dtoOperation.getType().equals(
+ dtoOperation = configOperationDAO.getOperation(deviceSpecificOperation.getId());
+ } else if (deviceSpecificOperation.getType().equals(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
- dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
- } else if (dtoOperation.getType().equals(
+ dtoOperation = profileOperationDAO.getOperation(deviceSpecificOperation.getId());
+ } else if (deviceSpecificOperation.getType().equals(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
- dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
+ dtoOperation = policyOperationDAO.getOperation(deviceSpecificOperation.getId());
}
-
if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
- " device id:" + deviceId.getId());
+ " device id:" + deviceId.getId());
}
- operation = OperationDAOUtil.convertOperation(dtoOperation);
+ dtoOperation.setStatus(deviceSpecificOperation.getStatus());
+ operation = OperationDAOUtil.convertOperation(deviceSpecificOperation);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening connection to the data source",
- e);
+ e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
@@ -649,15 +628,15 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
- deviceId.getType() + "' device, which carries the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "'");
}
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) {
throw new OperationManagementException(
"Device not found for device id:" + deviceId.getId() + " " + "type:" +
- deviceId.getType());
+ deviceId.getType());
}
try {
@@ -667,14 +646,14 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
- Status.PENDING));
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
+ Status.PENDING));
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
- Status.PENDING));
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
+ Status.PENDING));
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
- Status.PENDING));
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
+ Status.PENDING));
Operation operation;
@@ -685,9 +664,9 @@ public class OperationManagerImpl implements OperationManager {
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" +
- deviceId.getId() + "' and status:" + status.toString(), e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" +
+ deviceId.getId() + "' and status:" + status.toString(), e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -703,32 +682,32 @@ public class OperationManagerImpl implements OperationManager {
try {
OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation(
- operationId);
+ operationId);
if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for given Id:" + operationId);
}
if (dtoOperation.getType()
- .equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
+ .equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
- getOperation(dtoOperation.getId());
+ getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
- PROFILE)) {
+ PROFILE)) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
- POLICY)) {
+ POLICY)) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" +
- operationId, e);
+ operationId, e);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -737,62 +716,6 @@ public class OperationManagerImpl implements OperationManager {
return operation;
}
- // @Override
- // public Operation getOperationByActivityId(String activity) throws OperationManagementException {
- // // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
- // Operation operation;
- // int enrollmentOpMappingId = Integer.parseInt(
- // activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
- // if (enrollmentOpMappingId == 0) {
- // throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
- // }
- // try {
- // OperationManagementDAOFactory.openConnection();
- // org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation =
- // operationDAO.getOperationFromEnrollment(enrollmentOpMappingId);
- //
- // if (dtoOperation == null) {
- // throw new OperationManagementException("Operation not found for given activity Id:" + activity);
- // }
- // org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status status = dtoOperation.getStatus();
- // if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
- // org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
- // commandOperation =
- // (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
- // getOperation(dtoOperation.getId());
- // dtoOperation.setEnabled(commandOperation.isEnabled());
- // } else if (dtoOperation.getType().
- // equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
- // dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
- // } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
- // PROFILE)) {
- // dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
- // } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
- // POLICY)) {
- // dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
- // }
- // operation = OperationDAOUtil.convertOperation(dtoOperation);
- // int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId);
- // if (enrolmentId != 0) {
- // operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId()));
- // }
- //
- // operation.setStatus(Operation.Status.valueOf(status.toString()));
- // operation.setActivityId(activity);
- //
- // } catch (SQLException e) {
- // throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
- // } catch (OperationManagementDAOException e) {
- // throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" +
- // activity, e);
- // } finally {
- // OperationManagementDAOFactory.closeConnection();
- // }
- //
- // // return this.getOperation(operationId);
- // return operation;
- // }
-
@Override
public Activity getOperationByActivityId(String activity) throws OperationManagementException {
// This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
@@ -808,7 +731,7 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" +
- activity, e);
+ activity, e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
@@ -821,7 +744,11 @@ public class OperationManagerImpl implements OperationManager {
if (operationId == 0) {
throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
}
-
+ if (!isActionAuthorized(deviceId)) {
+ throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
+ deviceId.getType() + "' device, which carries the identifier '" +
+ deviceId.getId() + "'");
+ }
Device device = this.getDevice(deviceId);
try {
OperationManagementDAOFactory.openConnection();
@@ -836,26 +763,6 @@ public class OperationManagerImpl implements OperationManager {
}
}
- @Override
- public List getOperationUpdatedAfter(long timestamp) throws OperationManagementException {
- return null;
- }
-
- @Override
- public List getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException {
- try {
- OperationManagementDAOFactory.openConnection();
- return operationDAO.getActivitiesUpdatedAfter(timestamp);
- } catch (SQLException e) {
- throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
- } catch (OperationManagementDAOException e) {
- throw new OperationManagementException("Error occurred while getting the activity list changed after a " +
- "given time.", e);
- } finally {
- OperationManagementDAOFactory.closeConnection();
- }
- }
-
@Override
public List getActivitiesUpdatedAfter(long timestamp, int limit,
int offset) throws OperationManagementException {
@@ -866,7 +773,7 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while getting the activity list changed after a " +
- "given time.", e);
+ "given time.", e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
@@ -881,7 +788,7 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while getting the activity count changed after a " +
- "given time.", e);
+ "given time.", e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
@@ -902,19 +809,6 @@ public class OperationManagerImpl implements OperationManager {
}
}
- private OperationDAO lookupOperationDAO(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation) {
-
- if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) {
- return commandOperationDAO;
- } else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation) {
- return profileOperationDAO;
- } else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation) {
- return configOperationDAO;
- } else {
- return operationDAO;
- }
- }
-
private String getUser() {
return CarbonContext.getThreadLocalCarbonContext().getUsername();
}
@@ -957,26 +851,6 @@ public class OperationManagerImpl implements OperationManager {
return isUserAuthorized;
}
- private int getEnrolmentByStatus(DeviceIdentifier deviceId,
- EnrolmentInfo.Status status) throws OperationManagementException {
- int enrolmentId;
- try {
- DeviceManagementDAOFactory.openConnection();
- int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
- enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, status, tenantId);
- } catch (DeviceManagementDAOException e) {
- throw new OperationManagementException("Error occurred while retrieving metadata of '" +
- deviceId.getType() + "' device carrying the identifier '" +
- deviceId.getId() + "'", e);
- } catch (SQLException e) {
- throw new OperationManagementException(
- "Error occurred while opening a connection to the data source", e);
- } finally {
- DeviceManagementDAOFactory.closeConnection();
- }
- return enrolmentId;
- }
-
private EnrolmentInfo getEnrolmentInfo(DeviceIdentifier deviceId, String owner) throws OperationManagementException {
EnrolmentInfo enrolmentInfo = null;
try {
@@ -995,15 +869,15 @@ public class OperationManagerImpl implements OperationManager {
}
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
- deviceId.getType() + "' device carrying the identifier '" +
- deviceId.getId() + "' of owner '" + owner + "'", e);
+ deviceId.getType() + "' device carrying the identifier '" +
+ deviceId.getId() + "' of owner '" + owner + "'", e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while checking the device access permissions for '" +
- deviceId.getType() + "' device carrying the identifier '" +
- deviceId.getId() + "' of owner '" + owner + "'", e);
+ deviceId.getType() + "' device carrying the identifier '" +
+ deviceId.getId() + "' of owner '" + owner + "'", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
@@ -1018,8 +892,8 @@ public class OperationManagerImpl implements OperationManager {
enrolmentInfo = deviceDAO.getActiveEnrolment(deviceId, tenantId);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
- deviceId.getType() + "' device carrying the identifier '" +
- deviceId.getId() + "'", e);
+ deviceId.getType() + "' device carrying the identifier '" +
+ deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -1040,7 +914,7 @@ public class OperationManagerImpl implements OperationManager {
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while updating enrollment status of device of " +
- "enrolment-id '" + enrolmentId + "'", e);
+ "enrolment-id '" + enrolmentId + "'", e);
} catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating a transaction", e);
} finally {
@@ -1049,39 +923,15 @@ public class OperationManagerImpl implements OperationManager {
return updateStatus;
}
- private boolean isTaskScheduledOperation(Operation operation, List deviceIds) {
+ private boolean isTaskScheduledOperation(Operation operation) {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
-
List monitoringOperations = deviceManagementProviderService.getMonitoringOperationList(deviceType);//Get task list from each device type
-
- for(MonitoringOperation op : monitoringOperations){
+ for (MonitoringOperation op : monitoringOperations) {
if (operation.getCode().equals(op.getTaskName())) {
return true;
}
}
-
-// for(String dti : taskOperation){
-// if (dti.equals(deviceType)) {
-// monitoringOperations = deviceTypeSpecificTasks.get(dti);
-//
-// }
-// }
-//
-// for(DeviceIdentifier deviceIdentifier : deviceIds){
-// String deviceType = deviceIdentifier.getType();
-//
-//
-//
-// }
-
-// TaskConfiguration taskConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
-// getTaskConfiguration();
-// for (TaskConfiguration.Operation op : taskConfiguration.getOperations()) {
-// if (operation.getCode().equals(op.getOperationName())) {
-// return true;
-// }
-// }
return false;
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java
index cd39b73060..b0bd195dee 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java
@@ -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 {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java
index dc9b6dfb9a..58b0083b05 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java
@@ -33,12 +33,8 @@ public interface OperationDAO {
void updateOperation(Operation operation) throws OperationManagementDAOException;
- void deleteOperation(int operationId) throws OperationManagementDAOException;
-
Operation getOperation(int operationId) throws OperationManagementDAOException;
- Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException;
-
Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException;
List extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status)
@@ -66,24 +62,16 @@ public interface OperationDAO {
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException;
- List getOperationResponses(int enrolmentId, int operationId) throws OperationManagementDAOException;
-
Activity getActivity(int operationId) throws OperationManagementDAOException;
Activity getActivityByDevice(int operationId, int deviceId) throws OperationManagementDAOException;
- int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException;
-
- List getOperationsUpdatedAfter(long timestamp) throws OperationManagementDAOException;
-
List getActivitiesUpdatedAfter(long timestamp) throws OperationManagementDAOException;
List getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException;
int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementDAOException;
- boolean resetAttemptCount(int enrolmentId) throws OperationManagementDAOException;
-
/**
* This method provides operation mappings for given status
* @param opStatus Operation status
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java
index b28b773d7b..aa5d9b7bea 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java
@@ -18,6 +18,7 @@
*/
package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java
index fcf57ab022..ac64d6550c 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java
@@ -70,22 +70,6 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl {
}
}
- @Override
- public void deleteOperation(int id) throws OperationManagementDAOException {
- PreparedStatement stmt = null;
- try {
- super.deleteOperation(id);
- Connection connection = OperationManagementDAOFactory.getConnection();
- stmt = connection.prepareStatement("DELETE FROM DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
- stmt.setInt(1, id);
- stmt.executeUpdate();
- } catch (SQLException e) {
- throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt);
- }
- }
-
public CommandOperation getOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java
index 82beb1b5f0..052a9aeccb 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java
@@ -58,22 +58,6 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl {
return operationId;
}
- @Override
- public void deleteOperation(int id) throws OperationManagementDAOException {
- PreparedStatement stmt = null;
- try {
- super.deleteOperation(id);
- Connection connection = OperationManagementDAOFactory.getConnection();
- stmt = connection.prepareStatement("DELETE FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ;
- stmt.setInt(1, id);
- stmt.executeUpdate();
- } catch (SQLException e) {
- throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt);
- }
- }
-
@Override
public void updateOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java
index 7e174ec714..7ab5a4bd94 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java
@@ -249,68 +249,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
}
- @Override
- public List getOperationResponses(int enrolmentId, int operationId) throws
- OperationManagementDAOException {
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- List responces = new ArrayList<>();
- try {
- Connection conn = OperationManagementDAOFactory.getConnection();
- String sql = "SELECT * FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?";
- stmt = conn.prepareStatement(sql);
- stmt.setInt(1, enrolmentId);
- stmt.setInt(2, operationId);
- rs = stmt.executeQuery();
-
- while (rs.next()) {
- OperationResponse response = new OperationResponse();
- response.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
- ByteArrayInputStream bais = null;
- ObjectInputStream ois = null;
- byte[] contentBytes;
- try {
- contentBytes = (byte[]) rs.getBytes("OPERATION_RESPONSE");
- bais = new ByteArrayInputStream(contentBytes);
- ois = new ObjectInputStream(bais);
- response.setResponse(ois.readObject().toString());
-
- } finally {
- if (bais != null) {
- try {
- bais.close();
- } catch (IOException e) {
- log.warn("Error occurred while closing ByteArrayOutputStream", e);
- }
- }
- if (ois != null) {
- try {
- ois.close();
- } catch (IOException e) {
- log.warn("Error occurred while closing ObjectOutputStream", e);
- }
- }
- }
- responces.add(response);
- }
-
- } catch (SQLException e) {
- throw new OperationManagementDAOException("SQL Error occurred while retrieving the operation responses for " +
- "operation id " + operationId + " and enrolment id " + enrolmentId, e);
- } catch (ClassNotFoundException e) {
- throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" +
- " for operation id " + operationId + " and enrolment id " + enrolmentId, e);
- } catch (IOException e) {
- throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" +
- " for operation id " + operationId + " and enrolment id " + enrolmentId, e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt, rs);
- }
-
- return responces;
- }
-
@Override
public Activity getActivity(int operationId) throws OperationManagementDAOException {
@@ -674,80 +612,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
return 0;
}
- @Override
- public int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException {
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- Connection conn = OperationManagementDAOFactory.getConnection();
- String sql = "SELECT * FROM DM_ENROLMENT_OP_MAPPING WHERE ID = ?";
- stmt = conn.prepareStatement(sql);
- stmt.setInt(1, enrollmentOpMappingId);
- rs = stmt.executeQuery();
-
- if (rs.next()) {
- return rs.getInt("ENROLMENT_ID");
- }
-
- } catch (SQLException e) {
- throw new OperationManagementDAOException("SQL Error occurred while retrieving the enrolment id " +
- " for the mapping id '" + enrollmentOpMappingId, e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt, rs);
- }
- return -1;
- }
-
- @Override
- public List getOperationsUpdatedAfter(long timestamp) throws OperationManagementDAOException {
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- List operations = new ArrayList<>();
- try {
- Connection conn = OperationManagementDAOFactory.getConnection();
- String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE " +
- "FROM DM_OPERATION AS o \n" +
- "INNER JOIN DM_ENROLMENT_OP_MAPPING AS eom ON eom.OPERATION_ID=o.ID WHERE eom.UPDATED_TIMESTAMP = ?";
- stmt = conn.prepareStatement(sql);
- stmt.setLong(1, timestamp);
- rs = stmt.executeQuery();
-
- if (rs.next()) {
- Operation operation = new Operation();
- operation.setId(rs.getInt("ID"));
- operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
- operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
- operation.setCode(rs.getString("OPERATION_CODE"));
-
- operations.add(operation);
- }
-
- } catch (SQLException e) {
- throw new OperationManagementDAOException("Error occurred while retrieving the operations updated " +
- "after a given time", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt, rs);
- }
- return operations;
- }
-
-
- @Override
- public void deleteOperation(int id) throws OperationManagementDAOException {
- PreparedStatement stmt = null;
- try {
- Connection connection = OperationManagementDAOFactory.getConnection();
- stmt = connection.prepareStatement("DELETE FROM DM_OPERATION WHERE ID = ?");
- stmt.setInt(1, id);
- stmt.executeUpdate();
- } catch (SQLException e) {
- throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt);
- }
- }
-
@Override
public Operation getOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null;
@@ -783,49 +647,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
return operation;
}
- @Override
- public Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException {
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Operation operation = null;
- try {
- Connection conn = OperationManagementDAOFactory.getConnection();
- String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, \n" +
- " om.STATUS, om.UPDATED_TIMESTAMP FROM DM_OPERATION o \n" +
- "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm WHERE dm.ID = ? ) om \n" +
- "ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC ";
- stmt = conn.prepareStatement(sql);
- stmt.setInt(1, enrollmentOpMappingId);
- rs = stmt.executeQuery();
-
- if (rs.next()) {
- operation = new Operation();
- operation.setId(rs.getInt("ID"));
- operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
- operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
-// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
-// operation.setReceivedTimeStamp("");
-// } else {
-// operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
-// }
- if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
- operation.setReceivedTimeStamp("");
- } else {
- operation.setReceivedTimeStamp(
- new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
- }
- operation.setCode(rs.getString("OPERATION_CODE"));
- operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
- OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
- }
- } catch (SQLException e) {
- throw new OperationManagementDAOException("SQL error occurred while retrieving the operation .", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt, rs);
- }
- return operation;
- }
-
@Override
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null;
@@ -833,9 +654,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
- String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
+ String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, o.OPERATION_CODE, " +
"om.ID AS OM_MAPPING_ID, " +
- "om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," +
+ "om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
"OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"ON o.ID = om.OPERATION_ID ";
@@ -850,6 +671,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
+ operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
// operation.setReceivedTimeStamp("");
// } else {
@@ -1176,31 +998,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
return operations;
}
- @Override
- public boolean resetAttemptCount(int enrolmentId) throws OperationManagementDAOException {
- boolean status = false;
- Connection conn;
- PreparedStatement stmt = null;
- Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
- int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
- try {
- conn = OperationManagementDAOFactory.getConnection();
- String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = 0, LAST_REQUESTED_TIME = ? " +
- "WHERE ENROLMENT_ID = ? AND TENANT_ID = ?";
- stmt = conn.prepareStatement(query);
- stmt.setTimestamp(1, currentTimestamp);
- stmt.setInt(2, enrolmentId);
- stmt.setInt(3, tenantId);
- stmt.executeUpdate();
- status = true;
- } catch (SQLException e) {
- throw new OperationManagementDAOException("Unable to reset the attempt count in database.", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt, null);
- }
- return status;
- }
-
@Override
public Map> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
int limit) throws OperationManagementDAOException {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java
index 4c0243ac80..f24cfb3ae3 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java
@@ -122,22 +122,6 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl {
}
}
- @Override
- public void deleteOperation(int operationId) throws OperationManagementDAOException {
- PreparedStatement stmt = null;
- try {
- super.deleteOperation(operationId);
- Connection connection = OperationManagementDAOFactory.getConnection();
- stmt = connection.prepareStatement("DELETE FROM DM_POLICY_OPERATION WHERE OPERATION_ID=?");
- stmt.setInt(1, operationId);
- stmt.executeUpdate();
- } catch (SQLException e) {
- throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt);
- }
- }
-
@Override
public Operation getOperation(int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java
index 931cc079f4..78b88f9855 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java
@@ -123,22 +123,6 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl {
}
}
- @Override
- public void deleteOperation(int id) throws OperationManagementDAOException {
- PreparedStatement stmt = null;
- try {
- super.deleteOperation(id);
- Connection connection = OperationManagementDAOFactory.getConnection();
- stmt = connection.prepareStatement("DELETE FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?");
- stmt.setInt(1, id);
- stmt.executeUpdate();
- } catch (SQLException e) {
- throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
- } finally {
- OperationManagementDAOUtil.cleanupResources(stmt);
- }
- }
-
public Operation getOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java
deleted file mode 100644
index 79ffacb370..0000000000
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java
+++ /dev/null
@@ -1,154 +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 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 void deleteOperation(int operationId) throws OperationManagementException {
- this.operationManager.deleteOperation(operationId);
- }
-
- @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 getOperationUpdatedAfter(long timestamp) throws OperationManagementException {
- return this.operationManager.getOperationUpdatedAfter(timestamp);
- }
-
- @Override
- public List getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException {
- return this.operationManager.getActivitiesUpdatedAfter(timestamp);
- }
-
- @Override
- public List 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 void setNotificationStrategy(NotificationStrategy notificationStrategy) {
-
- }
-
- @Override
- public NotificationStrategy getNotificationStrategy() {
- return notificationProvider;
- }
-
-}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
index ffd559b1ad..fe77b94180 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
@@ -510,8 +510,6 @@ public interface DeviceManagementProviderService {
boolean enrollDevice(Device device) throws DeviceManagementException;
- PlatformConfiguration getConfiguration() throws DeviceManagementException;
-
boolean saveConfiguration(PlatformConfiguration configuration) throws DeviceManagementException;
boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
@@ -553,8 +551,6 @@ public interface DeviceManagementProviderService {
void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException;
- void deleteOperation(String type, int operationId) throws OperationManagementException;
-
Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
throws OperationManagementException;
@@ -568,8 +564,6 @@ public interface DeviceManagementProviderService {
Activity getOperationByActivityIdAndDevice(String activity, DeviceIdentifier deviceId) throws OperationManagementException;
- List getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException;
-
List getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException;
int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
index e91d5eb5ce..e5d065a196 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
@@ -129,11 +129,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return dms.saveConfiguration(configuration);
}
- @Override
- public PlatformConfiguration getConfiguration() throws DeviceManagementException {
- return null;
- }
-
@Override
public PlatformConfiguration getConfiguration(String deviceType) throws DeviceManagementException {
DeviceManager dms =
@@ -1429,11 +1424,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
.updateOperation(deviceId, operation);
}
- @Override
- public void deleteOperation(String type, int operationId) throws OperationManagementException {
- pluginRepository.getOperationManager(type, this.getTenantId()).deleteOperation(operationId);
- }
-
@Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId,
int operationId) throws OperationManagementException {
@@ -1463,11 +1453,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByActivityIdAndDevice(activity, deviceId);
}
- @Override
- public List getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException {
- return DeviceManagementDataHolder.getInstance().getOperationManager().getActivitiesUpdatedAfter(timestamp);
- }
-
@Override
public List getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException {
limit = DeviceManagerUtil.validateActivityListPageSize(limit);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java
index 13f87ad01f..69efaa107d 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java
@@ -259,7 +259,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
if (log.isDebugEnabled()) {
log.debug("Get groups");
}
- List deviceGroups = new ArrayList<>();
+ List deviceGroups;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection();
@@ -293,7 +293,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
log.debug("Get groups with pagination " + request.toString());
}
request = DeviceManagerUtil.validateGroupListPageSize(request);
- List deviceGroups = new ArrayList<>();
+ List deviceGroups;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection();
@@ -345,14 +345,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
for (DeviceGroup deviceGroup : deviceGroups) {
groups.put(deviceGroup.getGroupId(), deviceGroup);
}
-// } catch (UserStoreException e) {
-// String msg = "Error occurred while getting user store manager.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while retrieving all groups accessible to user.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (UserStoreException | SQLException | GroupManagementDAOException e) {
String msg = "Error occurred while retrieving all groups accessible to user.";
log.error(msg, e);
@@ -368,16 +360,11 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
}
private List getGroupIds(String username) throws GroupManagementException {
- if (username == null || username.isEmpty()) {
- String msg = "Received empty user name for getGroupIds";
- log.error(msg);
- throw new GroupManagementException(msg);
- }
if (log.isDebugEnabled()) {
log.debug("Get groups Ids of owner '" + username + "'");
}
UserStoreManager userStoreManager;
- List deviceGroupIds = new ArrayList<>();
+ List deviceGroupIds;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
@@ -386,14 +373,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
GroupManagementDAOFactory.openConnection();
deviceGroupIds = this.groupDAO.getOwnGroupIds(username, tenantId);
deviceGroupIds.addAll(this.groupDAO.getGroupIds(roleList, tenantId));
-// } catch (UserStoreException e) {
-// String msg = "Error occurred while getting user store manager.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while retrieving all groups accessible to user.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (UserStoreException | SQLException | GroupManagementDAOException e) {
String msg = "Error occurred while retrieving all groups accessible to user.";
log.error(msg, e);
@@ -421,7 +400,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
}
request = DeviceManagerUtil.validateGroupListPageSize(request);
List allDeviceGroupIdsOfUser = getGroupIds(currentUser);
- List allMatchingGroups = new ArrayList<>();
+ List allMatchingGroups;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.openConnection();
@@ -430,10 +409,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening a connection to the data source.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getGroups";
log.error(msg, e);
@@ -460,10 +435,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening a connection to the data source.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred";
log.error(msg, e);
@@ -490,10 +461,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening a connection to the data source.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getGroupCount";
log.error(msg, e);
@@ -527,18 +494,10 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
count = groupDAO.getOwnGroupsCount(username, tenantId);
count += groupDAO.getGroupsCount(roleList, tenantId);
return count;
-// } catch (UserStoreException e) {
-// String msg = "Error occurred while getting user store manager.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (UserStoreException | GroupManagementDAOException | SQLException e) {
String msg = "Error occurred while retrieving group count of user '" + username + "'";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening a connection to the data source.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getGroupCount for username '" + username + "'";
log.error(msg, e);
@@ -619,10 +578,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening a connection to the data source.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getRoles for groupId: " + groupId;
log.error(msg, e);
@@ -651,14 +606,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
String msg = "Error occurred while getting devices in group.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening a connection to the data source.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
-// } catch (DeviceManagementException e) {
-// String msg = "Error occurred while validating the limit of the devices to be returned";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getDevices for groupId: " + groupId;
log.error(msg, e);
@@ -684,10 +631,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
String msg = "Error occurred while retrieving all groups in tenant";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening a connection to the data source.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getDeviceCount for groupId: " + groupId;
log.error(msg, e);
@@ -838,18 +781,10 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
GroupManagementDAOFactory.openConnection();
return groupDAO.getGroups(device.getId(),
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
-// } catch (DeviceManagementException e) {
-// String msg = "Error occurred while retrieving the device details.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (DeviceManagementException | GroupManagementDAOException | SQLException e) {
String msg = "Error occurred while retrieving device groups.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
-// } catch (SQLException e) {
-// String msg = "Error occurred while opening database connection.";
-// log.error(msg, e);
-// throw new GroupManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred in getGroups";
log.error(msg, e);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java
index 19ab94ca8a..bfb4826762 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java
@@ -474,6 +474,13 @@ public final class DeviceManagerUtil {
return true;
}
+ public static boolean isDeviceExists(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
+ Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier,
+ false);
+ return !(device == null || device.getDeviceIdentifier() == null ||
+ device.getDeviceIdentifier().isEmpty() || device.getEnrolmentInfo() == null);
+ }
+
private static CacheManager getCacheManager() {
return Caching.getCacheManagerFactory().getCacheManager(DeviceManagementConstants.DM_CACHE_MANAGER);
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java
index fca34667aa..f83100b442 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java
@@ -31,10 +31,18 @@ public class TestDeviceManagementService implements DeviceManagementService {
private String providerType;
private String tenantDomain;
+ private String operationCode;
+
+ public TestDeviceManagementService(String deviceType, String tenantDomain, String operationCode) {
+ providerType = deviceType;
+ this.tenantDomain = tenantDomain;
+ this.operationCode = operationCode;
+ }
public TestDeviceManagementService(String deviceType, String tenantDomain) {
providerType = deviceType;
this.tenantDomain = tenantDomain;
+ this.operationCode = "default";
}
@Override
@@ -48,12 +56,10 @@ public class TestDeviceManagementService implements DeviceManagementService {
taskConfig.setEnabled(true);
taskConfig.setFrequency(3000);
List monitoringOperations = new ArrayList<>();
- for (int i = 0; i < 5; i++) {
- MonitoringOperation monitoringOperation = new MonitoringOperation();
- monitoringOperation.setTaskName("OPERATION-" + i);
- monitoringOperation.setRecurrentTimes(i);
- monitoringOperations.add(monitoringOperation);
- }
+ MonitoringOperation monitoringOperation = new MonitoringOperation();
+ monitoringOperation.setTaskName(operationCode);
+ monitoringOperation.setRecurrentTimes(2);
+ monitoringOperations.add(monitoringOperation);
taskConfig.setMonitoringOperation(monitoringOperations);
return taskConfig;
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java
index a1a17b47e3..c81b4e4eb3 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java
@@ -50,22 +50,22 @@ public class TestDeviceManager implements DeviceManager {
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
- return false;
+ return true;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
- return false;
+ return true;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
- return false;
+ return true;
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
- return false;
+ return true;
}
@Override
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestTaskServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestTaskServiceImpl.java
index 7210942ca5..882cc266f6 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestTaskServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestTaskServiceImpl.java
@@ -17,73 +17,30 @@
*/
package org.wso2.carbon.device.mgt.core;
+import org.wso2.carbon.device.mgt.core.task.TestTaskManagerImpl;
import org.wso2.carbon.ntask.common.TaskException;
import org.wso2.carbon.ntask.core.TaskInfo;
import org.wso2.carbon.ntask.core.TaskManager;
import org.wso2.carbon.ntask.core.service.TaskService;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestTaskServiceImpl implements TaskService {
- @Override
- public TaskManager getTaskManager(String s) throws TaskException {
- return new TaskManager() {
- @Override
- public void initStartupTasks() throws TaskException {
-
- }
-
- @Override
- public void scheduleTask(String s) throws TaskException {
-
- }
-
- @Override
- public void rescheduleTask(String s) throws TaskException {
-
- }
-
- @Override
- public boolean deleteTask(String s) throws TaskException {
- return false;
- }
-
- @Override
- public void pauseTask(String s) throws TaskException {
-
- }
+ private Set registeredTaskTypes;
+ private TaskManager taskManager;
- @Override
- public void resumeTask(String s) throws TaskException {
+ public TestTaskServiceImpl() {
- }
-
- @Override
- public void registerTask(TaskInfo taskInfo) throws TaskException {
-
- }
-
- @Override
- public TaskState getTaskState(String s) throws TaskException {
- return null;
- }
-
- @Override
- public TaskInfo getTask(String s) throws TaskException {
- return null;
- }
-
- @Override
- public List getAllTasks() throws TaskException {
- return null;
- }
+ this.registeredTaskTypes = new HashSet<>();
+ this.taskManager = new TestTaskManagerImpl();
+ }
- @Override
- public boolean isTaskScheduled(String s) throws TaskException {
- return false;
- }
- };
+ @Override
+ public TaskManager getTaskManager(String s) throws TaskException {
+ return this.taskManager;
}
@Override
@@ -93,12 +50,12 @@ public class TestTaskServiceImpl implements TaskService {
@Override
public void registerTaskType(String s) throws TaskException {
-
+ this.registeredTaskTypes.add(s);
}
@Override
public Set getRegisteredTaskTypes() {
- return null;
+ return this.registeredTaskTypes;
}
@Override
@@ -108,7 +65,7 @@ public class TestTaskServiceImpl implements TaskService {
@Override
public boolean isServerInit() {
- return false;
+ return true;
}
@Override
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java
index 1a21646150..29aad743c8 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java
@@ -22,7 +22,15 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
-
+import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
+import org.wso2.carbon.registry.core.config.RegistryContext;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
+import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
+
+import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -58,7 +66,6 @@ public class TestUtils {
}
}
-
public static DeviceGroup createDeviceGroup1(){
DeviceGroup group = new DeviceGroup();
group.setName("TEST_GROUP_01");
@@ -108,4 +115,14 @@ public class TestUtils {
return list;
}
+
+ public static RegistryService getRegistryService(Class clazz) throws RegistryException {
+ RealmService realmService = new InMemoryRealmService();
+ RegistryDataHolder.getInstance().setRealmService(realmService);
+ DeviceManagementDataHolder.getInstance().setRealmService(realmService);
+ InputStream is = clazz.getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
+ RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
+ context.setSetup(true);
+ return context.getEmbeddedRegistryService();
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
index a1752db7fb..e5c21cdcd8 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
@@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.testng.Assert;
-import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.w3c.dom.Document;
@@ -30,16 +29,31 @@ import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.TestUtils;
+import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
+import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
+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.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
+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.GroupManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
+import org.wso2.carbon.registry.core.config.RegistryContext;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
+import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
import javax.sql.DataSource;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
+import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -55,6 +69,7 @@ public abstract class BaseDeviceManagementTest {
this.initDataSource();
this.initSQLScript();
this.initializeCarbonContext();
+ this.initServices();
}
protected void initDataSource() throws Exception {
@@ -62,6 +77,28 @@ public abstract class BaseDeviceManagementTest {
DeviceManagementDAOFactory.init(dataSource);
GroupManagementDAOFactory.init(dataSource);
OperationManagementDAOFactory.init(dataSource);
+ NotificationManagementDAOFactory.init(dataSource);
+ }
+
+ private void initServices() throws DeviceManagementException, RegistryException {
+ DeviceConfigurationManager.getInstance().initConfig();
+ DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl();
+ DeviceManagementServiceComponent.notifyStartupListeners();
+ DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
+ DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
+ DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
+ DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
+ DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
+ }
+
+ private RegistryService getRegistryService() throws RegistryException {
+ RealmService realmService = new InMemoryRealmService();
+ RegistryDataHolder.getInstance().setRealmService(realmService);
+ DeviceManagementDataHolder.getInstance().setRealmService(realmService);
+ InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
+ RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
+ context.setSetup(true);
+ return context.getEmbeddedRegistryService();
}
@BeforeClass
@@ -131,7 +168,7 @@ public abstract class BaseDeviceManagementTest {
try {
conn = getDataSource().getConnection();
conn.setAutoCommit(false);
- String[] cleanupTables = new String[]{"DM_DEVICE_OPERATION_RESPONSE","DM_ENROLMENT_OP_MAPPING", "DM_CONFIG_OPERATION",
+ String[] cleanupTables = new String[]{"DM_NOTIFICATION","DM_DEVICE_OPERATION_RESPONSE","DM_ENROLMENT_OP_MAPPING", "DM_CONFIG_OPERATION",
"DM_POLICY_OPERATION", "DM_COMMAND_OPERATION", "DM_PROFILE_OPERATION", "DM_DEVICE_GROUP_MAP",
"DM_GROUP", "DM_ENROLMENT", "DM_DEVICE_APPLICATION_MAPPING",
"DM_APPLICATION", "DM_DEVICE", "DM_DEVICE_TYPE"};
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java
index 180fae6b1b..a23fdbc638 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java
@@ -18,8 +18,11 @@ package org.wso2.carbon.device.mgt.core.common;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
+import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
+import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.ArrayList;
@@ -52,6 +55,30 @@ public class TestDataHolder {
return device;
}
+ public static Notification getNotification(int notificationId, String status, String deviceId,
+ String description, String deviceName, int operationId,
+ String deviceType) {
+ Notification notification = new Notification();
+ notification.setNotificationId(notificationId);
+ notification.setStatus(status);
+ notification.setDeviceIdentifier(deviceId);
+ notification.setDescription(description);
+ notification.setDeviceName(deviceName);
+ notification.setOperationId(operationId);
+ notification.setDeviceType(deviceType);
+ return notification;
+ }
+
+ public static Device generateDummyDeviceData(String deviceIdentifier, String deviceType,
+ EnrolmentInfo enrolmentInfo) {
+ Device device = new Device();
+ device.setEnrolmentInfo(enrolmentInfo);
+ device.setDescription("Test Description");
+ device.setDeviceIdentifier(deviceIdentifier);
+ device.setType(deviceType);
+ return device;
+ }
+
public static List generateDummyDeviceData(List deviceIds) {
List devices = new ArrayList<>();
for (DeviceIdentifier deviceId : deviceIds) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java
new file mode 100644
index 0000000000..21e729293d
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java
@@ -0,0 +1,220 @@
+/*
+* Copyright (c) 2017, 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.notification.mgt;
+
+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;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.EntityDoesNotExistException;
+import org.wso2.carbon.device.mgt.common.PaginationRequest;
+import org.wso2.carbon.device.mgt.common.PaginationResult;
+import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
+import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
+import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
+import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
+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.DeviceManagementServiceComponent;
+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.GroupManagementProviderServiceImpl;
+import org.wso2.carbon.registry.core.config.RegistryContext;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
+import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This is the test class for {@link NotificationManagementServiceImpl}
+ */
+public class NotificationManagementServiceImplTests {
+
+ private static final Log log = LogFactory.getLog(NotificationManagementServiceImplTests.class);
+ private static final String DEVICE_TYPE = "NOTIFICATION_TEST_DEVICE";
+ private static final String DEVICE_ID_PREFIX = "NOTIFICATION-TEST-DEVICE-ID-";
+ private static final int NO_OF_DEVICES = 10;
+ private static final int NO_OF_NOTIFICATIONS = 10;
+ private List deviceIds = new ArrayList<>();
+ private NotificationManagementServiceImpl notificationManagementService;
+ private static final String TEST_NOTIFICATION_DESCRIPTION = "test notification";
+ private static final int NOTIFICATION_OPERATION_ID = 1;
+
+ @BeforeClass
+ public void init() throws Exception {
+ DeviceConfigurationManager.getInstance().initConfig();
+ log.info("Initializing");
+ for (int i = 1; i <= NO_OF_DEVICES; i++) {
+ deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
+ }
+ List devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
+ DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl();
+ DeviceManagementServiceComponent.notifyStartupListeners();
+ DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
+ DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
+ DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
+ DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
+ DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
+ deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
+ MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
+ for (Device device : devices) {
+ Assert.assertTrue(deviceMgtService.enrollDevice(device), "Device with Identifier - " +
+ device.getDeviceIdentifier() + " is not enrolled.");
+ }
+ List returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
+
+ for (Device device : returnedDevices) {
+ if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
+ throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
+ }
+ }
+ notificationManagementService = new NotificationManagementServiceImpl();
+ }
+
+ private RegistryService getRegistryService() throws RegistryException {
+ RealmService realmService = new InMemoryRealmService();
+ RegistryDataHolder.getInstance().setRealmService(realmService);
+ DeviceManagementDataHolder.getInstance().setRealmService(realmService);
+ InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
+ RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
+ context.setSetup(true);
+ return context.getEmbeddedRegistryService();
+ }
+
+ @Test(description = "Add notifications using addNotification method and check whether it returns true.")
+ public void addNotification() throws NotificationManagementException {
+ for (int i = 1; i <= NO_OF_DEVICES; i++) {
+ DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE);
+ Notification notification = TestDataHolder.getNotification(i, Notification.Status.NEW.toString(),
+ testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i,
+ NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
+ Assert.assertTrue(notificationManagementService.addNotification(testDeviceIdentifier, notification),
+ "Adding notification failed for [" + notification.toString() + "]");
+ }
+ }
+
+ @Test(expectedExceptions = EntityDoesNotExistException.class, description = "AddNotification method is checked" +
+ " whether it returns EntityDoesNotExistException when the device not registered is added notification")
+ public void addNotificationExceptions() throws NotificationManagementException {
+ DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + 123, DEVICE_TYPE);
+ Notification notification = TestDataHolder.getNotification(1, Notification.Status.NEW.toString(),
+ testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + 123,
+ NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
+ notificationManagementService.addNotification(new DeviceIdentifier(DEVICE_ID_PREFIX + 123,
+ DEVICE_TYPE), notification);
+ }
+
+ @Test(expectedExceptions = NotificationManagementException.class, description = "This tests the method getDevice which" +
+ " is called internally in addNotification for DeviceManagementException exception passing null device Id.")
+ public void getDevice() throws NotificationManagementException {
+ DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + 123, DEVICE_TYPE);
+ Notification notification = TestDataHolder.getNotification(1, Notification.Status.NEW.toString(),
+ testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + 123,
+ NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
+ notificationManagementService.addNotification(null, notification);
+ }
+
+ @Test(dependsOnMethods = "addNotification", description = "This tests the updateNotification Method" +
+ " and check whether it returns true ( got updated )")
+ public void updateNotification() throws NotificationManagementException {
+ for (int i = 1; i <= NO_OF_DEVICES; i++) {
+ DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE);
+ Notification notification = TestDataHolder.getNotification(i, Notification.Status.CHECKED.toString(),
+ testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i,
+ NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
+ Assert.assertTrue(notificationManagementService.updateNotification(notification), "Notification " +
+ "update failed for [" + notification.toString() + "]");
+ }
+ }
+
+ @Test(dependsOnMethods = "updateNotification", description = "This method update notification status " +
+ "and check whether it got updated")
+ public void updateNotificationStatus() throws NotificationManagementException {
+ for (int i = 1; i <= NO_OF_DEVICES; i++) {
+ Assert.assertTrue(notificationManagementService.updateNotificationStatus(i, Notification.Status.CHECKED),
+ "Notification update status failed for notification id:- " + i);
+ }
+ }
+
+ @Test(dependsOnMethods = "addNotification", description = "this tests getAllNotifications" +
+ " method by listing down all the notifications.")
+ public void getAllNotifications() throws NotificationManagementException {
+ List returnedNotifications = notificationManagementService.getAllNotifications();
+ Assert.assertEquals(returnedNotifications.size(), NO_OF_DEVICES, "No. of notifications added is not " +
+ "equal to no. of notifications retrieved.");
+ }
+
+ @Test(dependsOnMethods = "updateNotificationStatus", description = "this method retries notification by id" +
+ " and checks it")
+ public void getNotification() throws NotificationManagementException {
+ for (int i = 1; i <= NO_OF_DEVICES; i++) {
+ Notification returnedNotification = notificationManagementService.getNotification(i);
+ Assert.assertEquals(returnedNotification.getNotificationId(), i, "Returned notification ID is not " +
+ "same as added notification Id.");
+ Assert.assertEquals(returnedNotification.getStatus(), Notification.Status.CHECKED, "Returned " +
+ "notification status is not same as added notification status.");
+ Assert.assertEquals(returnedNotification.getDescription(), TEST_NOTIFICATION_DESCRIPTION, "Returned" +
+ " notification description is not same as added notification description.");
+ Assert.assertEquals(returnedNotification.getOperationId(), NOTIFICATION_OPERATION_ID, "Returned " +
+ "notification operation ID is not same as added notification operation Id.");
+ }
+ }
+
+ @Test(dependsOnMethods = "updateNotificationStatus", description = "this method gets all notification by status checked")
+ public void getNotificationsByStatus() throws NotificationManagementException {
+ List returnedNotifications = notificationManagementService.getNotificationsByStatus(Notification.
+ Status.CHECKED);
+ Assert.assertEquals(returnedNotifications.size(), NO_OF_NOTIFICATIONS, "Returned no. of notification is " +
+ "not same as added no. of notifications.");
+ }
+
+ @Test(dependsOnMethods = "addNotification", description = "this tests for getAllNotification method by passing " +
+ "pagination request and validates the no. of total records and filtered records. ")
+ public void getAllNotificationsWithPaginationRequest() throws NotificationManagementException {
+ PaginationRequest request = new PaginationRequest(1, 2);
+ PaginationResult result = notificationManagementService.getAllNotifications(request);
+ Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS, "Returned filtered records is " +
+ "not same as added filtered records.");
+ Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS, "Returned no. of records is not " +
+ "same as added no. of records.");
+ }
+
+ @Test(dependsOnMethods = "updateNotificationStatus", description = "this tests for getAllNotification method by" +
+ " passing pagination request & status and validates the no. of total records and filtered records. ")
+ public void getAllNotificationsWithPaginationRequestAndStatus() throws NotificationManagementException {
+ PaginationRequest request = new PaginationRequest(1, 2);
+ PaginationResult result = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED,
+ request);
+ Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS, "Returned filtered records is not " +
+ "same as added filtered records.");
+ Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS, "Returned no. of records is not same" +
+ " as added no. of records.");
+ }
+
+}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java
index 81cc2c4738..9ba56c160a 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementTests.java
@@ -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;
@@ -35,37 +33,30 @@ 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.OperationManagementException;
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.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
-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.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.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
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.ProfileOperation;
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.GroupManagementProviderServiceImpl;
-import org.wso2.carbon.registry.core.config.RegistryContext;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
-import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
-import org.wso2.carbon.registry.core.service.RegistryService;
-import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-import java.io.InputStream;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-public class OperationManagementTests{
- private static final Log log = LogFactory.getLog(OperationManagementTests.class);
+/**
+ * This is the testcase which covers the methods from {@link OperationManager}
+ */
+public class OperationManagementTests extends BaseDeviceManagementTest {
private static final String DEVICE_TYPE = "OP_TEST_TYPE";
private static final String DEVICE_ID_PREFIX = "OP-TEST-DEVICE-ID-";
@@ -77,25 +68,21 @@ public class OperationManagementTests{
private static final int NO_OF_DEVICES = 5;
private static final String ADMIN_USER = "admin";
private static final String NON_ADMIN_USER = "test";
+ private static final String INVALID_DEVICE = "ThisIsInvalid";
private List deviceIds = new ArrayList<>();
private OperationManager operationMgtService;
+ private Activity commandActivity;
+ private long commandActivityBeforeUpdatedTimestamp;
@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));
}
List devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
- DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl();
- DeviceManagementServiceComponent.notifyStartupListeners();
- DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
- DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
- DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
- DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
- DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
+ DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance().
+ getDeviceManagementProvider();
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
for (Device device : devices) {
@@ -107,48 +94,111 @@ public class OperationManagementTests{
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
}
}
- this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE);
+ NotificationStrategy notificationStrategy = new TestNotificationStrategy();
+ this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
}
- private RegistryService getRegistryService() throws RegistryException {
- RealmService realmService = new InMemoryRealmService();
- RegistryDataHolder.getInstance().setRealmService(realmService);
- DeviceManagementDataHolder.getInstance().setRealmService(realmService);
- InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
- RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
- context.setSetup(true);
- return context.getEmbeddedRegistryService();
+ @Test
+ public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ this.commandActivity = this.operationMgtService.addOperation(
+ getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
+ this.deviceIds);
+ validateOperationResponse(this.commandActivity, ActivityStatus.Status.PENDING);
}
@Test
- public void addCommandOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
- Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
- this.deviceIds);
- validateOperationResponse(activity);
+ public void addCommandOperationInvalidDeviceIds() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ startTenantFlowAsNonAdmin();
+ try {
+ ArrayList invalidDevices = new ArrayList<>();
+ for (int i = 0; i < 3; i++) {
+ invalidDevices.add(new DeviceIdentifier(INVALID_DEVICE + i, DEVICE_TYPE));
+ }
+ invalidDevices.addAll(this.deviceIds);
+ Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
+ Operation.Type.COMMAND, COMMAND_OPERATON_CODE), invalidDevices);
+ Assert.assertEquals(activity.getActivityStatus().size(), invalidDevices.size(),
+ "The operation response for add operation only have - " + activity.getActivityStatus().size());
+ for (int i = 0; i < activity.getActivityStatus().size(); i++) {
+ ActivityStatus status = activity.getActivityStatus().get(i);
+ if (i < 3) {
+ Assert.assertEquals(status.getStatus(), ActivityStatus.Status.INVALID);
+ } else {
+ Assert.assertEquals(status.getStatus(), ActivityStatus.Status.UNAUTHORIZED);
+ }
+ }
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
+
+ @Test(expectedExceptions = InvalidDeviceException.class)
+ public void addEmptyDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND,
+ COMMAND_OPERATON_CODE),
+ new ArrayList<>());
+ }
+
+ @Test(expectedExceptions = InvalidDeviceException.class)
+ public void addNonInitializedDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ List deviceIdentifiers = new ArrayList<>();
+ deviceIdentifiers.add(deviceIdentifier);
+ this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND,
+ COMMAND_OPERATON_CODE),
+ deviceIdentifiers);
+ }
+
+ @Test
+ public void addNonAdminUserDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ startTenantFlowAsNonAdmin();
+ Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
+ Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
+ deviceIds);
+ PrivilegedCarbonContext.endTenantFlow();
+ validateOperationResponse(activity, ActivityStatus.Status.UNAUTHORIZED);
+ }
+
+ private void startTenantFlowAsNonAdmin() {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_USER);
}
@Test(dependsOnMethods = "addCommandOperation")
- public void addPolicyOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
- Activity activity = this.operationMgtService.addOperation(getOperation(new PolicyOperation(), Operation.Type.POLICY, POLICY_OPERATION_CODE),
+ public void addPolicyOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ Activity activity = this.operationMgtService.addOperation(getOperation(new PolicyOperation(),
+ Operation.Type.POLICY, POLICY_OPERATION_CODE),
this.deviceIds);
- validateOperationResponse(activity);
+ validateOperationResponse(activity, ActivityStatus.Status.PENDING);
}
@Test(dependsOnMethods = "addPolicyOperation")
- public void addConfigOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
- Activity activity = this.operationMgtService.addOperation(getOperation(new ConfigOperation(), Operation.Type.CONFIG, CONFIG_OPERATION_CODE),
+ public void addConfigOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ Activity activity = this.operationMgtService.addOperation(getOperation(new ConfigOperation(),
+ Operation.Type.CONFIG, CONFIG_OPERATION_CODE),
this.deviceIds);
- validateOperationResponse(activity);
+ validateOperationResponse(activity, ActivityStatus.Status.PENDING);
}
@Test(dependsOnMethods = "addConfigOperation")
- public void addProfileOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
- Activity activity = this.operationMgtService.addOperation(getOperation(new ProfileOperation(), Operation.Type.PROFILE, PROFILE_OPERATION_CODE),
+ public void addProfileOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException {
+ Activity activity = this.operationMgtService.addOperation(getOperation(new ProfileOperation(),
+ Operation.Type.PROFILE, PROFILE_OPERATION_CODE),
this.deviceIds);
- validateOperationResponse(activity);
+ validateOperationResponse(activity, ActivityStatus.Status.PENDING);
}
- private Operation getOperation(Operation operation, Operation.Type type, String code) {
+ static Operation getOperation(Operation operation, Operation.Type type, String code) {
String date = new SimpleDateFormat(DATE_FORMAT_NOW).format(new Date());
operation.setCreatedTimeStamp(date);
operation.setType(type);
@@ -156,11 +206,11 @@ public class OperationManagementTests{
return operation;
}
- private void validateOperationResponse(Activity activity) {
- Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation reponse for add operation only have - " +
+ private void validateOperationResponse(Activity activity, ActivityStatus.Status expectedStatus) {
+ Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation response for add operation only have - " +
activity.getActivityStatus().size());
for (ActivityStatus status : activity.getActivityStatus()) {
- Assert.assertEquals(status.getStatus(), ActivityStatus.Status.PENDING);
+ Assert.assertEquals(status.getStatus(), expectedStatus);
}
}
@@ -172,6 +222,18 @@ public class OperationManagementTests{
}
}
+ @Test(dependsOnMethods = "addProfileOperation", expectedExceptions = OperationManagementException.class)
+ public void getOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
+ try {
+ startTenantFlowAsNonAdmin();
+ for (DeviceIdentifier deviceIdentifier : deviceIds) {
+ this.operationMgtService.getOperations(deviceIdentifier);
+ }
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
@Test(dependsOnMethods = "getOperations")
public void getPendingOperations() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
for (DeviceIdentifier deviceIdentifier : deviceIds) {
@@ -180,6 +242,18 @@ public class OperationManagementTests{
}
}
+ @Test(dependsOnMethods = "getOperations", expectedExceptions = OperationManagementException.class)
+ public void getPendingOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
+ try {
+ startTenantFlowAsNonAdmin();
+ for (DeviceIdentifier deviceIdentifier : deviceIds) {
+ this.operationMgtService.getPendingOperations(deviceIdentifier);
+ }
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
@Test(dependsOnMethods = "getPendingOperations")
public void getPaginatedRequestAsAdmin() throws OperationManagementException {
PrivilegedCarbonContext.startTenantFlow();
@@ -197,31 +271,39 @@ public class OperationManagementTests{
PrivilegedCarbonContext.endTenantFlow();
}
- @Test(dependsOnMethods = "getPendingOperations")
+ @Test(dependsOnMethods = "getPendingOperations", expectedExceptions = OperationManagementException.class)
public void getPaginatedRequestAsNonAdmin() throws OperationManagementException {
- PrivilegedCarbonContext.startTenantFlow();
- PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
- PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_USER);
- PaginationRequest request = new PaginationRequest(1, 2);
- request.setDeviceType(DEVICE_TYPE);
- request.setOwner(ADMIN_USER);
- for (DeviceIdentifier deviceIdentifier : deviceIds) {
- try {
- this.operationMgtService.getOperations(deviceIdentifier, request);
- } catch (OperationManagementException ex) {
- if (ex.getMessage() == null){
- Assert.assertTrue(ex.getMessage().contains("User '" + NON_ADMIN_USER + "' is not authorized"));
+ try {
+ startTenantFlowAsNonAdmin();
+ PaginationRequest request = new PaginationRequest(1, 2);
+ request.setDeviceType(DEVICE_TYPE);
+ request.setOwner(ADMIN_USER);
+ for (DeviceIdentifier deviceIdentifier : deviceIds) {
+ try {
+ this.operationMgtService.getOperations(deviceIdentifier, request);
+ } catch (OperationManagementException ex) {
+ if (ex.getMessage() == null) {
+ Assert.assertTrue(ex.getMessage().contains("User '" + NON_ADMIN_USER + "' is not authorized"));
+ }
+ throw ex;
}
}
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
}
- PrivilegedCarbonContext.endTenantFlow();
}
@Test(dependsOnMethods = "getPaginatedRequestAsAdmin")
public void updateOperation() throws OperationManagementException {
+ //This is required to introduce a delay for the update operation of the device.
+ this.commandActivityBeforeUpdatedTimestamp = System.currentTimeMillis();
+ 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);
+ Assert.assertTrue(operations != null && operations.size() == 4);
Operation operation = (Operation) operations.get(0);
operation.setStatus(Operation.Status.COMPLETED);
operation.setOperationResponse("The operation is successfully completed");
@@ -229,4 +311,194 @@ public class OperationManagementTests{
List pendingOperations = this.operationMgtService.getPendingOperations(deviceIdentifier);
Assert.assertEquals(pendingOperations.size(), 3);
}
+
+ @Test(dependsOnMethods = "updateOperation", expectedExceptions = OperationManagementException.class)
+ public void updateOperationAsNonAdmin() throws OperationManagementException {
+ //This is required to introduce a delay for the update operation of the device.
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ignored) {
+ }
+ try {
+ DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
+ List operations = this.operationMgtService.getPendingOperations(deviceIdentifier);
+ Assert.assertTrue(operations != null && operations.size() == 3);
+ startTenantFlowAsNonAdmin();
+ Operation operation = (Operation) operations.get(0);
+ operation.setStatus(Operation.Status.COMPLETED);
+ operation.setOperationResponse("The operation is successfully completed, and updated by non admin!");
+ this.operationMgtService.updateOperation(deviceIdentifier, operation);
+ List pendingOperations = this.operationMgtService.getPendingOperations(deviceIdentifier);
+ Assert.assertEquals(pendingOperations.size(), 3);
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+
+ }
+
+ @Test(dependsOnMethods = "updateOperation")
+ public void getNextPendingOperation() throws OperationManagementException {
+ DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
+ Operation operation = this.operationMgtService.getNextPendingOperation(deviceIdentifier);
+ Assert.assertTrue(operation.getType().equals(Operation.Type.POLICY));
+ }
+
+ @Test(dependsOnMethods = "updateOperation", expectedExceptions = OperationManagementException.class)
+ public void getNextPendingOperationAsNonAdmin() throws OperationManagementException {
+ startTenantFlowAsNonAdmin();
+ try {
+ DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
+ this.operationMgtService.getNextPendingOperation(deviceIdentifier);
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
+ @Test(dependsOnMethods = "getNextPendingOperation")
+ public void getOperationByDeviceAndOperationId() throws OperationManagementException {
+ DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
+ String operationId = this.commandActivity.getActivityId().
+ replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "");
+ Operation operation = this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier,
+ Integer.parseInt(operationId));
+ Assert.assertTrue(operation.getStatus().equals(Operation.Status.COMPLETED));
+ Assert.assertTrue(operation.getType().equals(Operation.Type.COMMAND));
+ }
+
+ @Test(dependsOnMethods = "getNextPendingOperation", expectedExceptions = OperationManagementException.class)
+ public void getOperationByDeviceAndOperationIdNonAdmin() throws OperationManagementException {
+ startTenantFlowAsNonAdmin();
+ try {
+ DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
+ String operationId = this.commandActivity.getActivityId().
+ replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "");
+ this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier,
+ Integer.parseInt(operationId));
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
+ @Test(dependsOnMethods = "getOperationByDeviceAndOperationId")
+ public void getOperationsByDeviceAndStatus() throws OperationManagementException, DeviceManagementException {
+ DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
+ List operation = this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
+ Assert.assertEquals(operation.size(), 3);
+ }
+
+ @Test(dependsOnMethods = "getOperationByDeviceAndOperationId", expectedExceptions = OperationManagementException.class)
+ public void getOperationsByDeviceAndStatusByNonAdmin() throws OperationManagementException, DeviceManagementException {
+ startTenantFlowAsNonAdmin();
+ try {
+ DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
+ this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
+ @Test(dependsOnMethods = "getOperationsByDeviceAndStatus")
+ public void getOperation() throws OperationManagementException, DeviceManagementException {
+ String operationId = this.commandActivity.getActivityId().
+ replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "");
+ Operation operation = this.operationMgtService.getOperation(Integer.parseInt(operationId));
+ Assert.assertEquals(operation.getType(), Operation.Type.COMMAND);
+ }
+
+ @Test(dependsOnMethods = "getOperation")
+ public void getOperationActivity() throws OperationManagementException {
+ Activity activity = this.operationMgtService.getOperationByActivityId(commandActivity.getActivityId());
+ Assert.assertEquals(activity.getType(), Activity.Type.COMMAND);
+ Assert.assertEquals(activity.getActivityStatus().size(), this.deviceIds.size());
+ Assert.assertEquals(activity.getActivityStatus().get(0).getStatus(), ActivityStatus.Status.COMPLETED);
+ for (int i = 1; i < this.deviceIds.size(); i++) {
+ Assert.assertEquals(activity.getActivityStatus().get(i).getStatus(), ActivityStatus.Status.PENDING);
+ }
+ }
+
+ @Test(dependsOnMethods = "getOperationActivity")
+ public void getOperationByActivityIdAndDevice() throws OperationManagementException {
+ Activity activity = this.operationMgtService.
+ getOperationByActivityIdAndDevice(this.commandActivity.getActivityId(), this.deviceIds.get(0));
+ Assert.assertEquals(activity.getType(), Activity.Type.COMMAND);
+ Assert.assertEquals(activity.getActivityStatus().size(), 1);
+ Assert.assertEquals(activity.getActivityStatus().get(0).getStatus(), ActivityStatus.Status.COMPLETED);
+ }
+
+ @Test(dependsOnMethods = "getOperationActivity", expectedExceptions = OperationManagementException.class)
+ public void getOperationByActivityIdAndDeviceAsNonAdmin() throws OperationManagementException {
+ startTenantFlowAsNonAdmin();
+ try {
+ this.operationMgtService.
+ getOperationByActivityIdAndDevice(this.commandActivity.getActivityId(), this.deviceIds.get(0));
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
+ @Test(dependsOnMethods = "updateOperation")
+ public void getOperationUpdatedAfterWithLimitAndOffset() throws OperationManagementException, ParseException {
+ List operations = this.operationMgtService.getActivitiesUpdatedAfter
+ (this.commandActivityBeforeUpdatedTimestamp / 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 = "getOperationUpdatedAfterWithLimitAndOffset")
+ public void getActivityCountUpdatedAfter() throws OperationManagementException, ParseException {
+ int activityCount = this.operationMgtService.getActivityCountUpdatedAfter
+ (this.commandActivityBeforeUpdatedTimestamp / 1000);
+ Assert.assertTrue(activityCount == 1,
+ "The activities updated after the created should be 1");
+ }
+
+ @Test
+ public void getNotificationStrategy() {
+ Assert.assertTrue(this.operationMgtService.getNotificationStrategy() != null);
+ }
+
+ @Test(dependsOnMethods = {"getOperationByActivityIdAndDevice", "getOperationByActivityIdAndDeviceAsNonAdmin"})
+ public void getOperationForInactiveDevice() throws DeviceManagementException, OperationManagementException {
+ boolean disEnrolled = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
+ disenrollDevice(deviceIds.get(0));
+ Assert.assertTrue(disEnrolled);
+ List operations = this.operationMgtService.getOperations(deviceIds.get(0));
+ Assert.assertTrue(operations == null);
+ }
+
+ @Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class)
+ public void getPaginatedOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
+ try {
+ PaginationRequest request = new PaginationRequest(1, 2);
+ request.setDeviceType(DEVICE_TYPE);
+ request.setOwner(ADMIN_USER);
+ PaginationResult result = this.operationMgtService.getOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), request);
+ Assert.assertEquals(result.getRecordsFiltered(), 4);
+ Assert.assertEquals(result.getData().size(), 2);
+ Assert.assertEquals(result.getRecordsTotal(), 4);
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+
+ @Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class)
+ public void getPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException {
+ this.operationMgtService.getPendingOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE));
+ }
+
+ @Test(dependsOnMethods = "getPendingOperationDeviceForInvalidDevice", expectedExceptions = OperationManagementException.class)
+ public void getNextPendingOperationDeviceForInvalidDevice() throws DeviceManagementException, OperationManagementException {
+ this.operationMgtService.getNextPendingOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE));
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/ScheduledTaskOperationTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/ScheduledTaskOperationTests.java
new file mode 100644
index 0000000000..269563b3a8
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/ScheduledTaskOperationTests.java
@@ -0,0 +1,117 @@
+/*
+* Copyright (c) 2017, 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;
+
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
+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.core.TestDeviceManagementService;
+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.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.operation.mgt.CommandOperation;
+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.task.DeviceTaskManagerService;
+import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl;
+import org.wso2.carbon.ntask.core.internal.TasksDSComponent;
+import org.wso2.carbon.ntask.core.service.TaskService;
+import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.wso2.carbon.device.mgt.core.operation.OperationManagementTests.getOperation;
+
+/**
+ * This class tests the tasks based operations of {@link OperationManager}
+ */
+public class ScheduledTaskOperationTests extends BaseDeviceManagementTest {
+ private static final String DEVICE_TYPE = "OP_SCHEDULE_TEST_TYPE";
+ private static final String DEVICE_ID_PREFIX = "OP-SCHEDULED_TEST-DEVICE-ID-";
+ private static final String COMMAND_OPERATON_CODE = "COMMAND-TEST";
+ private static final int NO_OF_DEVICES = 5;
+ private static final String DS_TASK_COMPONENT_FIELD = "taskService";
+ private static final String CDM_CONFIG_LOCATION = "src" + File.separator + "test" + File.separator + "resources" +
+ File.separator + "config" + File.separator + "operation" + File.separator + "cdm-config.xml";
+
+ private List deviceIds = new ArrayList<>();
+ private OperationManager operationMgtService;
+
+ @BeforeClass
+ public void init() throws Exception {
+ for (int i = 0; i < NO_OF_DEVICES; i++) {
+ deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
+ }
+ List devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
+ DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
+ initTaskService();
+ deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
+ MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, COMMAND_OPERATON_CODE));
+ for (Device device : devices) {
+ deviceMgtService.enrollDevice(device);
+ }
+ List returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
+ for (Device device : returnedDevices) {
+ if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
+ throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
+ }
+ }
+ DeviceConfigurationManager.getInstance().initConfig(CDM_CONFIG_LOCATION);
+ TestNotificationStrategy notificationStrategy = new TestNotificationStrategy();
+ this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
+ }
+
+
+ private void initTaskService() throws NoSuchFieldException, IllegalAccessException {
+ TaskService taskService = new TestTaskServiceImpl();
+ DeviceManagementDataHolder.getInstance().setTaskService(taskService);
+ DeviceTaskManagerService deviceTaskManager = new DeviceTaskManagerServiceImpl();
+ DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(deviceTaskManager);
+ Field taskServiceField = TasksDSComponent.class.getDeclaredField(DS_TASK_COMPONENT_FIELD);
+ taskServiceField.setAccessible(true);
+ taskServiceField.set(null, Mockito.mock(TaskServiceImpl.class, Mockito.RETURNS_MOCKS));
+
+ }
+
+ @Test
+ public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
+ InvalidDeviceException, NoSuchFieldException {
+ Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
+ this.deviceIds);
+ Assert.assertEquals(activity.getActivityStatus(), null);
+ Assert.assertEquals(activity.getType(), Activity.Type.COMMAND);
+ }
+
+
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/TestNotificationStrategy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/TestNotificationStrategy.java
new file mode 100644
index 0000000000..c10fc0372f
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/TestNotificationStrategy.java
@@ -0,0 +1,58 @@
+/*
+* Copyright (c) 2017, 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;
+
+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.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
+
+import java.util.HashMap;
+
+public class TestNotificationStrategy implements NotificationStrategy {
+ private PushNotificationConfig pushNotificationConfig;
+
+ public TestNotificationStrategy(){
+ this.pushNotificationConfig = new PushNotificationConfig("TEST", true, new HashMap<>());
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
+
+ }
+
+ @Override
+ public NotificationContext buildContext() {
+ return null;
+ }
+
+ @Override
+ public void undeploy() {
+
+ }
+
+ @Override
+ public PushNotificationConfig getConfig() {
+ return pushNotificationConfig;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceTest.java
new file mode 100644
index 0000000000..a5ca659e31
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/permission/mgt/PermissionManagerServiceTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2017, 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.permission.mgt;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.testng.Assert;
+import org.testng.IObjectFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.ObjectFactory;
+import org.testng.annotations.Test;
+import org.wso2.carbon.device.mgt.common.permission.mgt.Permission;
+import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException;
+import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+
+import java.util.Properties;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+
+@PrepareForTest(PermissionUtils.class)
+public class PermissionManagerServiceTest {
+
+ private static final Log log = LogFactory.getLog(PermissionManagerServiceTest.class);;
+ private static final String PERMISSION_URL = "permission/admin/device-mgt/test/testPermission";
+ private static final String PERMISSION_PATH = "permission/admin/device-mgt/test/testPermission";
+ private static final String PERMISSION_METHOD = "ui.execute";
+ private static final String PERMISSION_NAME = "Test Permission";
+
+ //For create properties to retrieve permission.
+ private static final String HTTP_METHOD = "HTTP_METHOD";
+ private static final String URL = "URL";
+
+ private Permission permission;
+ private PermissionManagerService permissionManagerService;
+
+ @ObjectFactory
+ public IObjectFactory getObjectFactory() {
+ return new org.powermock.modules.testng.PowerMockObjectFactory();
+ }
+
+ @BeforeClass
+ public void init() throws RegistryException {
+ initMocks(this);
+ permissionManagerService = PermissionManagerServiceImpl.getInstance();
+ this.permission = new Permission();
+ permission.setName(PERMISSION_NAME);
+ permission.setPath(PERMISSION_PATH);
+ permission.setMethod(PERMISSION_METHOD);
+ permission.setUrl(PERMISSION_URL);
+ }
+
+ @Test (description = "Create a new permission in the permission tree.")
+ public void testCreatePermission() {
+ try {
+ PowerMockito.mockStatic(PermissionUtils.class);
+ PowerMockito.when(PermissionUtils.putPermission(permission)).thenReturn(true);
+
+ Assert.assertTrue(permissionManagerService.addPermission(permission));
+ } catch (PermissionManagementException e) {
+ log.error("Error creating permission " + e.getErrorMessage());
+ }
+ }
+
+ @Test (dependsOnMethods = {"testCreatePermission"}, description = "Test for retrieving the created permission " +
+ "from the permission tree.")
+ public void testGetPermission() throws PermissionManagementException {
+ Permission permission = permissionManagerService.getPermission(createProperties());
+
+ Assert.assertEquals(permission.getMethod(), PERMISSION_METHOD);
+ Assert.assertEquals(permission.getName(), PERMISSION_NAME);
+ Assert.assertEquals(permission.getPath(), PERMISSION_PATH);
+ Assert.assertEquals(permission.getUrl(), PERMISSION_URL);
+ }
+
+ @Test (dependsOnMethods = {"testCreatePermission"},
+ expectedExceptions = {PermissionManagementException.class},
+ expectedExceptionsMessageRegExp = "Resource URI/HTTP method is empty")
+ public void testGetPermissionError() throws PermissionManagementException {
+ Permission permission = permissionManagerService.getPermission(createErrorProperty());
+ }
+
+ /**
+ * Create a Property object which will be passed to getPermission method to retrieve a permission.
+ * @return : Property object which contains permission url and method.
+ * */
+ private Properties createProperties() {
+ Properties properties = new Properties();
+ properties.setProperty(URL, PERMISSION_URL);
+ properties.setProperty(HTTP_METHOD, PERMISSION_METHOD);
+ return properties;
+ }
+
+ /**
+ * Creates property object with empty properties.
+ * @return : Properties object with empty set of properties.
+ * */
+ private Properties createErrorProperty() {
+ Properties properties = new Properties();
+ properties.setProperty(URL, "");
+ properties.setProperty(HTTP_METHOD, "");
+ return properties;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java
index a48ce1d3a7..4cb26bc170 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java
@@ -18,66 +18,307 @@ package org.wso2.carbon.device.mgt.core.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
-import org.wso2.carbon.device.mgt.common.FeatureManager;
+import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
+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.TestDataHolder;
+import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
+import org.wso2.carbon.device.mgt.core.dto.DeviceType;
+import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
+import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
+import org.wso2.carbon.registry.core.config.RegistryContext;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
+import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-public class DeviceManagementProviderServiceTest {
+import java.io.InputStream;
+import java.util.List;
+
+public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
private DeviceManagementProviderService providerService;
+ private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
+ private static final String DEVICE_TYPE_2 = "RANDOM_DEVICE_TYPE";
- private static final String NON_EXISTENT_DEVICE_TYPE = "Test";
-
+ DeviceManagementProviderService deviceMgtService;
@BeforeClass
public void init() throws Exception {
- this.providerService = new DeviceManagementProviderServiceImpl();
+ DeviceConfigurationManager.getInstance().initConfig();
+ log.info("Initializing");
+
+ deviceMgtService = new DeviceManagementProviderServiceImpl();
+ DeviceManagementServiceComponent.notifyStartupListeners();
+ DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
+ DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
+ DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
+ DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
+ DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
+ deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
+ MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
+
}
-// @Test
-// public void testEnrollment() {
-// try {
-// DeviceManagementPluginRepository deviceManagementPluginRepository = new DeviceManagementPluginRepository();
-// TestDeviceManagementService testDeviceManagementService =
-// new TestDeviceManagementService(TestDataHolder.TEST_DEVICE_TYPE);
-// deviceManagementPluginRepository.addDeviceManagementProvider(testDeviceManagementService);
+ private RegistryService getRegistryService() throws RegistryException {
+ RealmService realmService = new InMemoryRealmService();
+ RegistryDataHolder.getInstance().setRealmService(realmService);
+ DeviceManagementDataHolder.getInstance().setRealmService(realmService);
+ InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
+ RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
+ context.setSetup(true);
+ return context.getEmbeddedRegistryService();
+ }
+
+ @Test
+ public void testGetAvailableDeviceTypes() {
+ try {
+ List deviceTypes = deviceMgtService.getDeviceTypes();
+ Assert.assertTrue(deviceTypes.size() > 0);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while getting the device types";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test
+ public void testNullDeviceEnrollment() {
+ try {
+ boolean enrollmentStatus = deviceMgtService.enrollDevice(null);
+ } catch (DeviceManagementException e) {
+ Assert.assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testSuccessfulDeviceEnrollment() {
+ Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
+ try {
+ boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
+ Assert.assertTrue(enrollmentStatus);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while enrolling device";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test(dependsOnMethods = "testSuccessfulDeviceEnrollment")
+ public void testIsEnrolled() {
+ try {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(TestDataHolder.initialDeviceIdentifier);
+ deviceIdentifier.setType(DEVICE_TYPE);
+ boolean enrollmentStatus = deviceMgtService.isEnrolled(deviceIdentifier);
+ Assert.assertTrue(enrollmentStatus);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while checking enrollment status.";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test
+ public void testIsEnrolledForNonExistingDevice() {
+ try {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId("34535235235235235");
+ deviceIdentifier.setType(DEVICE_TYPE);
+ boolean enrollmentStatus = deviceMgtService.isEnrolled(deviceIdentifier);
+ Assert.assertFalse(enrollmentStatus);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while checking enrollment status.";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test(expectedExceptions = DeviceManagementException.class)
+ public void testIsEnrolledForNullDevice() throws DeviceManagementException {
+ deviceMgtService.isEnrolled(null);
+ }
+
+ @Test
+ public void testNonExistentDeviceType() {
+ Device device = TestDataHolder.generateDummyDeviceData("abc");
+ try {
+ boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
+ Assert.assertFalse(enrollmentStatus);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while enrolling device";
+ Assert.fail(msg, e);
+ }
+ }
+
+
+ @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
+ public void testReEnrollmentofSameDeviceUnderSameUser() {
+ Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
+
+ try {
+ boolean enrollment = deviceMgtService.enrollDevice(device);
+
+ Assert.assertTrue(enrollment);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while enrolling device";
+ Assert.fail(msg, e);
+ }
+ }
+
+// @Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
+// public void testReEnrollmentofSameDeviceWithOtherUser() {
//
-// deviceManagementProviderService = new DeviceManagementProviderServiceImpl();
-// DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
+// EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
+// enrolmentInfo.setDateOfEnrolment(new Date().getTime());
+// enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
+// enrolmentInfo.setOwner("user1");
+// enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
+// enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
//
-// Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
-// boolean isEnrolled = deviceManagementProviderService.enrollDevice(device);
+// Device alternateDevice = TestDataHolder.generateDummyDeviceData("12345", DEVICE_TYPE,
+// enrolmentInfo);
//
-// Assert.assertEquals(isEnrolled, true, "Enrolment fail");
-// if (isEnrolled) {
-// TestDataHolder.initialTestDevice = device;
-// }
+// try {
+// Device retrievedDevice1 = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE));
+//
+// deviceMgtService.enrollDevice(alternateDevice);
+// Device retrievedDevice2 = deviceMgtService.getDevice(new DeviceIdentifier(alternateDevice
+// .getDeviceIdentifier(), alternateDevice.getType()));
//
+// log.info(retrievedDevice1.getEnrolmentInfo().getOwner());
+// log.info(retrievedDevice2.getEnrolmentInfo().getOwner());
+//
+// Assert.assertFalse(retrievedDevice1.getEnrolmentInfo().getOwner().equalsIgnoreCase
+// (retrievedDevice2.getEnrolmentInfo().getOwner()));
// } catch (DeviceManagementException e) {
-// String msg = "Error occurred while adding device type '" + TestDataHolder.TEST_DEVICE_TYPE + "'";
-// log.error(msg, e);
+// String msg = "Error Occured while enrolling device";
// Assert.fail(msg, e);
-// } finally {
-// DeviceManagementDAOFactory.closeConnection();
// }
// }
+
+ @Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
+ public void testDisenrollment() {
+ Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
+ try {
+ boolean disenrollmentStatus = deviceMgtService.disenrollDevice(new DeviceIdentifier
+ (device
+ .getDeviceIdentifier(),
+ device.getType()));
+ log.info(disenrollmentStatus);
+
+ Assert.assertTrue(disenrollmentStatus);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while enrolling device";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
+ public void testGetDeviceCount() {
+ try {
+ int count = deviceMgtService.getDeviceCount();
+ Assert.assertTrue(count > 0);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while getting the device count";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
+ public void testGetDeviceCountForUser() {
+ try {
+ int count = deviceMgtService.getDeviceCount(TestDataHolder.OWNER);
+ Assert.assertTrue(count > 0);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while getting the device count";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test
+ public void testGetDeviceCountForNonExistingUser() {
+ try {
+ int count = deviceMgtService.getDeviceCount("ABCD");
+ Assert.assertEquals(count, 0);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while getting the device count";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test(expectedExceptions = DeviceManagementException.class)
+ public void testGetDeviceCountForNullUser() throws DeviceManagementException {
+ deviceMgtService.getDeviceCount(null);
+ }
+
+ @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
+ public void testIsActive() {
+ try {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(TestDataHolder.initialDeviceIdentifier);
+ deviceIdentifier.setType(DEVICE_TYPE);
+ Assert.assertTrue(deviceMgtService.isActive(deviceIdentifier));
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while checking the device status";
+ Assert.fail(msg, e);
+ }
+ }
+
@Test
- public void testGetFeatureManager() {
+ public void testIsActiveForNonExistingDevice() {
+ try {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId("34535235235235235");
+ deviceIdentifier.setType("TEST_TYPE");
+ Assert.assertFalse(deviceMgtService.isActive(deviceIdentifier));
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while checking the device status";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
+ public void testSetActive() {
try {
- FeatureManager featureManager = providerService.getFeatureManager(NON_EXISTENT_DEVICE_TYPE);
- Assert.assertNull(featureManager, "Feature manager retrieved is null, which is expected as the " +
- "input device type provided is non existent");
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(TestDataHolder.initialDeviceIdentifier);
+ deviceIdentifier.setType(DEVICE_TYPE);
+ Assert.assertFalse(deviceMgtService.setActive(deviceIdentifier, true));
} catch (DeviceManagementException e) {
- String msg = "Error occurred while retrieving feature manager associated with device type '" +
- NON_EXISTENT_DEVICE_TYPE + "'";
- log.error(msg, e);
+ String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
-}
+ @Test
+ public void testSetActiveForNonExistingDevice() {
+ try {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId("34535235235235235");
+ deviceIdentifier.setType("TEST_TYPE");
+ Assert.assertFalse(deviceMgtService.setActive(deviceIdentifier, true));
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while updating the device status for non-existing device";
+ Assert.fail(msg, e);
+ }
+ }
+
+ @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
+ public void testGetDeviceEnrolledTenants() {
+ try {
+ List tenants = deviceMgtService.getDeviceEnrolledTenants();
+ Assert.assertEquals(tenants.size(), 1);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while updating the device status";
+ Assert.fail(msg, e);
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java
index 6a13e27b70..994ef33e8e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java
@@ -42,7 +42,7 @@ import java.util.List;
public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest {
- GroupManagementProviderService groupManagementProviderService;
+ private GroupManagementProviderService groupManagementProviderService;
private static final String DEFAULT_ADMIN_ROLE = "admin";
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
"/permission/device-mgt/user/groups"};
@@ -54,6 +54,7 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
RealmService realmService = new InMemoryRealmService();
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
realmService.getTenantManager().getSuperTenantDomain();
+ DeviceConfigurationManager.getInstance().initConfig();
}
@Test(expectedExceptions = {GroupManagementException.class, GroupAlreadyExistException.class})
@@ -71,24 +72,32 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test
public void createGroup() throws GroupManagementException, GroupAlreadyExistException {
-
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup1(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
-
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup2(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
-
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup3(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
-
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
}
@Test(dependsOnMethods = ("createGroup"))
public void updateGroup() throws GroupManagementException, GroupNotExistException {
-
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName());
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
}
+ @Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
+ public void getGroupNull() throws GroupManagementException, GroupNotExistException {
+ groupManagementProviderService.getGroup(null);
+ }
+
+ // Rename again to use in different place.
+ @Test(dependsOnMethods = ("updateGroup"))
+ public void updateGroupSecondTime() throws GroupManagementException, GroupNotExistException {
+ DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName() + "_UPDATED");
+ deviceGroup.setName(TestUtils.createDeviceGroup1().getName());
+ groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
+ }
+
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
public void updateGroupError() throws GroupManagementException, GroupNotExistException {
groupManagementProviderService.updateGroup(null, 1);
@@ -96,7 +105,6 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
public void updateGroupErrorNotExist() throws GroupManagementException, GroupNotExistException {
-
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup2().getName());
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
groupManagementProviderService.updateGroup(deviceGroup, 6);
@@ -141,8 +149,7 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
public void getGroupsByUsernameError() throws GroupManagementException {
- String username = null;
- groupManagementProviderService.getGroups(username);
+ groupManagementProviderService.getGroups((String) null);
}
@Test(dependsOnMethods = ("createGroup"))
@@ -158,12 +165,19 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
}
@Test(dependsOnMethods = ("createGroup"))
- public void getGroupsByUsernameAndPagination(String username, GroupPaginationRequest paginationRequest)
+ public void getGroupsByUsernameAndPagination()
throws GroupManagementException {
- PaginationResult result = groupManagementProviderService.getGroups(username, paginationRequest);
+ PaginationResult result = groupManagementProviderService.getGroups("admin", TestUtils.createPaginationRequest());
Assert.assertNotNull(result);
}
+
+ @Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
+ public void getGroupsByUsernameAndPaginationError()
+ throws GroupManagementException {
+ groupManagementProviderService.getGroups(null, TestUtils.createPaginationRequest());
+ }
+
@Test(dependsOnMethods = ("createGroup"))
public void getGroupCount() throws GroupManagementException {
int x = groupManagementProviderService.getGroupCount();
@@ -176,27 +190,28 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
Assert.assertNotNull(x);
}
-// @Test
-// public void manageGroupSharing() throws GroupManagementException, RoleDoesNotExistException, UserStoreException {
-// groupManagementProviderService.manageGroupSharing(0, null);
-// List newRoles = new ArrayList<>();
-// newRoles.add("TEST_ROLE_1");
-// newRoles.add("TEST_ROLE_2");
-// newRoles.add("TEST_ROLE_3");
-//
-// UserStoreManager userStoreManager =
-// DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
-// -1234).getUserStoreManager();
-// Permission[] permissions = new Permission[1];
-// Permission perm = new Permission("/admin/test/perm", "add");
-//// perm.setAction("execute.ui");
-//// perm.setResourceId("/admin/test/perm");
-// permissions[0] = perm;
-//
-// userStoreManager.addRole("TEST_ROLE_1", null, permissions);
-//
-// groupManagementProviderService.manageGroupSharing(1, newRoles);
-// }
+ @Test(dependsOnMethods = ("updateGroupSecondTime"))
+ public void manageGroupSharing() throws GroupManagementException, RoleDoesNotExistException, UserStoreException {
+ groupManagementProviderService.manageGroupSharing(0, null);
+ List newRoles = new ArrayList<>();
+ newRoles.add("TEST_ROLE_1");
+ newRoles.add("TEST_ROLE_2");
+ newRoles.add("TEST_ROLE_3");
+
+ UserStoreManager userStoreManager =
+ DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
+ -1234).getUserStoreManager();
+ Permission[] permissions = new Permission[1];
+ Permission perm = new Permission("/admin/test/perm", "add");
+ permissions[0] = perm;
+
+ userStoreManager.addRole("TEST_ROLE_1", null, permissions);
+ userStoreManager.addRole("TEST_ROLE_2", null, permissions);
+ userStoreManager.addRole("TEST_ROLE_3", null, permissions);
+
+ groupManagementProviderService.manageGroupSharing(groupManagementProviderService.getGroup(
+ TestUtils.createDeviceGroup1().getName()).getGroupId(), newRoles);
+ }
@Test(dependsOnMethods = ("createGroup"))
public void getRoles() throws GroupManagementException {
@@ -216,26 +231,30 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
Assert.assertEquals(0, x);
}
-// @Test(dependsOnMethods = ("createGroup"))
-// public void addDevices() throws GroupManagementException, DeviceNotFoundException {
-//
-// DeviceCacheConfiguration configuration = new DeviceCacheConfiguration();
-// configuration.setEnabled(false);
-//
-// DeviceConfigurationManager.getInstance().getDeviceManagementConfig().setDeviceCacheConfiguration(configuration);
-//
-// List list = TestUtils.getDeviceIdentifiersList();
-// groupManagementProviderService.addDevices(1, list);
-// groupManagementProviderService.addDevices(2, list);
-// groupManagementProviderService.addDevices(3, list);
-// }
-//
-// @Test(dependsOnMethods = ("addDevices"))
-// public void removeDevice() throws GroupManagementException, DeviceNotFoundException {
-// List list = TestUtils.getDeviceIdentifiersList();
-// groupManagementProviderService.removeDevice(2, list);
-// groupManagementProviderService.removeDevice(3, list);
-// }
+ @Test(dependsOnMethods = ("createGroup"))
+ public void addDevices() throws GroupManagementException, DeviceNotFoundException {
+
+ DeviceCacheConfiguration configuration = new DeviceCacheConfiguration();
+ configuration.setEnabled(false);
+
+ DeviceConfigurationManager.getInstance().getDeviceManagementConfig().setDeviceCacheConfiguration(configuration);
+ List list = TestUtils.getDeviceIdentifiersList();
+ groupManagementProviderService.addDevices(groupManagementProviderService.getGroup(
+ TestUtils.createDeviceGroup1().getName()).getGroupId(), list);
+ groupManagementProviderService.addDevices(groupManagementProviderService.getGroup(
+ TestUtils.createDeviceGroup2().getName()).getGroupId(), list);
+ groupManagementProviderService.addDevices(groupManagementProviderService.getGroup(
+ TestUtils.createDeviceGroup3().getName()).getGroupId(), list);
+ }
+
+ @Test(dependsOnMethods = ("addDevices"))
+ public void removeDevice() throws GroupManagementException, DeviceNotFoundException {
+ List list = TestUtils.getDeviceIdentifiersList();
+ groupManagementProviderService.removeDevice(groupManagementProviderService.getGroup(
+ TestUtils.createDeviceGroup2().getName()).getGroupId(), list);
+ groupManagementProviderService.removeDevice(groupManagementProviderService.getGroup(
+ TestUtils.createDeviceGroup3().getName()).getGroupId(), list);
+ }
@Test(dependsOnMethods = ("createGroup"))
public void getGroupsByUsernameAndPermissions() throws GroupManagementException {
@@ -243,18 +262,24 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
Assert.assertNotNull(groups);
}
-// @Test(dependsOnMethods = ("addDevices"))
-// public void getGroupsByDeviceIdentifier() throws GroupManagementException {
-// DeviceIdentifier identifier = new DeviceIdentifier();
-// identifier.setId("12345");
-// identifier.setType("Test");
-// List groups = groupManagementProviderService.getGroups(identifier);
-// Assert.assertNull(groups);
-// }
+ @Test(dependsOnMethods = ("addDevices"))
+ public void getGroupsByDeviceIdentifier() throws GroupManagementException {
+ DeviceIdentifier identifier = new DeviceIdentifier();
+ identifier.setId("12345");
+ identifier.setType("Test");
+ List groups = groupManagementProviderService.getGroups(identifier);
+ Assert.assertNotNull(groups);
+ }
@Test
public void createDefaultGroup() throws GroupManagementException {
groupManagementProviderService.createDefaultGroup("BYOD");
}
+
+ @Test(dependsOnMethods = ("createDefaultGroup"))
+ public void createDefaultGroupTwice() throws GroupManagementException {
+ groupManagementProviderService.createDefaultGroup("BYOD");
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManagerServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManagerServiceTest.java
new file mode 100644
index 0000000000..2db940a4ec
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManagerServiceTest.java
@@ -0,0 +1,124 @@
+package org.wso2.carbon.device.mgt.core.task;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.opensaml.xml.signature.P;
+import org.powermock.api.mockito.PowerMockito;
+import org.quartz.impl.StdSchedulerFactory;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.wso2.carbon.device.mgt.common.MonitoringOperation;
+import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
+import org.wso2.carbon.device.mgt.core.TestTaskServiceImpl;
+import org.wso2.carbon.device.mgt.core.TestUtils;
+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.permission.mgt.PermissionUtils;
+import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
+import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl;
+import org.wso2.carbon.ntask.common.TaskException;
+import org.wso2.carbon.ntask.core.TaskInfo;
+import org.wso2.carbon.ntask.core.TaskManager;
+import org.wso2.carbon.ntask.core.TaskUtils;
+import org.wso2.carbon.ntask.core.impl.QuartzCachedThreadPool;
+import org.wso2.carbon.ntask.core.internal.TasksDSComponent;
+import org.wso2.carbon.ntask.core.service.TaskService;
+import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+
+public class DeviceTaskManagerServiceTest {
+ private static final Log log = LogFactory.getLog(DeviceTaskManagerService.class);
+ private static final String TASK_TYPE = "DEVICE_MONITORING";
+ private DeviceTaskManagerService deviceTaskManagerService;
+ @Mock private TaskService taskService;
+
+ @BeforeClass public void init() throws Exception {
+ DeviceConfigurationManager.getInstance().initConfig();
+ log.info("Initializing Device Task Manager Service Test Suite");
+ this.taskService = new TestTaskServiceImpl();
+ DeviceManagementDataHolder.getInstance().setTaskService(this.taskService);
+ this.deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
+ DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(this.deviceTaskManagerService);
+ Field taskServiceField = TasksDSComponent.class.getDeclaredField("taskService");
+ taskServiceField.setAccessible(true);
+ taskServiceField.set(null, Mockito.mock(TaskServiceImpl.class, Mockito.RETURNS_MOCKS));
+ }
+
+ @Test(groups = "Device Task Manager")
+ public void testStartTask() {
+ try {
+ log.debug("Attempting to start task from testStartTask");
+ this.deviceTaskManagerService
+ .startTask(TestDataHolder.TEST_DEVICE_TYPE, generateValidMonitoringTaskConfig("DEVICE_INFO"));
+ TaskManager taskManager = this.taskService.getTaskManager(TASK_TYPE);
+ Assert.assertEquals(this.taskService.getRegisteredTaskTypes().size(), 1);
+ Assert.assertNotNull(taskManager
+ .getTask(TestDataHolder.TEST_DEVICE_TYPE + String.valueOf(TestDataHolder.SUPER_TENANT_ID)));
+ log.debug("Task Successfully started");
+ } catch (DeviceMgtTaskException | TaskException e) {
+ Assert.fail("Exception occurred when starting the task", e);
+ }
+ }
+
+ @Test(groups = "Device Task Manager", dependsOnMethods = "testStartTask")
+ public void testUpdateTask() {
+ try {
+ log.debug("Attempting to update task from testStartTask");
+ this.deviceTaskManagerService
+ .updateTask(TestDataHolder.TEST_DEVICE_TYPE, generateValidMonitoringTaskConfig("DEVICE_LOCATION"));
+ Assert.assertEquals(this.taskService.getRegisteredTaskTypes().size(), 1);
+ TaskManager taskManager = this.taskService.getTaskManager(TASK_TYPE);
+ Assert.assertEquals(taskManager.getAllTasks().size(), 1);
+ log.debug("Task Successfully updated");
+ } catch (DeviceMgtTaskException | TaskException e) {
+ Assert.fail("Exception occurred when updating the task", e);
+ }
+ }
+
+ @Test(groups = "Device Task Manager", dependsOnMethods = "testUpdateTask")
+ public void testStopTask() {
+ log.debug("Attempting to stop task from testStopTask");
+ try {
+ this.deviceTaskManagerService
+ .stopTask(TestDataHolder.TEST_DEVICE_TYPE, generateValidMonitoringTaskConfig("DEVICE_LOCATION"));
+ TaskManager taskManager = this.taskService.getTaskManager(TASK_TYPE);
+ Assert.assertEquals(taskManager.getAllTasks().size(), 0);
+ } catch (DeviceMgtTaskException | TaskException e) {
+ Assert.fail("Exception occurred when stopping the task", e);
+ }
+ }
+
+
+
+ private OperationMonitoringTaskConfig generateValidMonitoringTaskConfig(String operationConfig) {
+ OperationMonitoringTaskConfig validTaskConfig = new OperationMonitoringTaskConfig();
+ List operationList = new ArrayList<>();
+ MonitoringOperation operation = new MonitoringOperation();
+ operation.setTaskName(operationConfig);
+ operation.setRecurrentTimes(1);
+ operationList.add(operation);
+
+ validTaskConfig.setEnabled(true);
+ validTaskConfig.setFrequency(60000);
+ validTaskConfig.setMonitoringOperation(operationList);
+
+ return validTaskConfig;
+ }
+
+ private Properties getStandardQuartzProps() {
+ Properties result = new Properties();
+ result.put("org.quartz.scheduler.skipUpdateCheck", "true");
+ result.put("org.quartz.threadPool.class", QuartzCachedThreadPool.class.getName());
+ return result;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/TestTaskManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/TestTaskManagerImpl.java
new file mode 100644
index 0000000000..fcebed343c
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/task/TestTaskManagerImpl.java
@@ -0,0 +1,82 @@
+package org.wso2.carbon.device.mgt.core.task;
+
+import org.wso2.carbon.ntask.common.TaskException;
+import org.wso2.carbon.ntask.core.TaskInfo;
+import org.wso2.carbon.ntask.core.TaskManager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestTaskManagerImpl implements TaskManager {
+ private List registeredTasks;
+
+ public TestTaskManagerImpl() {
+ this.registeredTasks = new ArrayList<>();
+ }
+
+ @Override
+ public void initStartupTasks() throws TaskException {
+
+ }
+
+ @Override
+ public void scheduleTask(String taskName) throws TaskException {
+
+ }
+
+ @Override
+ public void rescheduleTask(String taskName) throws TaskException {
+
+ }
+
+ @Override
+ public boolean deleteTask(String taskName) throws TaskException {
+ for (TaskInfo task : this.registeredTasks) {
+ if (task.getName().contains(taskName)) {
+ this.registeredTasks.remove(task);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void pauseTask(String taskName) throws TaskException {
+
+ }
+
+ @Override
+ public void resumeTask(String taskName) throws TaskException {
+
+ }
+
+ @Override
+ public void registerTask(TaskInfo taskInfo) throws TaskException {
+ this.registeredTasks.add(taskInfo);
+ }
+
+ @Override
+ public TaskState getTaskState(String taskName) throws TaskException {
+ return null;
+ }
+
+ @Override
+ public TaskInfo getTask(String taskName) throws TaskException {
+ for (TaskInfo task : this.registeredTasks) {
+ if (task.getName().contains(taskName)) {
+ return task;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List getAllTasks() throws TaskException {
+ return this.registeredTasks;
+ }
+
+ @Override
+ public boolean isTaskScheduled(String taskName) throws TaskException {
+ return this.registeredTasks.size() > 0;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml
index 58ed4e6167..9097a645cb 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml
@@ -76,7 +76,7 @@
device caching for upto configured expiry-time in seconds. In clustered setup all worker nodes can enable the
device-cache to improve performance. -->
- true
+ false
600
+ STANDALONE
+
+
+ 2
+
+
+
+ org.wso2.carbon.ntask.core.impl.RoundRobinTaskLocationResolver
+
+
+
+
+
+
+ https://localhost:9448
+
+
+ https://localhost:9443
+
+
+ admin
+
+
+ admin
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/cdm-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/cdm-config.xml
new file mode 100644
index 0000000000..d4e1acb139
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/cdm-config.xml
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+
+ jdbc/DM_DS
+
+
+
+
+ 2
+ 2000
+ 2000
+ true
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider
+
+
+
+ false
+
+
+ https://localhost:9443
+ admin
+ admin
+
+
+ org.wso2.carbon.policy.mgt
+ true
+ 60000
+ 5
+ 8
+ 20
+
+
+
+ Simple
+
+
+
+ 20
+ 20
+ 20
+ 20
+ 20
+ 20
+
+
+
+ true
+
+
+
+ false
+ 600
+
+ 10000
+
+
+ false
+ 86400
+
+
+ false
+ false
+
+ BYOD,COPE
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml
index cdb5fdc20f..de6bac1872 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml
@@ -43,6 +43,10 @@
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
index 98b5295724..76f5646e97 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
@@ -22,7 +22,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
@@ -77,7 +77,37 @@
org.wso2.carbon.device.mgt.extensions.pull.notification
test
-
+
+ com.h2database.wso2
+ h2-database-engine
+ test
+
+
+ commons-dbcp.wso2
+ commons-dbcp
+ test
+
+
+ commons-pool.wso2
+ commons-pool
+ test
+
+
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.registry.extensions
+ test
+
+
+ org.wso2.carbon.registry
+ org.wso2.carbon.registry.indexing
+ test
+
+
+ org.slf4j
+ jcl-over-slf4j
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
index 8bf15732a0..b0c4f8312e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
@@ -433,8 +433,11 @@ public class DeviceTypeManager implements DeviceManager {
if (propertiesExist) {
boolean status;
Device existingDevice = this.getDevice(deviceIdentifier);
- existingDevice.setProperties(device.getProperties());
+ if (existingDevice == null) {
+ return false;
+ }
+ existingDevice.setProperties(device.getProperties());
try {
if (log.isDebugEnabled()) {
log.debug(
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
index a8f9141904..e705661daa 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
@@ -252,21 +252,24 @@ public class DeviceTypePluginDAOImpl implements PluginDAO {
}
private void initializeDbQueries() {
- selectDBQueryForGetDevice = "SELECT " + getDeviceTableColumnNames() + " FROM " +
- deviceDAODefinition.getDeviceTableName() + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?";
+ selectDBQueryForGetDevice =
+ "SELECT " + getDeviceTableColumnNames() + " FROM " + deviceDAODefinition.getDeviceTableName()
+ + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?";
- createDBqueryForAddDevice = "INSERT INTO " + deviceDAODefinition.getDeviceTableName() + "("
- + deviceDAODefinition.getPrimaryKey() + " , " + getDeviceTableColumnNames() + ") VALUES ("
- + getPreparedInputString(deviceDAODefinition.getColumnNames().size() + 1) + ")";
+ createDBqueryForAddDevice =
+ "INSERT INTO " + deviceDAODefinition.getDeviceTableName() + "(" + deviceDAODefinition.getPrimaryKey()
+ + " , " + getDeviceTableColumnNames() + ") VALUES (" + getPreparedInputString(
+ deviceDAODefinition.getColumnNames().size() + 1) + ")";
updateDBQueryForUpdateDevice = "UPDATE " + deviceDAODefinition.getDeviceTableName() + " SET "
- + getDeviceTableColumnNamesForUpdateQuery() + " WHERE " + deviceDAODefinition.getPrimaryKey()
- + " = ?";
+ + getDeviceTableColumnNamesForUpdateQuery() + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?";
- deleteDBQueryToRemoveDevicd = "DELETE FROM " + deviceDAODefinition.getDeviceTableName()
- + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?";
+ deleteDBQueryToRemoveDevicd =
+ "DELETE FROM " + deviceDAODefinition.getDeviceTableName() + " WHERE " + deviceDAODefinition
+ .getPrimaryKey() + " = ?";
- selectDBQueryToGetAllDevice = "SELECT " + getDeviceTableColumnNames() + " FROM "
- + deviceDAODefinition.getDeviceTableName();
+ selectDBQueryToGetAllDevice =
+ "SELECT " + getDeviceTableColumnNames() + "," + deviceDAODefinition.getPrimaryKey() + " FROM "
+ + deviceDAODefinition.getDeviceTableName();
}
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java
new file mode 100644
index 0000000000..8d69cac776
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2017, 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.extensions.device.type.template;
+
+import org.testng.annotations.BeforeSuite;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.context.RegistryType;
+import org.wso2.carbon.context.internal.OSGiDataHolder;
+import org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionDataHolder;
+import org.wso2.carbon.device.mgt.extensions.utils.Utils;
+import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration;
+import org.wso2.carbon.governance.api.util.GovernanceUtils;
+import org.wso2.carbon.registry.core.Registry;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.utils.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceArtifactConfiguration;
+
+/**
+ * This class handles all the setup that need to be done before starting to run the test cases.
+ */
+public class BaseExtensionsTest {
+
+ @BeforeSuite
+ public void init() throws RegistryException, IOException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ URL resourceUrl = classLoader.getResource("license.rxt");
+ String rxt = null;
+ File carbonHome;
+ if (resourceUrl != null) {
+ rxt = FileUtil.readFileToString(resourceUrl.getFile());
+ }
+ resourceUrl = classLoader.getResource("carbon-home");
+
+ if (resourceUrl != null) {
+ carbonHome = new File(resourceUrl.getFile());
+ System.setProperty("carbon.home", carbonHome.getAbsolutePath());
+ }
+
+ PrivilegedCarbonContext.getThreadLocalCarbonContext()
+ .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ RegistryService registryService = Utils.getRegistryService();
+ OSGiDataHolder.getInstance().setRegistryService(registryService);
+ UserRegistry systemRegistry =
+ registryService.getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
+
+ GovernanceArtifactConfiguration configuration = getGovernanceArtifactConfiguration(rxt);
+ List configurations = new ArrayList<>();
+ configurations.add(configuration);
+ GovernanceUtils.loadGovernanceArtifacts(systemRegistry, configurations);
+ Registry governanceSystemRegistry = registryService.getConfigSystemRegistry();
+ DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext()
+ .setRegistry(RegistryType.SYSTEM_CONFIGURATION, governanceSystemRegistry);
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java
index f261f98374..2e1b1a52ac 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java
@@ -31,6 +31,8 @@ import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
+import org.wso2.carbon.device.mgt.common.license.mgt.License;
+import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceStatusTaskConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
@@ -40,6 +42,7 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNot
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
import org.wso2.carbon.device.mgt.extensions.utils.Utils;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.xml.sax.SAXException;
import javax.xml.bind.JAXBException;
@@ -63,6 +66,8 @@ public class DeviceTypeManagerServiceTest {
private DeviceTypeConfiguration androidDeviceConfiguration;
private DeviceTypeManagerService rasberrypiDeviceTypeManagerService;
private DeviceTypeConfiguration rasberrypiDeviceConfiguration;
+ private DeviceTypeManagerService arduinoDeviceTypeManagerService;
+ private DeviceTypeConfiguration arduinoDeviceTypeConfiguration;
private Method setProvisioningConfig;
private Method setOperationMonitoringConfig;
private Method setDeviceStatusTaskPluginConfig;
@@ -73,7 +78,9 @@ public class DeviceTypeManagerServiceTest {
@BeforeTest
public void setup() throws NoSuchMethodException, SAXException, JAXBException, ParserConfigurationException,
DeviceTypeConfigurationException, IOException, NoSuchFieldException, IllegalAccessException,
- DeviceManagementException {
+ DeviceManagementException, RegistryException {
+ ClassLoader classLoader = getClass().getClassLoader();
+
setProvisioningConfig = DeviceTypeManagerService.class
.getDeclaredMethod("setProvisioningConfig", String.class, DeviceTypeConfiguration.class);
setProvisioningConfig.setAccessible(true);
@@ -117,7 +124,6 @@ public class DeviceTypeManagerServiceTest {
operationMonitoringConfigs.set(rasberrypiDeviceTypeManagerService, new OperationMonitoringTaskConfig());
initialOperationConfig.set(rasberrypiDeviceTypeManagerService, new InitialOperationConfig());
- ClassLoader classLoader = getClass().getClassLoader();
URL resourceUrl = classLoader.getResource("android.xml");
File androidConfiguration = null;
@@ -143,14 +149,10 @@ public class DeviceTypeManagerServiceTest {
configurationEntries.add(configurationEntry);
platformConfiguration.setConfiguration(configurationEntries);
-
- if (androidConfiguration != null) {
- // This is needed for DeviceTypeManager Initialization
- System.setProperty("carbon.home", androidConfiguration.getAbsolutePath());
- }
DeviceTypeManager deviceTypeManager = Mockito.mock(DeviceTypeManager.class);
when(deviceTypeManager.getConfiguration()).thenReturn(platformConfiguration);
deviceManager.set(androidDeviceTypeManagerService, deviceTypeManager);
+ setupArduinoDeviceType();
}
@Test(description = "This test cases tests the retrieval of provisioning config after providing the configurations "
@@ -164,7 +166,7 @@ public class DeviceTypeManagerServiceTest {
ProvisioningConfig provisioningConfig = androidDeviceTypeManagerService.getProvisioningConfig();
Assert.assertEquals(provisioningConfig.isSharedWithAllTenants(),
androidDeviceConfiguration.getProvisioningConfig().isSharedWithAllTenants(),
- "Provisioning configs " + "are not correctly set as per the configuration file provided");
+ "Provisioning configs are not correctly set as per the configuration file provided");
setProvisioningConfig.invoke(rasberrypiDeviceTypeManagerService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
rasberrypiDeviceConfiguration);
@@ -273,4 +275,42 @@ public class DeviceTypeManagerServiceTest {
rasberrypiDeviceConfiguration.getPullNotificationSubscriberConfig() != null);
}
+
+ @Test (description = "This test case tests the addition and retrieval of the license")
+ public void testGetLicense () throws LicenseManagementException {
+ License license = arduinoDeviceTypeManagerService.getDeviceManager().getLicense("en_Us");
+ Assert.assertEquals(license.getText(), arduinoDeviceTypeConfiguration.getLicense().getText(),
+ "The retrieved" + " license is different from added license");
+ license.setLanguage("eu");
+ license.setText("This is a EU License");
+ arduinoDeviceTypeManagerService.getDeviceManager().addLicense(license);
+ License newLicense = arduinoDeviceTypeManagerService.getDeviceManager().getLicense("eu");
+ Assert.assertEquals(newLicense.getText(), license.getText(),
+ "The retrieved license is different from added license");
+ Assert.assertNull(arduinoDeviceTypeManagerService.getDeviceManager().getLicense("tn"),
+ "License is retrieved for a non-existing language code");
+ }
+
+ /**
+ * Setting the Arduino Device Type
+ * @throws RegistryException Registry Exception
+ * @throws IOException IO Exception
+ * @throws SAXException SAX Exception
+ * @throws ParserConfigurationException Parser Configuration Exception
+ * @throws DeviceTypeConfigurationException Device Type Configuration Exception
+ * @throws JAXBException JAXB Exception
+ */
+ private void setupArduinoDeviceType()
+ throws RegistryException, IOException, SAXException, ParserConfigurationException,
+ DeviceTypeConfigurationException, JAXBException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ URL resourceUrl = classLoader.getResource("arduino.xml");
+ File raspberrypiConfiguration = null;
+ if (resourceUrl != null) {
+ raspberrypiConfiguration = new File(resourceUrl.getFile());
+ }
+ arduinoDeviceTypeConfiguration = Utils.getDeviceTypeConfiguration(raspberrypiConfiguration);
+ arduinoDeviceTypeManagerService = new DeviceTypeManagerService(new
+ DeviceTypeConfigIdentifier("arduino", "carbon.super"), arduinoDeviceTypeConfiguration);
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java
new file mode 100644
index 0000000000..137640f5d8
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 2017, 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.extensions.device.type.template;
+
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinition;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypeDAOHandler;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOImpl;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager;
+import org.wso2.carbon.device.mgt.extensions.utils.Utils;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.xml.sax.SAXException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class tests the {@link DeviceTypeManager}
+ */
+public class DeviceTypeManagerTest {
+ private DeviceTypeManager androidDeviceTypeManager;
+ private DeviceIdentifier nonExistingDeviceIdentifier;
+ private Device sampleDevice1;
+ private Device sampleDevice2;
+ private String androidDeviceType;
+
+ @BeforeTest(description = "Mocking the classes for testing")
+ public void setup() throws NoSuchFieldException, IllegalAccessException, IOException, SQLException, SAXException,
+ ParserConfigurationException, DeviceTypeConfigurationException, JAXBException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ URL resourceUrl = classLoader.getResource("android_h2.sql");
+ androidDeviceType = "android";
+ File androidDatabaseScript = null;
+ javax.sql.DataSource dataSource = null;
+ File carbonHome = new File("src/test/resources/carbon-home");
+
+ if (resourceUrl != null) {
+ androidDatabaseScript = new File(resourceUrl.getFile());
+ }
+ if (carbonHome.exists()) {
+ System.setProperty("carbon.home", carbonHome.getAbsolutePath());
+ }
+ resourceUrl = classLoader.getResource("android.xml");
+ File androidConfiguration = null;
+ if (resourceUrl != null) {
+ androidConfiguration = new File(resourceUrl.getFile());
+ }
+ DeviceTypeConfiguration androidDeviceConfiguration = Utils.getDeviceTypeConfiguration(androidConfiguration);
+ androidDeviceTypeManager = Mockito.mock(DeviceTypeManager.class, Mockito.CALLS_REAL_METHODS);
+
+ if (androidDatabaseScript != null) {
+ dataSource = Utils.createDataTables("deviceType", androidDatabaseScript.getAbsolutePath());
+ }
+ DeviceTypePluginDAOManager deviceTypePluginDAOManager = createMockDeviceTypePluginDAOManager(dataSource,
+ androidDeviceConfiguration);
+ Field deviceTypePluginDAOManagerField = DeviceTypeManager.class.getDeclaredField("deviceTypePluginDAOManager");
+ deviceTypePluginDAOManagerField.setAccessible(true);
+ deviceTypePluginDAOManagerField.set(androidDeviceTypeManager, deviceTypePluginDAOManager);
+
+ Field propertiesExist = DeviceTypeManager.class.getDeclaredField("propertiesExist");
+ propertiesExist.setAccessible(true);
+ Field deviceType = DeviceTypeManager.class.getDeclaredField("deviceType");
+ deviceType.setAccessible(true);
+ deviceType.set(androidDeviceTypeManager, androidDeviceType);
+ propertiesExist.set(androidDeviceTypeManager, true);
+ createDevice();
+ }
+
+ @Test(description = "This test case tests IsEnrolled method of the DeviceTypeManager",
+ dependsOnMethods = {"testEnrollDevice"})
+ public void testIsEnrolled() throws DeviceManagementException {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
+ sampleDevice2.getType());
+ Assert.assertTrue(!androidDeviceTypeManager.isEnrolled(nonExistingDeviceIdentifier),
+ "Device with " + "NON-Existing ID is not enrolled, but this shows as enrolled");
+ Assert.assertTrue(androidDeviceTypeManager.isEnrolled(deviceIdentifier),
+ "Enrolled device is shown as un-enrolled");
+ }
+
+ @Test(description = "This test case tests the getDevcie method of the DeviceTypeManager", dependsOnMethods =
+ {"testEnrollDevice"})
+ public void testGetDevice() throws DeviceManagementException {
+ DeviceIdentifier existingDeviceIdntifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
+ androidDeviceType);
+ Assert.assertNull(androidDeviceTypeManager.getDevice(nonExistingDeviceIdentifier),
+ "Non existing sampleDevice was retrieved");
+ Assert.assertNotNull(androidDeviceTypeManager.getDevice(existingDeviceIdntifier),
+ "Existing sampleDevice was retrieved");
+ }
+
+ @Test(description = "This test case tests the enrollment of the device")
+ public void testEnrollDevice() throws DeviceManagementException {
+ Assert.assertTrue(androidDeviceTypeManager.enrollDevice(sampleDevice1));
+ Assert.assertTrue(!androidDeviceTypeManager.enrollDevice(sampleDevice2));
+ }
+
+ @Test(description = "This test case tests the get all devices method of the DeviceTypeManager", dependsOnMethods
+ = {"testEnrollDevice"})
+ public void testGetAllDevices() throws DeviceManagementException {
+ Assert.assertEquals(androidDeviceTypeManager.getAllDevices().size(), 1,
+ "All the added devices are not fetched " + "from the database");
+ }
+
+ @Test(description = "This test case tests the addition of platform configuration and retrieval of the same")
+ public void testAddPlatformConfiguration() throws RegistryException, DeviceManagementException {
+ PlatformConfiguration platformConfiguration = new PlatformConfiguration();
+ platformConfiguration.setType(androidDeviceType);
+ androidDeviceTypeManager.saveConfiguration(platformConfiguration);
+ androidDeviceTypeManager.getConfiguration();
+ PlatformConfiguration actualPlatformConfiguration = androidDeviceTypeManager.getConfiguration();
+ Assert.assertNotNull(actualPlatformConfiguration,
+ "Platform Configuration saved and retrieved correctly in " + "DeviceType Manager");
+ Assert.assertEquals(actualPlatformConfiguration.getType(), androidDeviceType,
+ "Platform Configuration saved and " + "retrieved correctly in DeviceType Manager");
+ }
+
+ @Test (description = "This test case tests the getDefaultConfiguration method")
+ public void testGetDefaultConfiguration()
+ throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Method getDefaultConfiguration = DeviceTypeManager.class.getDeclaredMethod("getDefaultConfiguration");
+ getDefaultConfiguration.setAccessible(true);
+ Assert.assertNull(getDefaultConfiguration.invoke(androidDeviceTypeManager), "Default configuration file "
+ + "retrieved even without adding the configuration for the device type android");
+ }
+
+ @Test (description = "This test case tests the updateDeviceInfo method")
+ public void testUpdateDeviceInfo() throws DeviceManagementException {
+ DeviceIdentifier existingDeviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
+ androidDeviceType);
+ Assert.assertFalse(androidDeviceTypeManager.updateDeviceInfo(nonExistingDeviceIdentifier, sampleDevice1),
+ "Non-existing device was updated");
+ Assert.assertTrue(androidDeviceTypeManager.updateDeviceInfo(existingDeviceIdentifier, sampleDevice1),
+ "Existing device update failed");
+ }
+
+ /**
+ * To create a sample sampleDevice to add to DAO Layer.
+ */
+ private void createDevice() {
+ nonExistingDeviceIdentifier = new DeviceIdentifier("NON-EXISTING", androidDeviceType);
+ List list = new ArrayList<>();
+
+ String[] deviceTypeAttributes = { "FCM_TOKEN", "DEVICE_INFO", "IMEI", "IMSI", "OS_VERSION", "DEVICE_MODEL",
+ "VENDOR", "LATITUDE", "LONGITUDE", "SERIAL", "MAC_ADDRESS", "DEVICE_NAME", "DEVICE_NAME",
+ "OS_BUILD_DATE" };
+
+ for (String deviceTypeAttribute : deviceTypeAttributes) {
+ Device.Property property = new Device.Property();
+ property.setName(deviceTypeAttribute);
+ property.setValue(deviceTypeAttribute + "T");
+ list.add(property);
+ }
+
+ sampleDevice1 = new Device("testdevice", androidDeviceType, "test", "testdevice", null, null, list);
+ sampleDevice2 = new Device("testdevice1", androidDeviceType, "test", "testdevice", null, null, list);
+ }
+
+ /*
+ * To create a mock sampleDevice type plugin dao manager.
+ * @param dataSource DataSource for the DAO layer
+ * @param androidDeviceConfiguration Android Device Configuration
+ * @return Mock Device Type Plugin DAO Manager
+ * @throws NoSuchFieldException No Such Field Exception
+ * @throws IllegalAccessException Illegal Access Exception
+ */
+ private DeviceTypePluginDAOManager createMockDeviceTypePluginDAOManager(javax.sql.DataSource dataSource,
+ DeviceTypeConfiguration androidDeviceConfiguration) throws NoSuchFieldException, IllegalAccessException {
+ Field datasourceField = DeviceTypeDAOHandler.class.getDeclaredField("dataSource");
+ datasourceField.setAccessible(true);
+ Field currentConnection = DeviceTypeDAOHandler.class.getDeclaredField("currentConnection");
+ currentConnection.setAccessible(true);
+
+ DeviceTypeDAOHandler deviceTypeDAOHandler = Mockito
+ .mock(DeviceTypeDAOHandler.class, Mockito.CALLS_REAL_METHODS);
+ datasourceField.set(deviceTypeDAOHandler, dataSource);
+ currentConnection.set(deviceTypeDAOHandler, new ThreadLocal());
+
+ DeviceDAODefinition deviceDAODefinition = Utils.getDeviceDAODefinition(androidDeviceConfiguration);
+ DeviceTypePluginDAOImpl deviceTypePluginDAO = new DeviceTypePluginDAOImpl(deviceDAODefinition,
+ deviceTypeDAOHandler);
+
+ DeviceTypePluginDAOManager deviceTypePluginDAOManager = Mockito
+ .mock(DeviceTypePluginDAOManager.class, Mockito.CALLS_REAL_METHODS);
+ Field deviceTypePluginDAOField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypePluginDAO");
+ deviceTypePluginDAOField.setAccessible(true);
+ Field deviceTypeDAOHandlerField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypeDAOHandler");
+ deviceTypeDAOHandlerField.setAccessible(true);
+ deviceTypePluginDAOField.set(deviceTypePluginDAOManager, deviceTypePluginDAO);
+ deviceTypeDAOHandlerField.set(deviceTypePluginDAOManager, deviceTypeDAOHandler);
+
+ return deviceTypePluginDAOManager;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java
new file mode 100644
index 0000000000..461b9d9f72
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2017, 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.extensions.device.type.template;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.context.RegistryType;
+import org.wso2.carbon.context.internal.OSGiDataHolder;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
+import org.wso2.carbon.device.mgt.common.license.mgt.License;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Operation;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
+import org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionDataHolder;
+import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
+import org.wso2.carbon.device.mgt.extensions.utils.Utils;
+import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration;
+import org.wso2.carbon.governance.api.util.GovernanceUtils;
+import org.wso2.carbon.registry.core.Registry;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.utils.FileUtil;
+import org.xml.sax.SAXException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceArtifactConfiguration;
+
+/**
+ * This test case contains the tests for {@link HTTPDeviceTypeManagerService} and {@link DeviceTypeGeneratorServiceImpl}
+ */
+public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest {
+ private DeviceTypeMetaDefinition deviceTypeMetaDefinition;
+ private HTTPDeviceTypeManagerService httpDeviceTypeManagerService;
+ private DeviceTypeGeneratorServiceImpl deviceTypeGeneratorService;
+ private String androidSenseDeviceType = "androidsense";
+ private String sampleDeviceType = "sample";
+
+ @BeforeTest
+ public void setup() throws RegistryException, IOException, SAXException, ParserConfigurationException,
+ DeviceTypeConfigurationException, JAXBException {
+ createSampleDeviceTypeMetaDefinition();
+ httpDeviceTypeManagerService = new HTTPDeviceTypeManagerService(androidSenseDeviceType,
+ deviceTypeMetaDefinition);
+ deviceTypeGeneratorService = new DeviceTypeGeneratorServiceImpl();
+
+ }
+
+ @Test(description = "This test case tests the get type method of the device type manager")
+ public void testGetType() {
+ Assert.assertEquals(httpDeviceTypeManagerService.getType(), androidSenseDeviceType,
+ "HttpDeviceTypeManagerService returns" + " a different device type than initially provided");
+ }
+
+ @Test(description = "This test case tests the enrollment of newly added device type")
+ public void testEnrollDevice() throws DeviceManagementException {
+ String deviceId = "testdevice1";
+ Device sampleDevice1 = new Device(deviceId, androidSenseDeviceType, "test", "testdevice", null, null, null);
+ Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager().enrollDevice(sampleDevice1),
+ "Enrollment of " + androidSenseDeviceType + " device failed");
+ Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager()
+ .isEnrolled(new DeviceIdentifier(deviceId, androidSenseDeviceType)),
+ "Enrollment of " + androidSenseDeviceType + " device " + "failed");
+ }
+
+ @Test(description = "This test case tests the populate device management service method")
+ public void testPopulateDeviceManagementService() {
+ DeviceManagementService deviceManagementService = deviceTypeGeneratorService
+ .populateDeviceManagementService(sampleDeviceType, deviceTypeMetaDefinition);
+ Assert.assertEquals(deviceManagementService.getType(), sampleDeviceType,
+ "DeviceTypeGeneration for the " + "sample device type failed");
+ }
+
+ /**
+ * To create a sample device type meta defintion.
+ * @throws SAXException SAX Exception.
+ * @throws JAXBException JAXB Exception.
+ * @throws ParserConfigurationException ParserConfiguration Exception.
+ * @throws DeviceTypeConfigurationException DeviceTypeConfiguration Exception.
+ * @throws IOException IO Exception.
+ */
+ private void createSampleDeviceTypeMetaDefinition()
+ throws SAXException, JAXBException, ParserConfigurationException, DeviceTypeConfigurationException,
+ IOException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ URL resourceUrl = classLoader.getResource("android_sense.xml");
+ File androidSenseConfiguration = null;
+
+ if (resourceUrl != null) {
+ androidSenseConfiguration = new File(resourceUrl.getFile());
+ }
+ DeviceTypeConfiguration androidSenseDeviceTypeConfiguration = Utils
+ .getDeviceTypeConfiguration(androidSenseConfiguration);
+ PushNotificationProvider pushNotificationProvider = androidSenseDeviceTypeConfiguration
+ .getPushNotificationProvider();
+ PushNotificationConfig pushNotificationConfig = new PushNotificationConfig(pushNotificationProvider.getType(),
+ pushNotificationProvider.isScheduled(), null);
+ org.wso2.carbon.device.mgt.extensions.device.type.template.config.License license =
+ androidSenseDeviceTypeConfiguration.getLicense();
+ License androidSenseLicense = new License();
+ androidSenseLicense.setText(license.getText());
+ androidSenseLicense.setLanguage(license.getLanguage());
+
+ List configurationFeatues = androidSenseDeviceTypeConfiguration.getFeatures().getFeature();
+ List features = new ArrayList<>();
+
+ for (Feature feature : configurationFeatues) {
+ org.wso2.carbon.device.mgt.common.Feature commonFeature = new org.wso2.carbon.device.mgt.common.Feature();
+ commonFeature.setCode(feature.getCode());
+ commonFeature.setDescription(feature.getDescription());
+ commonFeature.setName(feature.getName());
+ features.add(commonFeature);
+ }
+
+ deviceTypeMetaDefinition = new DeviceTypeMetaDefinition();
+ deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig);
+ deviceTypeMetaDefinition.setDescription("This is android_sense");
+ deviceTypeMetaDefinition.setClaimable(true);
+ deviceTypeMetaDefinition.setLicense(androidSenseLicense);
+ deviceTypeMetaDefinition.setFeatures(features);
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java
index f19049015b..0e6c37cd1b 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java
@@ -19,12 +19,24 @@
package org.wso2.carbon.device.mgt.extensions.utils;
+import org.h2.jdbcx.JdbcDataSource;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
+import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Table;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinition;
+import org.wso2.carbon.registry.core.config.RegistryContext;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
+import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
import org.xml.sax.SAXException;
+import javax.sql.DataSource;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -34,6 +46,11 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
/**
* This class handles the test utility tasks.
@@ -73,4 +90,83 @@ public class Utils {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file);
}
+
+ /**
+ * To create the database tables for the particular device-type based on the scripts
+ *
+ * @param databaseName Name of the Database
+ * @param scriptFilePath Path of the SQL script File
+ * @throws IOException IO Exception
+ * @throws SQLException SQL Exception.
+ */
+ public static DataSource createDataTables(String databaseName, String scriptFilePath) throws IOException,
+ SQLException {
+ JdbcDataSource dataSource = new JdbcDataSource();
+ dataSource.setURL("jdbc:h2:mem:" + databaseName + ";DB_CLOSE_DELAY=-1");
+ dataSource.setUser("sa");
+ dataSource.setPassword("sa");
+
+ File file = new File(scriptFilePath);
+
+ final String LOAD_DATA_QUERY = "RUNSCRIPT FROM '" + file.getCanonicalPath() + "'";
+
+ Connection connection = null;
+ try {
+ connection = dataSource.getConnection();
+ Statement statement = connection.createStatement();
+ statement.execute(LOAD_DATA_QUERY);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+ return dataSource;
+ }
+
+ /**
+ * To get the DeviceDAO Definition from the DeviceTypeConfiguration.
+ *
+ * @param deviceTypeConfiguration Device Type Configuration which we need the DeviceDAO Definition
+ * @return DeviceDAO Definition of the particular devicetype
+ */
+ public static DeviceDAODefinition getDeviceDAODefinition(DeviceTypeConfiguration deviceTypeConfiguration) {
+ DeviceDetails deviceDetails = deviceTypeConfiguration.getDeviceDetails();
+ DeviceDAODefinition deviceDAODefinition = null;
+
+ if (deviceDetails != null) {
+ String tableName = deviceTypeConfiguration.getDeviceDetails().getTableId();
+ if (tableName != null && !tableName.isEmpty()) {
+ List tables = deviceTypeConfiguration.getDataSource().getTableConfig().getTable();
+ Table deviceDefinitionTable = null;
+ for (Table table : tables) {
+ if (tableName.equals(table.getName())) {
+ deviceDefinitionTable = table;
+ break;
+ }
+ }
+ if (deviceDefinitionTable != null) {
+ deviceDAODefinition = new DeviceDAODefinition(deviceDefinitionTable);
+ }
+ }
+ }
+ return deviceDAODefinition;
+ }
+
+ /**
+ * To get the registry service.
+ * @return RegistryService
+ * @throws RegistryException Registry Exception
+ */
+ public static RegistryService getRegistryService() throws RegistryException {
+ RealmService realmService = new InMemoryRealmService();
+ RegistryDataHolder.getInstance().setRealmService(realmService);
+ DeviceManagementDataHolder.getInstance().setRealmService(realmService);
+ InputStream is = Utils.class.getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
+ RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
+ context.setSetup(true);
+ return context.getEmbeddedRegistryService();
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_h2.sql
new file mode 100644
index 0000000000..9eed9b2d5e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_h2.sql
@@ -0,0 +1,31 @@
+
+-- -----------------------------------------------------
+-- Table `AD_DEVICE`
+-- -----------------------------------------------------
+CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
+ `DEVICE_ID` VARCHAR(45) NOT NULL,
+ `FCM_TOKEN` VARCHAR(1000) NULL DEFAULT NULL,
+ `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL,
+ `IMEI` VARCHAR(45) NULL DEFAULT NULL,
+ `IMSI` VARCHAR(45) NULL DEFAULT NULL,
+ `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
+ `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
+ `VENDOR` VARCHAR(45) NULL DEFAULT NULL,
+ `LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
+ `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
+ `SERIAL` VARCHAR(45) NULL DEFAULT NULL,
+ `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
+ `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
+ `OS_BUILD_DATE` VARCHAR(100) NULL DEFAULT NULL,
+ PRIMARY KEY (`DEVICE_ID`));
+
+-- -----------------------------------------------------
+-- Table `AD_FEATURE`
+-- -----------------------------------------------------
+CREATE TABLE IF NOT EXISTS `AD_FEATURE` (
+ `ID` INT NOT NULL AUTO_INCREMENT,
+ `CODE` VARCHAR(45) NOT NULL,
+ `NAME` VARCHAR(100) NULL,
+ `DESCRIPTION` VARCHAR(200) NULL,
+ PRIMARY KEY (`ID`));
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml
new file mode 100644
index 0000000000..fbc58a1115
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+ Add Keywords
+ Send keywords to the device
+
+
+ Add Threshold
+ Send Threshold to the device
+
+
+ Remove words
+ Remove Threshold from the device
+
+
+
+
+ true
+
+
+
+ true
+
+
+
+ en_US
+ 1.0.0
+ This is license text
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml
new file mode 100644
index 0000000000..eb12e9ccb3
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+ Control Bulb
+ Control Bulb on Arduino Uno
+
+
+ state
+
+
+
+
+
+
+ true
+
+
+
+ en_US
+ 1.0.0
+ This is license text
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/dbscripts/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/dbscripts/h2.sql
new file mode 100644
index 0000000000..f6b31c78d9
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/dbscripts/h2.sql
@@ -0,0 +1,429 @@
+CREATE TABLE IF NOT EXISTS REG_CLUSTER_LOCK (
+ REG_LOCK_NAME VARCHAR (20),
+ REG_LOCK_STATUS VARCHAR (20),
+ REG_LOCKED_TIME TIMESTAMP,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (REG_LOCK_NAME)
+);
+
+CREATE TABLE IF NOT EXISTS REG_LOG (
+ REG_LOG_ID INTEGER AUTO_INCREMENT,
+ REG_PATH VARCHAR (2000),
+ REG_USER_ID VARCHAR (31) NOT NULL,
+ REG_LOGGED_TIME TIMESTAMP NOT NULL,
+ REG_ACTION INTEGER NOT NULL,
+ REG_ACTION_DATA VARCHAR (500),
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (REG_LOG_ID, REG_TENANT_ID)
+);
+
+CREATE INDEX IF NOT EXISTS REG_LOG_IND_BY_REG_LOGTIME ON REG_LOG(REG_LOGGED_TIME, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_PATH(
+ REG_PATH_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_PATH_VALUE VARCHAR(2000) NOT NULL,
+ REG_PATH_PARENT_ID INT,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_PATH PRIMARY KEY(REG_PATH_ID, REG_TENANT_ID)
+);
+CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_NAME ON REG_PATH(REG_PATH_VALUE, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_PARENT_ID ON REG_PATH(REG_PATH_PARENT_ID, REG_TENANT_ID);
+
+
+CREATE TABLE IF NOT EXISTS REG_CONTENT (
+ REG_CONTENT_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_CONTENT_DATA LONGBLOB,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_CONTENT PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_CONTENT_HISTORY (
+ REG_CONTENT_ID INTEGER NOT NULL,
+ REG_CONTENT_DATA LONGBLOB,
+ REG_DELETED SMALLINT,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_CONTENT_HISTORY PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE (
+ REG_PATH_ID INTEGER NOT NULL,
+ REG_NAME VARCHAR(256),
+ REG_VERSION INTEGER NOT NULL AUTO_INCREMENT,
+ REG_MEDIA_TYPE VARCHAR(500),
+ REG_CREATOR VARCHAR(31) NOT NULL,
+ REG_CREATED_TIME TIMESTAMP NOT NULL,
+ REG_LAST_UPDATOR VARCHAR(31),
+ REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL,
+ REG_DESCRIPTION VARCHAR(1000),
+ REG_CONTENT_ID INTEGER,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ REG_UUID VARCHAR(100) NOT NULL,
+ CONSTRAINT PK_REG_RESOURCE PRIMARY KEY(REG_VERSION, REG_TENANT_ID)
+);
+
+ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT (REG_CONTENT_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_NAME ON REG_RESOURCE(REG_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_UUID ON REG_RESOURCE(REG_UUID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TENANT ON REG_RESOURCE(REG_TENANT_ID, REG_UUID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TYPE ON REG_RESOURCE(REG_TENANT_ID, REG_MEDIA_TYPE);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_HISTORY (
+ REG_PATH_ID INTEGER NOT NULL,
+ REG_NAME VARCHAR(256),
+ REG_VERSION INTEGER NOT NULL,
+ REG_MEDIA_TYPE VARCHAR(500),
+ REG_CREATOR VARCHAR(31) NOT NULL,
+ REG_CREATED_TIME TIMESTAMP NOT NULL,
+ REG_LAST_UPDATOR VARCHAR(31),
+ REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL,
+ REG_DESCRIPTION VARCHAR(1000),
+ REG_CONTENT_ID INTEGER,
+ REG_DELETED SMALLINT,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ REG_UUID VARCHAR(100) NOT NULL,
+ CONSTRAINT PK_REG_RESOURCE_HISTORY PRIMARY KEY(REG_VERSION, REG_TENANT_ID)
+);
+
+ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_PATHID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT_HISTORY (REG_CONTENT_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_NAME ON REG_RESOURCE_HISTORY(REG_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_COMMENT (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_COMMENT_TEXT VARCHAR(500) NOT NULL,
+ REG_USER_ID VARCHAR(31) NOT NULL,
+ REG_COMMENTED_TIME TIMESTAMP NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_COMMENT PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_COMMENT (
+ REG_COMMENT_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_COMMENT_ID FOREIGN KEY (REG_COMMENT_ID, REG_TENANT_ID) REFERENCES REG_COMMENT (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_COMMENT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_VERSION ON REG_RESOURCE_COMMENT(REG_VERSION, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_RATING (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_RATING INTEGER NOT NULL,
+ REG_USER_ID VARCHAR(31) NOT NULL,
+ REG_RATED_TIME TIMESTAMP NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_RATING PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_RATING (
+ REG_RATING_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_RATING_ID FOREIGN KEY (REG_RATING_ID, REG_TENANT_ID) REFERENCES REG_RATING (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_RATING(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_VERSION ON REG_RESOURCE_RATING(REG_VERSION, REG_TENANT_ID);
+
+
+CREATE TABLE IF NOT EXISTS REG_TAG (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_TAG_NAME VARCHAR(500) NOT NULL,
+ REG_USER_ID VARCHAR(31) NOT NULL,
+ REG_TAGGED_TIME TIMESTAMP NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_TAG PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_TAG (
+ REG_TAG_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_TAG_ID FOREIGN KEY (REG_TAG_ID, REG_TENANT_ID) REFERENCES REG_TAG (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_TAG(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_VERSION ON REG_RESOURCE_TAG(REG_VERSION, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_PROPERTY (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_NAME VARCHAR(100) NOT NULL,
+ REG_VALUE VARCHAR(1000),
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_PROPERTY PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_PROPERTY (
+ REG_PROPERTY_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_TAG_ID FOREIGN KEY (REG_PROPERTY_ID, REG_TENANT_ID) REFERENCES REG_PROPERTY (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_PROPERTY(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_VERSION ON REG_RESOURCE_PROPERTY(REG_VERSION, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_ASSOCIATION (
+ REG_ASSOCIATION_ID INTEGER AUTO_INCREMENT,
+ REG_SOURCEPATH VARCHAR (2000) NOT NULL,
+ REG_TARGETPATH VARCHAR (2000) NOT NULL,
+ REG_ASSOCIATION_TYPE VARCHAR (2000) NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (REG_ASSOCIATION_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_SNAPSHOT (
+ REG_SNAPSHOT_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_PATH_ID INTEGER NOT NULL,
+ REG_RESOURCE_NAME VARCHAR (256),
+ REG_RESOURCE_VIDS LONGBLOB NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_SNAPSHOT PRIMARY KEY(REG_SNAPSHOT_ID, REG_TENANT_ID)
+);
+
+ALTER TABLE REG_SNAPSHOT ADD CONSTRAINT IF NOT EXISTS REG_SNAPSHOT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_SNAPSHOT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_SNAPSHOT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+
+-- ################################
+-- USER MANAGER TABLES
+-- ################################
+
+CREATE TABLE IF NOT EXISTS UM_TENANT (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DOMAIN_NAME VARCHAR(255) NOT NULL,
+ UM_EMAIL VARCHAR(255),
+ UM_ACTIVE BOOLEAN DEFAULT FALSE,
+ UM_CREATED_DATE TIMESTAMP NOT NULL,
+ UM_USER_CONFIG LONGBLOB NOT NULL,
+ PRIMARY KEY (UM_ID),
+ UNIQUE(UM_DOMAIN_NAME));
+
+CREATE TABLE IF NOT EXISTS UM_DOMAIN(
+ UM_DOMAIN_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DOMAIN_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_DOMAIN_ID, UM_TENANT_ID)
+);
+
+CREATE INDEX IF NOT EXISTS INDEX_UM_TENANT_UM_DOMAIN_NAME ON UM_TENANT (UM_DOMAIN_NAME);
+
+CREATE TABLE IF NOT EXISTS UM_USER (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_USER_PASSWORD VARCHAR(255) NOT NULL,
+ UM_SALT_VALUE VARCHAR(31),
+ UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE,
+ UM_CHANGED_TIME TIMESTAMP NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ UNIQUE(UM_USER_NAME, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_USER_PASSWORD VARCHAR(255) NOT NULL,
+ UM_SALT_VALUE VARCHAR(31),
+ UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE,
+ UM_CHANGED_TIME TIMESTAMP NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ UNIQUE(UM_USER_NAME, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_USER_ATTRIBUTE (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ATTR_NAME VARCHAR(255) NOT NULL,
+ UM_ATTR_VALUE VARCHAR(1024),
+ UM_PROFILE_ID VARCHAR(255),
+ UM_USER_ID INTEGER,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID));
+
+CREATE INDEX IF NOT EXISTS UM_USER_ID_INDEX ON UM_USER_ATTRIBUTE(UM_USER_ID);
+
+CREATE TABLE IF NOT EXISTS UM_ROLE (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_NAME VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_SHARED_ROLE BOOLEAN DEFAULT FALSE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ UNIQUE(UM_ROLE_NAME, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_MODULE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_MODULE_NAME VARCHAR(100),
+ UNIQUE(UM_MODULE_NAME),
+ PRIMARY KEY(UM_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_MODULE_ACTIONS(
+ UM_ACTION VARCHAR(255) NOT NULL,
+ UM_MODULE_ID INTEGER NOT NULL,
+ PRIMARY KEY(UM_ACTION, UM_MODULE_ID),
+ FOREIGN KEY (UM_MODULE_ID) REFERENCES UM_MODULE(UM_ID) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS UM_PERMISSION (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_RESOURCE_ID VARCHAR(255) NOT NULL,
+ UM_ACTION VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_MODULE_ID INTEGER DEFAULT 0,
+ UNIQUE(UM_RESOURCE_ID,UM_ACTION, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+CREATE INDEX IF NOT EXISTS INDEX_UM_PERMISSION_UM_RESOURCE_ID_UM_ACTION ON UM_PERMISSION (UM_RESOURCE_ID, UM_ACTION, UM_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS UM_ROLE_PERMISSION (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_PERMISSION_ID INTEGER NOT NULL,
+ UM_ROLE_NAME VARCHAR(255) NOT NULL,
+ UM_IS_ALLOWED SMALLINT NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_DOMAIN_ID INTEGER,
+ FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_USER_PERMISSION (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_PERMISSION_ID INTEGER NOT NULL,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_IS_ALLOWED SMALLINT NOT NULL,
+ UNIQUE (UM_PERMISSION_ID, UM_USER_NAME, UM_TENANT_ID),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_USER_ROLE (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_USER_ID INTEGER NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_ROLE(UM_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+
+CREATE TABLE IF NOT EXISTS UM_SHARED_USER_ROLE(
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_USER_ID INTEGER NOT NULL,
+ UM_USER_TENANT_ID INTEGER NOT NULL,
+ UM_ROLE_TENANT_ID INTEGER NOT NULL,
+ UNIQUE(UM_USER_ID,UM_ROLE_ID,UM_USER_TENANT_ID, UM_ROLE_TENANT_ID),
+ FOREIGN KEY(UM_ROLE_ID,UM_ROLE_TENANT_ID) REFERENCES UM_ROLE(UM_ID,UM_TENANT_ID) ON DELETE CASCADE ,
+ FOREIGN KEY(UM_USER_ID,UM_USER_TENANT_ID) REFERENCES UM_USER(UM_ID,UM_TENANT_ID) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS UM_ACCOUNT_MAPPING(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER NOT NULL,
+ UM_USER_STORE_DOMAIN VARCHAR(100),
+ UM_ACC_LINK_ID INTEGER NOT NULL,
+ UNIQUE(UM_USER_NAME, UM_TENANT_ID, UM_USER_STORE_DOMAIN, UM_ACC_LINK_ID),
+ FOREIGN KEY (UM_TENANT_ID) REFERENCES UM_TENANT(UM_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID)
+);
+
+
+CREATE TABLE IF NOT EXISTS UM_DIALECT(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DIALECT_URI VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE(UM_DIALECT_URI, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+
+CREATE TABLE IF NOT EXISTS UM_CLAIM(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DIALECT_ID INTEGER NOT NULL,
+ UM_CLAIM_URI VARCHAR(255) NOT NULL,
+ UM_DISPLAY_TAG VARCHAR(255),
+ UM_DESCRIPTION VARCHAR(255),
+ UM_MAPPED_ATTRIBUTE_DOMAIN VARCHAR(255),
+ UM_MAPPED_ATTRIBUTE VARCHAR(255),
+ UM_REG_EX VARCHAR(255),
+ UM_SUPPORTED SMALLINT,
+ UM_REQUIRED SMALLINT,
+ UM_DISPLAY_ORDER INTEGER,
+ UM_CHECKED_ATTRIBUTE SMALLINT,
+ UM_READ_ONLY SMALLINT,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE(UM_DIALECT_ID, UM_CLAIM_URI,UM_MAPPED_ATTRIBUTE_DOMAIN, UM_TENANT_ID),
+ FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_PROFILE_CONFIG(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DIALECT_ID INTEGER,
+ UM_PROFILE_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+
+CREATE TABLE IF NOT EXISTS UM_HYBRID_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_HYBRID_USER_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255),
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_DOMAIN_ID INTEGER,
+ UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID,UM_DOMAIN_ID),
+ FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_HYBRID_ROLE(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_HYBRID_REMEMBER_ME (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_COOKIE_VALUE VARCHAR(1024),
+ UM_CREATED_TIME TIMESTAMP,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_SYSTEM_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255),
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_SYSTEM_ROLE(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml
new file mode 100644
index 0000000000..31752cf9b4
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml
@@ -0,0 +1,656 @@
+
+
+
+
+
+
+
+
+ ${product.name}
+
+
+ ${product.key}
+
+
+ ${product.version}
+
+
+
+
+
+
+
+
+ local:/${carbon.context}/services/
+
+
+
+
+
+
+ ${default.server.role}
+
+
+
+
+
+
+ org.wso2.carbon
+
+
+ /
+
+
+
+
+
+
+
+
+ 15
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+ 9999
+
+ 11111
+
+
+
+
+
+ 10389
+
+ 8000
+
+
+
+
+
+ 10500
+
+
+
+
+
+
+ org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory
+
+
+
+
+
+
+
+
+ java
+
+
+
+
+
+
+
+
+
+ false
+
+
+ false
+
+
+ 600
+
+
+
+ false
+
+
+
+
+
+
+
+ 30
+
+
+
+
+
+
+
+
+ 15
+
+
+
+
+
+ ${carbon.home}/repository/deployment/server/
+
+
+ 15
+
+
+ ${carbon.home}/repository/conf/axis2/axis2.xml
+
+
+ 30000
+
+
+ ${carbon.home}/repository/deployment/client/
+
+ ${carbon.home}/repository/conf/axis2/axis2_client.xml
+
+ true
+
+
+
+
+
+
+
+
+
+ admin
+ Default Administrator Role
+
+
+ user
+ Default User Role
+
+
+
+
+
+
+
+
+
+
+
+ ${carbon.home}/repository/resources/security/wso2carbon.jks
+
+ JKS
+
+ wso2carbon
+
+ wso2carbon
+
+ wso2carbon
+
+
+
+
+
+ ${carbon.home}/repository/resources/security/client-truststore.jks
+
+ JKS
+
+ wso2carbon
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UserManager
+
+
+ false
+
+
+
+
+
+
+ ${carbon.home}/tmp/work
+
+
+
+
+
+ true
+
+
+ 10
+
+
+ 30
+
+
+
+
+
+ 100
+
+
+
+ keystore
+ certificate
+ *
+
+ org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor
+
+
+
+
+ jarZip
+
+ org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor
+
+
+
+ dbs
+
+ org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor
+
+
+
+ tools
+
+ org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor
+
+
+
+ toolsAny
+
+ org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor
+
+
+
+
+
+
+ - info
+ org.wso2.carbon.core.transports.util.InfoProcessor
+
+
+ - wsdl
+ org.wso2.carbon.core.transports.util.Wsdl11Processor
+
+
+ - wsdl2
+ org.wso2.carbon.core.transports.util.Wsdl20Processor
+
+
+ - xsd
+ org.wso2.carbon.core.transports.util.XsdProcessor
+
+
+
+
+
+ false
+ false
+ true
+ svn
+ http://svnrepo.example.com/repos/
+ username
+ password
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${require.carbon.servlet}
+
+
+
+
+ true
+
+
+
+
+
+
+ default repository
+ ${p2.repo.url}
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+ true
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/registry.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/registry.xml
new file mode 100644
index 0000000000..0bb97a7dc9
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/registry.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+ wso2registry
+ false
+ true
+ /
+
+
+ jdbc:h2:./target/databasetest/CARBON_TEST
+
+ org.h2.Driver
+ 80
+ 60000
+ 5
+
+
+ false
+
+
+
+ true
+ true
+ true
+ true
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/license.rxt b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/license.rxt
new file mode 100644
index 0000000000..3fa9d8b7c9
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/license.rxt
@@ -0,0 +1,41 @@
+
+
+ /device-mgt/license/@{overview_name}/@{overview_language}/@{overview_version}
+ overview_name
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Name
+
+
+ Language
+
+
+ Version
+
+
+ Validity From
+
+
+ Validity To
+
+
+ License
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml
index 026b63df9a..bad5807be5 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml
@@ -23,7 +23,10 @@
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/user-test/user-mgt-registry-test.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/user-test/user-mgt-registry-test.xml
new file mode 100644
index 0000000000..bac4fc7667
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/user-test/user-mgt-registry-test.xml
@@ -0,0 +1,80 @@
+
+
+
+
+ true
+ admin
+
+ admin
+ admin
+
+ everyone
+ false
+ 500
+ jdbc:h2:target/databasetest/CARBON_TEST
+ org.h2.Driver
+ 50
+ 60000
+ 5
+
+
+ org.wso2.carbon.user.core.tenant.JDBCTenantManager
+ false
+ 100
+ false
+ default
+ SHA-256
+ true
+ true
+ true
+ false
+ ^[\S]{5,30}$
+ Password length should be between 5 to 30 characters
+
+ ^[\S]{5,30}$
+ [a-zA-Z0-9._-|//]{3,30}$
+ ^[\S]{3,30}$
+ ^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$
+ ^[\S]{3,30}$
+ true
+ 100
+ 100
+ false
+ false
+ true
+ ,
+ true
+
+
+ true
+
+
+
+ login
+ manage-configuration
+ manage-security
+ upload-services
+ manage-services
+ manage-lc-configuration
+ manage-mediation
+ monitor-system
+ delegate-identity
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml
index 29097d0a50..142656d5b1 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml
@@ -22,7 +22,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml
index b05db9d6e3..892c79bdef 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml
@@ -23,7 +23,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml
index c5256932de..2bce3a4937 100644
--- a/components/device-mgt/pom.xml
+++ b/components/device-mgt/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
diff --git a/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml b/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml
index 2a9b39a992..79bd5c63e5 100644
--- a/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml
+++ b/components/email-sender/org.wso2.carbon.email.sender.core/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
email-sender
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/email-sender/pom.xml b/components/email-sender/pom.xml
index 4d788c5633..0f4ae84fb1 100644
--- a/components/email-sender/pom.xml
+++ b/components/email-sender/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml
index d311cb6eea..c9ef8e709f 100644
--- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml
+++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml
@@ -22,13 +22,13 @@
org.wso2.carbon.devicemgt
identity-extensions
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.oauth.extensions
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - OAuth Extensions
http://wso2.org
diff --git a/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml
index 41918d73c2..0383643e61 100644
--- a/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml
+++ b/components/identity-extensions/org.wso2.carbon.identity.authenticator.backend.oauth/pom.xml
@@ -21,7 +21,7 @@
identity-extensions
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
4.0.0
diff --git a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml
index 6b879bfae0..da097cc0d1 100644
--- a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml
+++ b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
identity-extensions
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml
index 5e3f39f99a..052251804b 100644
--- a/components/identity-extensions/pom.xml
+++ b/components/identity-extensions/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml
index f26b522c1d..9e0d88c288 100644
--- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml
+++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
policy-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.devicemgt
org.wso2.carbon.complex.policy.decision.point
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - Policy Decision Point
WSO2 Carbon - Policy Decision Point
diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml
index 9165a0c8df..a3db6acb45 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml
+++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml
@@ -3,14 +3,14 @@
org.wso2.carbon.devicemgt
policy-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.devicemgt
org.wso2.carbon.policy.decision.point
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - Policy Decision Point
WSO2 Carbon - Policy Decision Point
diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml
index ad9309d956..0c9934edfe 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml
+++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml
@@ -3,7 +3,7 @@
org.wso2.carbon.devicemgt
policy-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
@@ -11,7 +11,7 @@
4.0.0
org.wso2.carbon.devicemgt
org.wso2.carbon.policy.information.point
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - Policy Information Point
WSO2 Carbon - Policy Information Point
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml
index eb6ad3f4f8..2479693c38 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
policy-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.devicemgt
org.wso2.carbon.policy.mgt.common
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - Policy Management Common
WSO2 Carbon - Policy Management Common
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml
index d71a8a2744..a385653328 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
policy-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.devicemgt
org.wso2.carbon.policy.mgt.core
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - Policy Management Core
WSO2 Carbon - Policy Management Core
diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml
index 00434beb70..a05f902b2d 100644
--- a/components/policy-mgt/pom.xml
+++ b/components/policy-mgt/pom.xml
@@ -23,13 +23,13 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
policy-mgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Policy Management Component
http://wso2.org
diff --git a/components/test-coverage/pom.xml b/components/test-coverage/pom.xml
index b51fc5cc9f..2e61e10ca4 100644
--- a/components/test-coverage/pom.xml
+++ b/components/test-coverage/pom.xml
@@ -21,7 +21,7 @@
carbon-devicemgt
org.wso2.carbon.devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml
index 9118025d84..b7d92092ad 100644
--- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml
+++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml
@@ -21,14 +21,14 @@
org.wso2.carbon.devicemgt
webapp-authenticator-framework
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.devicemgt
org.wso2.carbon.webapp.authenticator.framework
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
bundle
WSO2 Carbon - Web Application Authenticator Framework Bundle
WSO2 Carbon - Web Application Authenticator Framework Bundle
diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml
index ad52910f03..f328cb7f94 100644
--- a/components/webapp-authenticator-framework/pom.xml
+++ b/components/webapp-authenticator-framework/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
webapp-authenticator-framework
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Webapp Authenticator Framework
http://wso2.org
diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml
index e7c6ff2026..979f807736 100644
--- a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml
+++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml
@@ -21,14 +21,14 @@
org.wso2.carbon.devicemgt
apimgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.application.extension.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - API Management Application Extension Feature
http://wso2.org
This feature contains an implementation of a api application registration, which takes care of subscription
diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml
index f2818cff2c..1727335b98 100644
--- a/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml
+++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.handler.server.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
apimgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.handler.server.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Device Management - APIM handler Server Feature
http://wso2.org
This feature contains the handler for the api authentications
diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml
index 5b1b53d785..afcc65fd2d 100644
--- a/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml
+++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.integration.client.feature/pom.xml
@@ -21,13 +21,13 @@
org.wso2.carbon.devicemgt
apimgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.integration.client.feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - APIM Integration Client Feature
http://wso2.org
diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml
index a3c098a703..8ac5c0ed1c 100644
--- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml
+++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml
@@ -21,14 +21,14 @@
org.wso2.carbon.devicemgt
apimgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.apimgt.webapp.publisher.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - API Management Webapp Publisher Feature
http://wso2.org
This feature contains an implementation of a Tomcat lifecycle listener, which takes care of publishing
diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml
index 8a5ff55dfd..64876d735a 100644
--- a/features/apimgt-extensions/pom.xml
+++ b/features/apimgt-extensions/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
apimgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - API Management Extensions Feature
http://wso2.org
diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml
index 834b62d2c5..3bca50c433 100644
--- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml
+++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
certificate-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml
index 0d1075561c..1713cee3fa 100644
--- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml
+++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
certificate-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml
index 8b7bdf728e..6204881295 100644
--- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml
+++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
certificate-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.certificate.mgt.server.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Certificate Management Server Feature
http://wso2.org
This feature contains the core bundles required for back-end Certificate Management functionality
diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml
index 846ae3f266..11e835f04e 100644
--- a/features/certificate-mgt/pom.xml
+++ b/features/certificate-mgt/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
certificate-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Certificate Management Feature
http://wso2.org
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml
index 55ee459452..34706c191f 100644
--- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
device-mgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Device Type Deployer Feature
http://wso2.org
WSO2 Carbon - Device Type Deployer Feature
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml
index 65b256bde2..f74e054504 100644
--- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
device-mgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - FCM Based Push Notification Provider Feature
http://wso2.org
WSO2 Carbon - MQTT Based Push Notification Provider Feature
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml
index dc46549cfc..3d39b225a6 100644
--- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
device-mgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - MQTT Based Push Notification Provider Feature
http://wso2.org
WSO2 Carbon - MQTT Based Push Notification Provider Feature
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml
index 258907a6c6..9123ad52d5 100644
--- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
device-mgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - MQTT Based Push Notification Provider Feature
http://wso2.org
WSO2 Carbon - MQTT Based Push Notification Provider Feature
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml
index 8c02456c24..ca973cb899 100644
--- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
device-mgt-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - XMPP Based Push Notification Provider Feature
http://wso2.org
WSO2 Carbon - XMPP Based Push Notification Provider Feature
diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml
index 66fcb63dfc..d5b8233d86 100644
--- a/features/device-mgt-extensions/pom.xml
+++ b/features/device-mgt-extensions/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard.feature/pom.xml
index 7fa1f091eb..9fbf2fa3dd 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard.feature/pom.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard.feature/pom.xml
@@ -3,13 +3,13 @@
org.wso2.carbon.devicemgt
device-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.analytics.dashboard.feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Device Management Dashboard Analytics Feature
WSO2 Carbon - Device Management Dashboard Analytics Feature
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/pom.xml
index ec55f16f82..7353aa8dfb 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/pom.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
device-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.analytics.data.publisher.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Device Management Server Feature
http://wso2.org
This feature contains bundles related to device analytics data publisher
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml
index b1854928d9..65e7996ae9 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml
index 30d1c65dd5..aae4e73d71 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml
@@ -4,14 +4,14 @@
org.wso2.carbon.devicemgt
device-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.extensions.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Device Management Extensions Feature
http://wso2.org
This feature contains common extensions used by key device management functionalities
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml
index 77ae93c168..1662e096dc 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml
index 210d760e5f..29a3a17c8f 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
device-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.server.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Device Management Server Feature
http://wso2.org
This feature contains the core bundles required for Back-end Device Management functionality
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml
index fb01bc31f6..775e2a3c1a 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml
index 41154c7573..6055bd234c 100644
--- a/features/device-mgt/pom.xml
+++ b/features/device-mgt/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
diff --git a/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml b/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml
index 762d25747e..4492b69a56 100644
--- a/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml
+++ b/features/email-sender/org.wso2.carbon.email.sender.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
email-sender-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.email.sender.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Email Sender Feature
http://wso2.org
This feature contains the core bundles required for email sender related functionality
diff --git a/features/email-sender/pom.xml b/features/email-sender/pom.xml
index 97b184a916..7eec61ff26 100644
--- a/features/email-sender/pom.xml
+++ b/features/email-sender/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
email-sender-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Email Sender Feature
http://wso2.org
diff --git a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml
index 1ffa238ff9..2c89b1b15e 100644
--- a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml
+++ b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml
@@ -23,14 +23,14 @@
org.wso2.carbon.devicemgt
jwt-client-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.identity.jwt.client.extension.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - JWT Client Feature
http://wso2.org
This feature contains jwt client implementation from which we can get a access token using the jwt
diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml
index ca9604c881..fc663c5330 100644
--- a/features/jwt-client/pom.xml
+++ b/features/jwt-client/pom.xml
@@ -23,13 +23,13 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
jwt-client-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - JWT Client Extension Feature
http://wso2.org
diff --git a/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml
index a1c7045ded..0fdcbbe975 100644
--- a/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml
+++ b/features/oauth-extensions/org.wso2.carbon.device.mgt.oauth.extensions.feature/pom.xml
@@ -23,14 +23,14 @@
org.wso2.carbon.devicemgt
oauth-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.device.mgt.oauth.extensions.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Device Mgt OAuth Extensions Feature
http://wso2.org
This feature contains devicemgt related OAuth extensions
diff --git a/features/oauth-extensions/pom.xml b/features/oauth-extensions/pom.xml
index 51a5f737df..9162badcfb 100644
--- a/features/oauth-extensions/pom.xml
+++ b/features/oauth-extensions/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
oauth-extensions-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Device Management OAuth Extensions Feature
http://wso2.org
diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml
index a128a7529e..f0778a8abc 100644
--- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml
+++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml
@@ -23,14 +23,14 @@
org.wso2.carbon.devicemgt
policy-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.policy.mgt.server.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Policy Management Server Feature
http://wso2.org
This feature contains the core bundles required for Back-end Device Management functionality
diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml
index c51f85ab08..7a3a7b85b5 100644
--- a/features/policy-mgt/pom.xml
+++ b/features/policy-mgt/pom.xml
@@ -23,14 +23,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
policy-mgt-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Policy Management Feature
http://wso2.org
diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml
index cabea2b24e..0a745fa1e9 100644
--- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml
+++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
webapp-authenticator-framework-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../pom.xml
4.0.0
org.wso2.carbon.webapp.authenticator.framework.server.feature
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Webapp Authenticator Framework Server Feature
http://wso2.org
This feature contains the core bundles required for Back-end Device Management functionality
diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml
index ee627f9daa..452c97861b 100644
--- a/features/webapp-authenticator-framework/pom.xml
+++ b/features/webapp-authenticator-framework/pom.xml
@@ -22,14 +22,14 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
../../pom.xml
4.0.0
org.wso2.carbon.devicemgt
webapp-authenticator-framework-feature
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
pom
WSO2 Carbon - Webapp Authenticator Framework Feature
http://wso2.org
diff --git a/pom.xml b/pom.xml
index c30878f9e1..d9840a129b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
org.wso2.carbon.devicemgt
carbon-devicemgt
pom
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
WSO2 Carbon - Device Management - Parent
http://wso2.org
WSO2 Connected Device Manager Components
@@ -1532,6 +1532,30 @@
${power.mock.version}
test
+
+ org.powermock
+ powermock-module-testng
+ ${power.mock.version}
+ test
+
+
+ commons-dbcp.wso2
+ commons-dbcp
+ ${commons.dbcp.version}
+ test
+
+
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.registry.extensions
+ ${carbon.governance.version}
+ test
+
+
+ org.slf4j
+ jcl-over-slf4j
+
+
+
@@ -1827,7 +1851,7 @@
1.2.11.wso2v10
- 3.0.115-SNAPSHOT
+ 3.0.123-SNAPSHOT
4.4.8
@@ -1961,7 +1985,9 @@
0.7.8
0.7.5.201505241946
1.0b3
- 1.6.4
+ 1.7.0
+ 1.4.0.wso2v1
+