@Test void testAttachingEncasses() throws IOException, DocumentParseException { File originFolder = new File(rootProjectDir.getRoot(), "original"); originFolder.mkdirs(); File destinationFolder = new File(rootProjectDir.getRoot(), "processed"); destinationFolder.mkdirs(); byte[] bundle1Contents = IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResource(TEST_1_BUNDLE)); byte[] bundle2Contents = IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResource(TEST_2_BUNDLE)); File file1 = new File(originFolder, TEST_1_BUNDLE); file1.createNewFile(); File file2 = new File(originFolder, TEST_2_BUNDLE); file2.createNewFile(); Files.write(file1.toPath(), bundle1Contents); Files.write(file2.toPath(), bundle2Contents); LinkedList<File> processed = processor.process(Stream.of(new File(originFolder, TEST_1_BUNDLE), new File(originFolder, TEST_2_BUNDLE)).collect(toCollection(LinkedList::new)), destinationFolder.toString()); assertNotNull(processed); assertEquals(2, processed.size()); File bundle1 = processed.get(0); assertEquals(destinationFolder.toString() + File.separator + TEST_1_BUNDLE, bundle1.toString()); File bundle2 = processed.get(1); assertEquals(destinationFolder.toString() + File.separator + TEST_2_BUNDLE, bundle2.toString()); Document bundle2Doc = DocumentTools.INSTANCE.parse(bundle2); NodeList resources = bundle2Doc.getDocumentElement().getElementsByTagName(RESOURCE); assertNotNull(resources); assertEquals(3, resources.getLength()); Element resourceElement = StreamSupport.stream(nodeList(resources).spliterator(), false).map(n -> (Element) n).filter(e -> PolicyEntityBuilder.POLICY.equals(e.getAttribute(ATTRIBUTE_TYPE))).findFirst().orElse(null); assertNotNull(resourceElement); String policyXML = resourceElement.getTextContent(); assertNotNull(policyXML); Element policyElement = DocumentTools.INSTANCE.parse(policyXML).getDocumentElement(); assertNotNull(policyElement); NodeList guids = policyElement.getElementsByTagName(ENCAPSULATED_ASSERTION_CONFIG_GUID); assertNotNull(guids); assertEquals(1, guids.getLength()); String guid = guids.item(0).getAttributes().getNamedItem(STRING_VALUE).getTextContent(); assertEquals("283e93c6-9cf6-46f1-a34a-cf333bf4f1c3", guid); }
public LinkedList<File> process(final List<File> bundles, String bundleFolderPath) { Bundle bundleObject = entityBundleLoader.load(bundles, BundleLoadingOperation.VALIDATE, ENCAPSULATED_ASSERTION_TYPE, EntityTypes.POLICY_TYPE, FOLDER_TYPE); LinkedList<File> processedBundles = new LinkedList<>(); for (File bundle : bundles) { Document document = parseBundleFile(bundle); Element bundleElement = document.getDocumentElement(); NodeList items = bundleElement.getElementsByTagName(ITEM); processEncasses(bundleObject, items); File processedBundle = writeProcessedBundle(bundle, bundleElement, bundleFolderPath); processedBundles.add(processedBundle); } return processedBundles; }
DependencyBundlesProcessor { public LinkedList<File> process(final List<File> bundles, String bundleFolderPath) { Bundle bundleObject = entityBundleLoader.load(bundles, BundleLoadingOperation.VALIDATE, ENCAPSULATED_ASSERTION_TYPE, EntityTypes.POLICY_TYPE, FOLDER_TYPE); LinkedList<File> processedBundles = new LinkedList<>(); for (File bundle : bundles) { Document document = parseBundleFile(bundle); Element bundleElement = document.getDocumentElement(); NodeList items = bundleElement.getElementsByTagName(ITEM); processEncasses(bundleObject, items); File processedBundle = writeProcessedBundle(bundle, bundleElement, bundleFolderPath); processedBundles.add(processedBundle); } return processedBundles; } }
DependencyBundlesProcessor { public LinkedList<File> process(final List<File> bundles, String bundleFolderPath) { Bundle bundleObject = entityBundleLoader.load(bundles, BundleLoadingOperation.VALIDATE, ENCAPSULATED_ASSERTION_TYPE, EntityTypes.POLICY_TYPE, FOLDER_TYPE); LinkedList<File> processedBundles = new LinkedList<>(); for (File bundle : bundles) { Document document = parseBundleFile(bundle); Element bundleElement = document.getDocumentElement(); NodeList items = bundleElement.getElementsByTagName(ITEM); processEncasses(bundleObject, items); File processedBundle = writeProcessedBundle(bundle, bundleElement, bundleFolderPath); processedBundles.add(processedBundle); } return processedBundles; } @Inject  DependencyBundlesProcessor(EntityBundleLoader entityBundleLoader, DocumentTools documentTools, DocumentFileUtils documentFileUtils); }
DependencyBundlesProcessor { public LinkedList<File> process(final List<File> bundles, String bundleFolderPath) { Bundle bundleObject = entityBundleLoader.load(bundles, BundleLoadingOperation.VALIDATE, ENCAPSULATED_ASSERTION_TYPE, EntityTypes.POLICY_TYPE, FOLDER_TYPE); LinkedList<File> processedBundles = new LinkedList<>(); for (File bundle : bundles) { Document document = parseBundleFile(bundle); Element bundleElement = document.getDocumentElement(); NodeList items = bundleElement.getElementsByTagName(ITEM); processEncasses(bundleObject, items); File processedBundle = writeProcessedBundle(bundle, bundleElement, bundleFolderPath); processedBundles.add(processedBundle); } return processedBundles; } @Inject  DependencyBundlesProcessor(EntityBundleLoader entityBundleLoader, DocumentTools documentTools, DocumentFileUtils documentFileUtils); LinkedList<File> process(final List<File> bundles, String bundleFolderPath); }
DependencyBundlesProcessor { public LinkedList<File> process(final List<File> bundles, String bundleFolderPath) { Bundle bundleObject = entityBundleLoader.load(bundles, BundleLoadingOperation.VALIDATE, ENCAPSULATED_ASSERTION_TYPE, EntityTypes.POLICY_TYPE, FOLDER_TYPE); LinkedList<File> processedBundles = new LinkedList<>(); for (File bundle : bundles) { Document document = parseBundleFile(bundle); Element bundleElement = document.getDocumentElement(); NodeList items = bundleElement.getElementsByTagName(ITEM); processEncasses(bundleObject, items); File processedBundle = writeProcessedBundle(bundle, bundleElement, bundleFolderPath); processedBundles.add(processedBundle); } return processedBundles; } @Inject  DependencyBundlesProcessor(EntityBundleLoader entityBundleLoader, DocumentTools documentTools, DocumentFileUtils documentFileUtils); LinkedList<File> process(final List<File> bundles, String bundleFolderPath);  }