PolicyManagerServiceImpl implements PolicyManagerService { @Override public Policy addPolicy(Policy policy) throws PolicyManagementException { return policyAdministratorPoint.addPolicy(policy); } PolicyManagerServiceImpl(); @Override Profile addProfile(Profile profile); @Override Profile updateProfile(Profile profile); @Override Policy addPolicy(Policy policy); @Override Policy updatePolicy(Policy policy); @Override boolean deletePolicy(Policy policy); @Override boolean deletePolicy(int policyId); @Override Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier); @Override List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier); @Override List<Policy> getPolicies(String deviceType); @Override List<Feature> getFeatures(); @Override PolicyAdministratorPoint getPAP(); @Override PolicyInformationPoint getPIP(); @Override PolicyEvaluationPoint getPEP(); @Override TaskScheduleService getTaskScheduleService(); @Override int getPolicyCount(); @Override Policy getAppliedPolicyToDevice(
            DeviceIdentifier deviceIdentifier); @Override List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object
            deviceResponse); @Override boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object response); @Override NonComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier); @Override boolean isCompliant(DeviceIdentifier deviceIdentifier);  }
@Test public void addPolicy() throws DeviceManagementException, GroupManagementException, PolicyManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); policyManagerService = new PolicyManagerServiceImpl(); DeviceManagementService deviceManagementService = new TypeXDeviceManagementService(DEVICE_TYPE_A); deviceMgtService.registerDeviceType(deviceManagementService); operationManager = new OperationManagerImpl(DEVICE_TYPE_A, deviceManagementService); 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<ProfileFeature> profileFeatures = new ArrayList<ProfileFeature>(); 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<DeviceGroupWrapper> 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<Device> devices = new ArrayList<Device>(); 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<Policy> 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."); }