BalanaPolicyManager implements XACMLPolicyManager { @Activate protected void start(BundleContext context, Map<String, Object> props) { typeIRI = vf.createIRI(com.mobi.ontologies.rdfs.Resource.type_IRI); policyFileTypeIRI = vf.createIRI(PolicyFile.TYPE); PolicyManagerConfig config = Configurable.createConfigurable(PolicyManagerConfig.class, props); try { LOG.debug("Setting up policy file directory"); VirtualFile file = this.vfs.resolveVirtualFile(config.policyFileLocation()); if (!file.exists()) { if (config.createLocationIfNotExists()) { LOG.debug("Directory does not exist. Creating it now."); file.createFolder(); } else { throw new MobiException("Policy File Location " + config.policyFileLocation() + " does not exist"); } } else if (!file.isFolder()) { throw new MobiException("Policy File Location " + config.policyFileLocation() + " is not a directory"); } fileLocation = config.policyFileLocation(); } catch (VirtualFilesystemException e) { throw new MobiException(e); } loadPolicies(context); }  @Override XACMLPolicy createPolicy(PolicyType policyType); @Override Resource addPolicy(XACMLPolicy policy); @Override List<XACMLPolicy> getPolicies(PolicyQueryParams params); @Override Optional<XACMLPolicy> getPolicy(Resource policyId); @Override void updatePolicy(XACMLPolicy newPolicy); @Override void deletePolicy(Resource policyId); @Override Repository getRepository();  }
@Test public void startWithoutCacheTest() throws Exception { when(policyCache.getPolicyCache()).thenReturn(Optional.empty()); initializeRepo(); manager.start(context, props); verify(policyCache, atLeastOnce()).getPolicyCache(); verify(cache, times(0)).clear(); assertFalse(entries.containsKey(policyId.stringValue())); }
@Test(expected = MobiException.class) public void startIncorrectConfigTest() { props.put("policyFileLocation", ""); manager.start(context, props); }
@Test(expected = IllegalStateException.class) public void startWithMissingFileTest() { setUpMissingFileTest(); manager.start(context, props); }
@Test public void startWithCacheTest() throws Exception { initializeRepo(); manager.start(context, props); verify(policyCache, atLeastOnce()).getPolicyCache(); verify(cache).clear(); assertTrue(entries.containsKey(policyId.stringValue())); Policy policy = entries.get(policyId.stringValue()); assertTrue(policy instanceof BalanaPolicy); assertEquals(policyId, policy.getId()); }