private static void replaceWithRelativePaths(MetadataElement[] elements, File outputDir) { for (MetadataElement element : elements) { final String pathName = element.getAttributeString(AbstractTimeSeries.PL_PATH); final URI relativeUri = FileUtils.getRelativeUri(outputDir.toURI(), new File(pathName)); final MetadataAttribute pathAttr = element.getAttribute(AbstractTimeSeries.PL_PATH); final MetadataAttribute typeAttr = element.getAttribute(AbstractTimeSeries.PL_TYPE); element.removeAttribute(pathAttr); element.removeAttribute(typeAttr); pathAttr.dispose(); final MetadataAttribute newPathAttr = new MetadataAttribute(AbstractTimeSeries.PL_PATH, ProductData.createInstance(relativeUri.toString()), true); element.addAttribute(newPathAttr); element.addAttribute(typeAttr); } }
@Test public void testAggregateOneInput_withGraph_withoutValidProductName() { final Product product = TestHelper.createProductWithProcessingGraph(1, "inputProduct"); final MetadataElement node_0 = product.getMetadataRoot().getElement("Processing_Graph").getElement("node.0"); final MetadataElement sourcesElement = node_0.getElement("sources"); final MetadataAttribute sourceProductAttribute = sourcesElement.getAttribute("sourceProduct"); sourcesElement.removeAttribute(sourceProductAttribute); aggregator.aggregateMetadata(product); final MetadataElement metadataElement = aggregator.getMetadata(); TestHelper.assertCorrectNameAndNoAttributes(metadataElement); assertEquals(1, metadataElement.getNumElements()); TestHelper.assertInputElementAt(0, "product_1", metadataElement); }
/** * Tests the functionality for removeAttribute() */ public void testRemoveAttribute() { MetadataElement annot = new MetadataElement("yepp"); MetadataAttribute att = new MetadataAttribute("GuiTest_DialogAndModalDialog", ProductData.createInstance(ProductData.TYPE_INT32), false); MetadataAttribute att2 = new MetadataAttribute("GuiTest_DialogAndModalDialog", ProductData.createInstance(ProductData.TYPE_INT32), false); // add one, check, remove again, check again annot.addAttribute(att); assertEquals(1, annot.getNumAttributes()); annot.removeAttribute(att); assertEquals(0, annot.getNumAttributes()); // try to add existent attribute name annot.addAttribute(att); assertEquals(1, annot.getNumAttributes()); annot.addAttribute(att2); assertEquals(2, annot.getNumAttributes()); // try to remove non existent attribute att2 = new MetadataAttribute("DifferentName", ProductData.createInstance(ProductData.TYPE_INT32), false); annot.removeAttribute(att2); assertEquals(2, annot.getNumAttributes()); }