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 7c2f10ac9e..facda03430 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
@@ -122,6 +122,11 @@
+
+ org.apache.sling
+ org.apache.sling.testing.osgi-mock
+ test
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/policy/mgt/DefaultPolicyMonitoringManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/policy/mgt/DefaultPolicyMonitoringManager.java
index 3486446343..8a0bc9c292 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/policy/mgt/DefaultPolicyMonitoringManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/policy/mgt/DefaultPolicyMonitoringManager.java
@@ -54,7 +54,6 @@ public class DefaultPolicyMonitoringManager implements PolicyMonitoringManager {
if (!complianceFeature.isCompliant()) {
nonComplianceFeatures.add(complianceFeature);
nonComplianceData.setStatus(false);
- break;
}
}
nonComplianceData.setComplianceFeatures(nonComplianceFeatures);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
index 180e9717e3..50a90b11b4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
@@ -44,11 +44,18 @@ public class DeviceTypeExtensionServiceComponent {
private static final Log log = LogFactory.getLog(DeviceTypeExtensionServiceComponent.class);
protected void activate(ComponentContext ctx) {
- if (log.isDebugEnabled()) {
- log.debug("Activating DeviceType Deployer Service Component");
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Activating DeviceType Deployer Service Component");
+ }
+ ctx.getBundleContext()
+ .registerService(DeviceTypeGeneratorService.class, new DeviceTypeGeneratorServiceImpl(), null);
+ if (log.isDebugEnabled()) {
+ log.debug("Device Type Extension Service Component successfully activated");
+ }
+ } catch (Throwable e) {
+ log.error("Error occurred while initializing device type extension component ", e);
}
- ctx.getBundleContext().registerService(DeviceTypeGeneratorService.class, new DeviceTypeGeneratorServiceImpl()
- , null);
}
protected void deactivate(ComponentContext ctx) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponentTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponentTest.java
new file mode 100644
index 0000000000..e82e818b84
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponentTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.internal;
+
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.testng.annotations.Test;
+
+public class DeviceTypeExtensionServiceComponentTest {
+ @Test(description = "This test case tests the behaviour of the Service Component when there is a possible "
+ + "exception")
+ public void testActivateWithException() {
+ DeviceTypeExtensionServiceComponent deviceTypeExtensionServiceComponent = new
+ DeviceTypeExtensionServiceComponent();
+ deviceTypeExtensionServiceComponent.activate(null);
+ }
+
+ @Test(description = "This test case tests the behaviour of the Service Component when the pre-conditions are "
+ + "satisfied")
+ public void testActivateWithoutException() {
+ DeviceTypeExtensionServiceComponent deviceTypeExtensionServiceComponent = new
+ DeviceTypeExtensionServiceComponent();
+ deviceTypeExtensionServiceComponent.activate(MockOsgi.newComponentContext());
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java
index c5a6f419cd..803823d836 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java
@@ -24,10 +24,16 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.policy.mgt.Policy;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeConfigIdentifier;
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.policy.mgt.DefaultPolicyMonitoringManager;
import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceSchemaInitializer;
import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils;
import org.wso2.carbon.device.mgt.extensions.license.mgt.file.FileSystemBasedLicenseManager;
@@ -36,6 +42,8 @@ import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedL
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
/**
* This is a test case for testing common utilities used.
@@ -123,4 +131,26 @@ public class UtilsTest {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(4);
DeviceTypeUtils.getConfigurationRegistry();
}
+
+ @Test(description = "This test case tests DefaultPolicyMonitoringManager functionality")
+ public void testDefaultPolicyMonitoringManager() throws PolicyComplianceException {
+ List complianceFeatures = new ArrayList<>();
+ ComplianceFeature complianceFeature = new ComplianceFeature();
+ complianceFeature.setCompliance(true);
+ complianceFeatures.add(complianceFeature);
+
+ ComplianceFeature nonCompliant = new ComplianceFeature();
+ nonCompliant.setCompliance(false);
+ complianceFeatures.add(nonCompliant);
+ DefaultPolicyMonitoringManager policyMonitoringManager = new DefaultPolicyMonitoringManager();
+ NonComplianceData nonComplianceData = policyMonitoringManager
+ .checkPolicyCompliance(new DeviceIdentifier("android", "test"), null, complianceFeatures);
+ Policy policy = new Policy();
+ Assert.assertNull(nonComplianceData.getComplianceFeatures(),
+ "When policy is null policy manager returns a " + "list of non-compilance features");
+ nonComplianceData = policyMonitoringManager
+ .checkPolicyCompliance(new DeviceIdentifier("android", "test"), policy, complianceFeatures);
+ Assert.assertEquals(nonComplianceData.getComplianceFeatures().size(), 1,
+ "Non-compliant feature count does " + "not match with expected count");
+ }
}
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 661e7dd0dd..61740e5007 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
@@ -19,9 +19,7 @@
-
-
-
+
@@ -30,6 +28,7 @@
+