@Test @ExtendWith(TemporaryFolderExtension.class) void testLoad(TemporaryFolder temporaryFolder) throws IOException { PolicyAndFolderLoader policyAndFolderLoader = new PolicyAndFolderLoader(policyConverterRegistry, fileUtils, new IdGenerator(), JsonFileUtils.INSTANCE); Mockito.when(fileUtils.getFileAsString(Mockito.any(File.class))).thenReturn("policy-content"); File policyFolder = temporaryFolder.createDirectory("policy"); File a = new File(policyFolder, "a"); Assert.assertTrue(a.mkdir()); File b = new File(a, "b"); Assert.assertTrue(b.mkdir()); File c = new File(b, "c"); Assert.assertTrue(c.mkdir()); File policy = new File(c, "policy.xml"); Files.touch(policy); File configFolder = temporaryFolder.createDirectory("config"); File policyDep = new File(configFolder, "policies.yml"); Map<String, PolicyMetadata> policyMetadataMap = new HashMap<>(); PolicyMetadata policyMetadata = new PolicyMetadata(); policyMetadata.setPath("a/b/c"); policyMetadata.setName("policy"); policyMetadata.setTag("tag"); policyMetadata.setType("include"); Set<Dependency> dependencySet = new HashSet<>(); dependencySet.add(new Dependency("jdbc", EntityTypes.JDBC_CONNECTION)); policyMetadata.setUsedEntities(dependencySet); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); JsonFileUtils.INSTANCE.createFile(policyMetadataMap, policyDep.toPath()); Bundle bundle = new Bundle(); policyAndFolderLoader.load(bundle, temporaryFolder.getRoot()); Assert.assertNotNull(bundle.getFolders().get("")); Assert.assertNotNull(bundle.getFolders().get("a/")); Assert.assertNotNull(bundle.getFolders().get("a/b/")); Folder parentFolder = bundle.getFolders().get("a/b/c/"); Assert.assertNotNull(parentFolder); Policy loadedPolicy = bundle.getPolicies().get("a/b/c/policy"); Assert.assertNotNull(loadedPolicy); Assert.assertEquals(parentFolder, loadedPolicy.getParentFolder()); Map<Dependency, List<Dependency>> dependencyListMap = bundle.getDependencyMap(); Assert.assertNotNull(dependencyListMap); List<Dependency> dependencyList = dependencyListMap.get(new Dependency("policy", EntityTypes.POLICY_TYPE)); Assert.assertNotNull(dependencyList); Assert.assertEquals(dependencyList.size(), 1); }
@Override public void load(final Bundle bundle, final File rootDir) { final File policyRootDir = FolderLoaderUtils.getPolicyRootDir(rootDir); if (policyRootDir == null) return; final Map<String, Policy> policies = new HashMap<>(); loadPolicies(policyRootDir, policyRootDir, null, policies, bundle); loadPoliciesMetadata(rootDir, policies, bundle); bundle.putAllPolicies(policies); }
PolicyAndFolderLoader implements EntityLoader { @Override public void load(final Bundle bundle, final File rootDir) { final File policyRootDir = FolderLoaderUtils.getPolicyRootDir(rootDir); if (policyRootDir == null) return; final Map<String, Policy> policies = new HashMap<>(); loadPolicies(policyRootDir, policyRootDir, null, policies, bundle); loadPoliciesMetadata(rootDir, policies, bundle); bundle.putAllPolicies(policies); } }
PolicyAndFolderLoader implements EntityLoader { @Override public void load(final Bundle bundle, final File rootDir) { final File policyRootDir = FolderLoaderUtils.getPolicyRootDir(rootDir); if (policyRootDir == null) return; final Map<String, Policy> policies = new HashMap<>(); loadPolicies(policyRootDir, policyRootDir, null, policies, bundle); loadPoliciesMetadata(rootDir, policies, bundle); bundle.putAllPolicies(policies); } @Inject  PolicyAndFolderLoader(PolicyConverterRegistry policyConverterRegistry, FileUtils fileUtils,
                          IdGenerator idGenerator, JsonFileUtils jsonFileUtils); }
PolicyAndFolderLoader implements EntityLoader { @Override public void load(final Bundle bundle, final File rootDir) { final File policyRootDir = FolderLoaderUtils.getPolicyRootDir(rootDir); if (policyRootDir == null) return; final Map<String, Policy> policies = new HashMap<>(); loadPolicies(policyRootDir, policyRootDir, null, policies, bundle); loadPoliciesMetadata(rootDir, policies, bundle); bundle.putAllPolicies(policies); } @Inject  PolicyAndFolderLoader(PolicyConverterRegistry policyConverterRegistry, FileUtils fileUtils,
                          IdGenerator idGenerator, JsonFileUtils jsonFileUtils); @Override void load(final Bundle bundle, final File rootDir); @Override void load(Bundle bundle, String name, String value); @Override Object loadSingle(String name, File entitiesFile); @Override Map<String, Object> load(File entitiesFile); @Override String getEntityType(); }
PolicyAndFolderLoader implements EntityLoader { @Override public void load(final Bundle bundle, final File rootDir) { final File policyRootDir = FolderLoaderUtils.getPolicyRootDir(rootDir); if (policyRootDir == null) return; final Map<String, Policy> policies = new HashMap<>(); loadPolicies(policyRootDir, policyRootDir, null, policies, bundle); loadPoliciesMetadata(rootDir, policies, bundle); bundle.putAllPolicies(policies); } @Inject  PolicyAndFolderLoader(PolicyConverterRegistry policyConverterRegistry, FileUtils fileUtils,
                          IdGenerator idGenerator, JsonFileUtils jsonFileUtils); @Override void load(final Bundle bundle, final File rootDir); @Override void load(Bundle bundle, String name, String value); @Override Object loadSingle(String name, File entitiesFile); @Override Map<String, Object> load(File entitiesFile); @Override String getEntityType();  }