PolicyManagerServiceImpl implements PolicyManagerService { @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { try { PolicyEvaluationPoint policyEvaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); Policy policy; if (policyEvaluationPoint != null) { policy = policyEvaluationPoint. getEffectivePolicy(deviceIdentifier); if (policy == null) { policyAdministratorPoint.removePolicyUsed(deviceIdentifier); return null; } this.getPAP().setPolicyUsed(deviceIdentifier, policy); } else { throw new PolicyEvaluationException("Error occurred while getting the policy evaluation point " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); } List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>(); deviceIdentifiers.add(deviceIdentifier); String type = null; if (deviceIdentifiers.size() > 0) { type = deviceIdentifiers.get(0).getType(); } PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type, PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers); return policy; } catch (InvalidDeviceException e) { String msg = "Error occurred while getting the effective policies for invalid DeviceIdentifiers"; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (PolicyEvaluationException e) { String msg = "Error occurred while getting the effective policies from the PEP service for device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (OperationManagementException e) { String msg = "Error occurred while adding the effective feature to database." + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new PolicyManagementException(msg, e); } } 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(description = "Get active policy but there is no EvaluationPoint define for device yet should be return PolicyManagement exception" + " caused by PolicyEvaluationException",dependsOnMethods = "addPolicy",expectedExceptions = PolicyManagementException.class) public void getActivePolicyForDeviceWithNoEvaluationEPDefine() throws Exception { PolicyEvaluationPoint policyEvaluationPoint = null; try{ policyEvaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint("Simple", null); policyManagerService.getEffectivePolicy(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A)); }catch (Exception e){ Assert.assertTrue(e.getCause() instanceof PolicyEvaluationException); throw e; }finally { PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint("Simple", policyEvaluationPoint); } }
@Test(description = "Get active policy but no any policy applied for device yet should be return PolicyManagement exception" + " caused by PolicyEvaluationException",dependsOnMethods = "addPolicy",expectedExceptions = PolicyManagementException.class) public void getActivePolicyForDeviceWithNoAppliedPolicy() throws Exception { try{ policyManagerService.getEffectivePolicy(new DeviceIdentifier(DEVICE_WITHOUT_POLICY, DEVICE_TYPE_B)); }catch (Exception e){ Assert.assertTrue(e.getCause() instanceof PolicyEvaluationException); throw e; } }
@Test(description = "Get active policy if enrollment status removed should be return PolicyManagement exception" + " caused by InvalidDeviceException",dependsOnMethods = "addPolicy",expectedExceptions = PolicyManagementException.class) public void getActivatePolicyForEnrolmentStatusAsRemoved() throws Exception { EnrolmentInfo.Status status =null; try{ Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). getDevice(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), false); status = device.getEnrolmentInfo().getStatus(); device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED); policyManagerService.getEffectivePolicy(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A)); }catch (Exception e){ Assert.assertTrue(e.getCause() instanceof InvalidDeviceException); throw e; }finally { if(status != null){ DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). getDevice(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), false).getEnrolmentInfo().setStatus(status); } } }