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 9a0f7fc578..23ba4b22fe 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
@@ -77,6 +77,7 @@
!org.wso2.carbon.policy.mgt.core.internal,
org.wso2.carbon.policy.mgt.core.*
+ *
@@ -204,11 +205,29 @@
h2-database-engine
test
+
+
+
+ commons-dbcp.wso2
+ commons-dbcp
+ 1.4.0.wso2v1
+ test
+
+
+
+ commons-pool.wso2
+ commons-pool
+ 1.5.6.wso2v1
+ test
+
+
+
org.mockito
mockito-core
2.10.0
+
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java
index 88af6eb50a..79626eb485 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java
@@ -232,7 +232,7 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.addDeviceGroupsToPolicy(policy);
}
- if (policy.getPolicyCriterias() != null) {
+ if (policy.getPolicyCriterias() != null && !policy.getPolicyCriterias().isEmpty()) {
List criteria = policy.getPolicyCriterias();
for (PolicyCriterion criterion : criteria) {
if (!policyDAO.checkCriterionExists(criterion.getName())) {
@@ -794,7 +794,7 @@ public class PolicyManagerImpl implements PolicyManager {
List deviceList = new ArrayList<>();
List deviceIds;
try {
- DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
+ DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance().getDeviceManagementService();
List allDevices = service.getAllDevices();
PolicyManagementDAOFactory.openConnection();
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
@@ -1092,9 +1092,9 @@ public class PolicyManagerImpl implements PolicyManager {
String type = null;
if (deviceIdentifiers.size() > 0) {
type = deviceIdentifiers.get(0).getType();
+ PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
+ this.getPolicyRevokeOperation(), deviceIdentifiers);
}
- PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
- this.getPolicyRevokeOperation(), deviceIdentifiers);
} catch (InvalidDeviceException e) {
String msg = "Invalid DeviceIdentifiers found.";
log.error(msg, e);
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java
index 482a205f65..9e86417fd0 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/BasePolicyManagementDAOTest.java
@@ -122,7 +122,7 @@ public abstract class BasePolicyManagementDAOTest {
}
}
- private void initSQLScript() throws Exception {
+ protected void initSQLScript() throws Exception {
Connection conn = null;
Statement stmt = null;
try {
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImplTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImplTest.java
new file mode 100644
index 0000000000..75e5bb69b8
--- /dev/null
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImplTest.java
@@ -0,0 +1,334 @@
+/*
+ * 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.policy.mgt.core;
+
+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.context.PrivilegedCarbonContext;
+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.DeviceNotFoundException;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
+import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
+import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
+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.policy.mgt.DeviceGroupWrapper;
+import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
+import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
+import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
+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.internal.DeviceManagementDataHolder;
+import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
+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.GroupManagementProviderService;
+import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
+import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
+import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
+import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask;
+import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
+import org.wso2.carbon.policy.mgt.core.mock.TypeADeviceManagementService;
+import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
+import org.wso2.carbon.policy.mgt.core.task.MonitoringTask;
+import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
+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.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
+public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
+
+ private static final Log log = LogFactory.getLog(PolicyManagerServiceImpl.class);
+
+ private static final String DEVICE_TYPE_A = "deviceTypeA";
+ private static final String DEVICE1 = "device1";
+ private static final String GROUP1 = "group1";
+ private static final String POLICY1 = "policy1";
+ private static final String POLICY1_FEATURE1_CODE = "DISALLOW_ADJUST_VOLUME";
+ private static final String ADMIN_USER = "admin";
+
+ private DeviceManagementProviderService deviceMgtService;
+ private GroupManagementProviderService groupMgtService;
+ private OperationManager operationManager;
+ private PolicyManagerService policyManagerService;
+
+ private Policy policy1;
+
+ @BeforeClass
+ public void init() throws Exception {
+ super.initSQLScript();
+
+ DeviceConfigurationManager.getInstance().initConfig();
+ log.info("Initializing policy tests");
+
+ deviceMgtService = new DeviceManagementProviderServiceImpl();
+ groupMgtService = new GroupManagementProviderServiceImpl();
+
+ DeviceManagementServiceComponent.notifyStartupListeners();
+ DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
+ DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
+ DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
+ DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(groupMgtService);
+ DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
+
+ PolicyEvaluationPoint policyEvaluationPoint = new SimplePolicyEvaluationTest();
+ PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint("Simple", policyEvaluationPoint);
+ PolicyManagementDataHolder.getInstance().setDeviceManagementService(deviceMgtService);
+ }
+
+ 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();
+ }
+
+ private boolean enrollDevice(String deviceName, String deviceType) {
+ boolean success = false;
+ EnrolmentInfo enrolmentInfo = new EnrolmentInfo(
+ ADMIN_USER, EnrolmentInfo.OwnerShip.BYOD, EnrolmentInfo.Status.ACTIVE);
+ Device device1 = new Device(deviceName, deviceType, deviceName, deviceName, enrolmentInfo, null, null);
+ try {
+ success = deviceMgtService.enrollDevice(device1);
+ } catch (DeviceManagementException e) {
+ String msg = "Failed to enroll a device.";
+ log.error(msg, e);
+ Assert.fail();
+ }
+ return success;
+ }
+
+ private void createDeviceGroup(String groupName) {
+ DeviceGroup deviceGroup = new DeviceGroup(groupName);
+ deviceGroup.setDescription(groupName);
+ deviceGroup.setOwner(ADMIN_USER);
+ try {
+ groupMgtService.createGroup(deviceGroup, null, null);
+ } catch (GroupAlreadyExistException | GroupManagementException e) {
+ String msg = "Failed to create group: " + groupName;
+ log.error(msg, e);
+ Assert.fail(msg);
+ }
+ }
+
+ private void addDeviceToGroup(DeviceIdentifier deviceIdentifier, String groupName) {
+ List groupDevices = new ArrayList<>();
+ groupDevices.add(deviceIdentifier);
+ try {
+ DeviceGroup group = groupMgtService.getGroup(groupName);
+ groupMgtService.addDevices(group.getGroupId(), groupDevices);
+ } catch (DeviceNotFoundException | GroupManagementException e) {
+ String msg = "Failed to add device " + deviceIdentifier.getId() + " to group " + groupName;
+ log.error(msg, e);
+ Assert.fail(msg);
+ }
+ }
+
+ @Test
+ public void addPolicy() throws DeviceManagementException, GroupManagementException, PolicyManagementException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ policyManagerService = new PolicyManagerServiceImpl();
+
+ deviceMgtService.registerDeviceType(new TypeADeviceManagementService());
+ operationManager = new OperationManagerImpl(DEVICE_TYPE_A);
+ enrollDevice(DEVICE1, DEVICE_TYPE_A);
+ createDeviceGroup(GROUP1);
+ DeviceGroup group1 = groupMgtService.getGroup(GROUP1);
+ addDeviceToGroup(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), GROUP1);
+
+ Profile profile = new Profile();
+ profile.setTenantId(tenantId);
+ profile.setCreatedDate(new Timestamp(System.currentTimeMillis()));
+ profile.setDeviceType(DEVICE_TYPE_A);
+
+ List profileFeatures = new ArrayList();
+ ProfileFeature profileFeature = new ProfileFeature();
+ profileFeature.setContent("{'enable':'true'}");
+ profileFeature.setDeviceType(DEVICE_TYPE_A);
+ profileFeature.setFeatureCode(POLICY1_FEATURE1_CODE);
+ profileFeatures.add(profileFeature);
+ profile.setProfileFeaturesList(profileFeatures);
+ profile.setProfileName("tp_profile1");
+ profile.setUpdatedDate(new Timestamp(System.currentTimeMillis()));
+
+ DeviceGroupWrapper deviceGroupWrapper = new DeviceGroupWrapper();
+ deviceGroupWrapper.setId(group1.getGroupId());
+ deviceGroupWrapper.setName(GROUP1);
+ deviceGroupWrapper.setOwner(ADMIN_USER);
+ deviceGroupWrapper.setTenantId(tenantId);
+ List deviceGroupWrappers = new ArrayList<>();
+ deviceGroupWrappers.add(deviceGroupWrapper);
+
+ policy1 = new Policy();
+ policy1.setPolicyName(POLICY1);
+ policy1.setDescription(POLICY1);
+ policy1.setProfile(profile);
+ policy1.setOwnershipType("BYOD");
+ policy1.setActive(false);
+ policy1.setRoles(new ArrayList<>());
+ policy1.setUsers(new ArrayList<>());
+ policy1.setCompliance(PolicyManagementConstants.ENFORCE);
+ policy1.setDeviceGroups(deviceGroupWrappers);
+ List devices = new ArrayList();
+ policy1.setDevices(devices);
+ policy1.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
+ policy1 = policyManagerService.addPolicy(policy1);
+
+ int policyCount = policyManagerService.getPolicyCount();
+ Assert.assertEquals(policyCount, 1, "Policy count should be 1");
+
+ List allPolicies = policyManagerService.getPolicies(DEVICE_TYPE_A);
+ boolean policyFound = false;
+ for (Policy policy : allPolicies) {
+ String policyName = policy.getPolicyName();
+ if (POLICY1.equals(policyName)) {
+ policyFound = true;
+ break;
+ }
+ }
+ Assert.assertTrue(policyFound, POLICY1 + " was not added.");
+ }
+
+ @Test(dependsOnMethods = "addPolicy")
+ public void activatePolicy() throws PolicyManagementException {
+ policyManagerService.getPAP().activatePolicy(policy1.getId());
+ Policy effectivePolicy = policyManagerService.getEffectivePolicy(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
+ Assert.assertEquals(effectivePolicy.getPolicyName(), POLICY1, POLICY1 + " was not activated for " + DEVICE1);
+ }
+
+ @Test(dependsOnMethods = "activatePolicy")
+ public void applyPolicy() throws PolicyManagementException, OperationManagementException {
+ new DelegationTask().execute();
+ Policy appliedPolicy = policyManagerService.getAppliedPolicyToDevice(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
+ Assert.assertEquals(appliedPolicy.getPolicyName(), POLICY1, POLICY1 + " was not applied on " + DEVICE1);
+
+ List extends Operation> operations = operationManager.getPendingOperations(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
+ boolean policyOperationFound = false;
+ for (Operation operation : operations) {
+ if (policyOperationFound) {
+ break;
+ }
+ if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) {
+ Object o = operation.getPayLoad();
+ if (o instanceof ArrayList) {
+ ArrayList profileOps = (ArrayList) o;
+ for (Object op : profileOps) {
+ if (op instanceof ProfileOperation) {
+ ProfileOperation profileOperation = (ProfileOperation) op;
+ if (POLICY1_FEATURE1_CODE.equals(profileOperation.getCode())) {
+ policyOperationFound = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ Assert.assertTrue(policyOperationFound, "Policy operation for " + POLICY1 + " was not added to " + DEVICE1);
+ }
+
+ @Test(dependsOnMethods = "applyPolicy")
+ public void checkCompliance() throws PolicyComplianceException {
+ new MonitoringTask().execute();
+
+ List complianceFeatures = new ArrayList<>();
+ ComplianceFeature complianceFeature = new ComplianceFeature();
+ ProfileFeature profileFeature = new ProfileFeature();
+ profileFeature.setContent("{'enable':'false'}");
+ profileFeature.setDeviceType(DEVICE_TYPE_A);
+ profileFeature.setFeatureCode(POLICY1_FEATURE1_CODE);
+ complianceFeature.setFeature(profileFeature);
+ complianceFeature.setFeatureCode(profileFeature.getFeatureCode());
+ complianceFeature.setMessage("Test message");
+ complianceFeature.setCompliance(true);
+ complianceFeatures.add(complianceFeature);
+ policyManagerService.checkCompliance(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), complianceFeatures);
+ boolean deviceCompliance = policyManagerService.isCompliant(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
+
+ Assert.assertTrue(deviceCompliance, "Policy was not compliant");
+ }
+
+ @Test(dependsOnMethods = "checkCompliance")
+ public void checkNonCompliance() throws PolicyComplianceException {
+ new MonitoringTask().execute();
+
+ List complianceFeatures = new ArrayList<>();
+ ComplianceFeature complianceFeature = new ComplianceFeature();
+ ProfileFeature profileFeature = new ProfileFeature();
+ profileFeature.setContent("{'enable':'false'}");
+ profileFeature.setDeviceType(DEVICE_TYPE_A);
+ profileFeature.setFeatureCode(POLICY1_FEATURE1_CODE);
+ complianceFeature.setFeature(profileFeature);
+ complianceFeature.setFeatureCode(profileFeature.getFeatureCode());
+ complianceFeature.setMessage("Test message");
+ complianceFeature.setCompliance(false);
+ complianceFeatures.add(complianceFeature);
+ policyManagerService.checkCompliance(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), complianceFeatures);
+ boolean deviceCompliance = policyManagerService.isCompliant(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
+
+ Assert.assertFalse(deviceCompliance, "Policy was compliant even though the response was not compliant");
+ }
+
+ @Test(dependsOnMethods = "inactivatePolicy")
+ public void updatePolicy() throws PolicyManagementException {
+ Policy policy1Temp = policyManagerService.getPAP().getPolicy(policy1.getId());
+ policy1Temp.setDescription("Updated policy1");
+ policy1Temp = policyManagerService.updatePolicy(policy1Temp);
+
+ Policy policy1Updated = policyManagerService.getPAP().getPolicy(policy1.getId());
+ Assert.assertEquals(policy1Updated.getDescription(), policy1Temp.getDescription(), "Policy was not updated successfully.");
+ }
+
+ @Test(dependsOnMethods = "checkNonCompliance")
+ public void inactivatePolicy() throws PolicyManagementException {
+ policyManagerService.getPAP().inactivatePolicy(policy1.getId());
+ new DelegationTask().execute();
+ Policy effectivePolicy = policyManagerService.getEffectivePolicy(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
+ Assert.assertNull(effectivePolicy, POLICY1 + " (after inactivation) is still applied for " + DEVICE1);
+ }
+
+ @Test(dependsOnMethods = "updatePolicy")
+ public void deletePolicy() throws PolicyManagementException {
+ policyManagerService.deletePolicy(policy1.getId());
+ Policy tempPolicy = policyManagerService.getPAP().getPolicy(policy1.getId());
+ Assert.assertNull(tempPolicy, "Policy was not deleted successfully");
+ }
+}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TestPolicyMonitoringManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TestPolicyMonitoringManager.java
new file mode 100644
index 0000000000..56ff683f03
--- /dev/null
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TestPolicyMonitoringManager.java
@@ -0,0 +1,60 @@
+/*
+ * 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.policy.mgt.core.mock;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
+import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
+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 java.util.ArrayList;
+import java.util.List;
+
+public class TestPolicyMonitoringManager implements PolicyMonitoringManager {
+
+ private static Log log = LogFactory.getLog(TestPolicyMonitoringManager.class);
+ @Override
+ public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
+ throws PolicyComplianceException {
+ if (log.isDebugEnabled()) {
+ log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
+ }
+ NonComplianceData nonComplianceData = new NonComplianceData();
+ if (response == null || policy == null) {
+ return nonComplianceData;
+ }
+
+ List complianceFeatures = (List) response;
+ List nonComplianceFeatures = new ArrayList<>();
+
+ for (ComplianceFeature complianceFeature : complianceFeatures) {
+ if (!complianceFeature.isCompliant()) {
+ nonComplianceFeatures.add(complianceFeature);
+ nonComplianceData.setStatus(false);
+ break;
+ }
+ }
+ nonComplianceData.setComplianceFeatures(nonComplianceFeatures);
+
+ return nonComplianceData;
+ }
+}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeADeviceManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeADeviceManagementService.java
new file mode 100644
index 0000000000..df070ab3c2
--- /dev/null
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeADeviceManagementService.java
@@ -0,0 +1,99 @@
+/*
+ * 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.policy.mgt.core.mock;
+
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.DeviceManager;
+import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
+import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
+import org.wso2.carbon.device.mgt.common.MonitoringOperation;
+import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
+import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
+import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
+import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+
+import java.util.ArrayList;
+
+public class TypeADeviceManagementService implements DeviceManagementService {
+
+ public static String DEVICE_TYPE = "deviceTypeA";
+
+ public TypeADeviceManagementService() {
+ super();
+ }
+
+ @Override
+ public void init() throws DeviceManagementException {
+
+ }
+
+ @Override
+ public String getType() {
+ return DEVICE_TYPE;
+ }
+
+ @Override
+ public OperationMonitoringTaskConfig getOperationMonitoringConfig() {
+ OperationMonitoringTaskConfig operationMonitoringTaskConfig = new OperationMonitoringTaskConfig();
+ operationMonitoringTaskConfig.setMonitoringOperation(new ArrayList());
+ return operationMonitoringTaskConfig;
+ }
+
+ @Override
+ public DeviceManager getDeviceManager() {
+ return new TypeADeviceManager();
+ }
+
+ @Override
+ public ApplicationManager getApplicationManager() {
+ return null;
+ }
+
+ @Override
+ public ProvisioningConfig getProvisioningConfig() {
+ return new ProvisioningConfig("carbon.super", true);
+ }
+
+ @Override
+ public PushNotificationConfig getPushNotificationConfig() {
+ return null;
+ }
+
+ @Override
+ public PolicyMonitoringManager getPolicyMonitoringManager() {
+ return new TestPolicyMonitoringManager();
+ }
+
+ @Override
+ public InitialOperationConfig getInitialOperationConfig() {
+ return null;
+ }
+
+ @Override
+ public PullNotificationSubscriber getPullNotificationSubscriber() {
+ return null;
+ }
+
+ @Override
+ public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() {
+ return null;
+ }
+}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeADeviceManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeADeviceManager.java
new file mode 100644
index 0000000000..60f93fa485
--- /dev/null
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeADeviceManager.java
@@ -0,0 +1,126 @@
+/*
+ * 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.policy.mgt.core.mock;
+
+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.DeviceManager;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+import org.wso2.carbon.device.mgt.common.FeatureManager;
+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 java.util.List;
+
+public class TypeADeviceManager implements DeviceManager {
+
+ @Override
+ public FeatureManager getFeatureManager() {
+ return null;
+ }
+
+ @Override
+ public boolean saveConfiguration(PlatformConfiguration configuration)
+ throws DeviceManagementException {
+ return false;
+ }
+
+ @Override public PlatformConfiguration getConfiguration() throws DeviceManagementException {
+ return null;
+ }
+
+ @Override
+ public boolean enrollDevice(Device device) throws DeviceManagementException {
+ return true;
+ }
+
+ @Override
+ public boolean modifyEnrollment(Device device) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public List getAllDevices() throws DeviceManagementException {
+ return null;
+ }
+
+ @Override
+ public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
+ return null;
+ }
+
+ @Override
+ public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
+ throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
+ throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status)
+ throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public License getLicense(String languageCode) throws LicenseManagementException {
+ return null;
+ }
+
+ @Override
+ public void addLicense(License license) throws LicenseManagementException {
+
+ }
+
+ @Override
+ public boolean requireDeviceAuthorization() {
+ return false;
+ }
+}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/dbscripts/h2.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/dbscripts/h2.sql
new file mode 100644
index 0000000000..f6b31c78d9
--- /dev/null
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/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/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml
index 0cd1564505..df960ed64e 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml
@@ -54,5 +54,11 @@
true
300
+
+ 100
+ 2000
+ 10
+ false
+
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/registry.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/registry.xml
index 01ffe07c15..191df68000 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/registry.xml
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/registry.xml
@@ -28,9 +28,19 @@
/
- jdbc/WSO2CarbonDB
+ jdbc:h2:./target/databasetest/CARBON_TEST
+
+ org.h2.Driver
+ 80
+ 60000
+ 5
+
+
+
+
+
+
+
+ true
+ admin
+
+ admin
+ admin
+
+ everyone
+ false
+ 500
+ jdbc:h2:target/databasetest/CARBON_TEST
+ org.h2.Driver
+ 50
+ 60000
+ 5
+
+
+ [\S]{5,30}$
+ [\\S]{5,30}
+ SELECT * FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SHA-256
+ true
+ false
+ false
+ wso2.com
+ true
+ 100
+
+
+ INSERT INTO UM_ROLE (UM_ROLE_NAME, UM_TENANT_ID) VALUES (?, ?)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.wso2.carbon.user.core.tenant.JDBCTenantManager
+
+
+ true
+
+
+
+ login
+ manage-configuration
+ manage-security
+ upload-services
+ manage-services
+ manage-lc-configuration
+ manage-mediation
+ monitor-system
+ delegate-identity
+
+
+