Java Code Examples for groovy.util.Node#appendNode()
The following examples show how to use
groovy.util.Node#appendNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 5 votes |
/** * Test method for {@link ClasspathFile#putJreOnModulePath(Node)}. */ @Test void test_putJreOnModulePath__Node() { // Test strategy: // ... assertion 1: method isJre(Node) works as intended // ... assertion 2: method hasNoAttributeModule(Node) works as intended // ... assertion 3: method moveToModulePath(Node) works as intended // --- a. rootNode with a bunch of entries and entries differing slightly // --- a. rootNode with a bunch of entries and entries differing slightly final Node rootNode = new Node(null, "root"); // a.1: difference in name of item final Map<String, String> mapA1 = new ConcurrentSkipListMap<>(); mapA1.put("path", "prefix" + "JRE_CONTAINER" + "suffix"); mapA1.put("kind", "con"); rootNode.appendNode("classpathentry", mapA1); // ok rootNode.appendNode("classpathEntry", mapA1); // not classpathentry // --- improve insDut.putJreOnModulePath(rootNode); // --- check assertEquals( "root[attributes={}; value=[" // a.1, begin + "classpathentry[attributes={kind=con, path=prefixJRE_CONTAINERsuffix}; value=[" + "attributes[attributes={}; value=[" + "attribute[attributes={name=module, value=true}; value=[]]" + "]]]" + "], " + "classpathEntry[attributes={kind=con, path=prefixJRE_CONTAINERsuffix}; value=[]]" + "]]", rootNode.toString() ); }
Example 2
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 4 votes |
/** * Test method for {@link ClasspathFile#improveEclipseClasspathFile(Node)}. */ @Test void test_improveEclipseClasspathFile__Node() { // Test strategy: // ... assertion 1: method putJreOnModulePath(Node) works as intended // --- a. JRE, rootNode with a bunch of entries and entries differing slightly // --- b. Main, rootNode with a bunch of entries and entries differing slightly // --- c. Test, rootNode with a bunch of entries and entries differing slightly final Node root = new Node(null, "root"); // --- a. JRE, rootNode with a bunch of entries and entries differing slightly // a.1: difference in name of item final Map<String, String> mapA1 = new ConcurrentSkipListMap<>(); mapA1.put("path", "prefix" + "JRE_CONTAINER" + "suffix"); mapA1.put("kind", "con"); root.appendNode("classpathentry", mapA1); // ok root.appendNode("classpathEntry", mapA1); // not classpathentry // --- b. Main, rootNode with a bunch of entries and entries differing slightly // b.1: difference in name of item final Map<String, String> kind = Map.of("kind", "lib"); final Map<String, String> mapB1 = new ConcurrentSkipListMap<>(); mapB1.put("name", ClasspathFile.NAME_ATTRIBUTE); mapB1.put("value", "main"); root.appendNode("classpathentry", kind) // ok .appendNode(ClasspathFile.NAME_CHILD) .appendNode(ClasspathFile.NAME_GRAND, mapB1); root.appendNode("Classpathentry", kind) // not classpathentry .appendNode(ClasspathFile.NAME_CHILD) .appendNode(ClasspathFile.NAME_GRAND, mapB1); // --- c. Test, rootNode with a bunch of entries and entries differing slightly // c.1: difference in name of item final Map<String, String> mapC1 = new ConcurrentSkipListMap<>(); mapC1.put("name", ClasspathFile.NAME_ATTRIBUTE); mapC1.put("value", "test"); root.appendNode("classpathentry") // ok .appendNode(ClasspathFile.NAME_CHILD) .appendNode(ClasspathFile.NAME_GRAND, mapC1); root.appendNode("Classpathentry") // not classpathentry .appendNode(ClasspathFile.NAME_CHILD) .appendNode(ClasspathFile.NAME_GRAND, mapC1); // --- improve insDut.improveEclipseClasspathFile(root); // --- check assertEquals( "root[attributes={}; value=[" // a.1, begin + "classpathentry[attributes={kind=con, path=prefixJRE_CONTAINERsuffix}; value=[" + "attributes[attributes={}; value=[" + "attribute[attributes={name=module, value=true}; value=[]]" + "]]]" + "], " + "classpathEntry[attributes={kind=con, path=prefixJRE_CONTAINERsuffix}; value=[]], " // b.1, begin + "classpathentry[attributes={kind=lib}; value=[" + "attributes[attributes={}; value=[" + "attribute[attributes={name=gradle_used_by_scope, value=main}; value=[]], " + "attribute[attributes={name=module, value=true}; value=[]]" + "]]" + "]], " + "Classpathentry[attributes={kind=lib}; value=[" + "attributes[attributes={}; value=[" + "attribute[attributes={name=gradle_used_by_scope, value=main}; value=[]]" + "]]" + "]], " // c.1, begin + "classpathentry[attributes={}; value=[" + "attributes[attributes={}; value=[" + "attribute[attributes={name=gradle_used_by_scope, value=test}; value=[]], " + "attribute[attributes={name=test, value=true}; value=[]]" + "]]" + "]], " + "Classpathentry[attributes={}; value=[" + "attributes[attributes={}; value=[" + "attribute[attributes={name=gradle_used_by_scope, value=test}; value=[]]" + "]]" + "]]" // end + "]]", root.toString() ); }
Example 3
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 4 votes |
/** * Test method for {@link ClasspathFile#getAttributeNamed(Node, String)}. */ @Test void test_getAttributeNamed__Node_String() { // Test strategy: // a. Node without children SHALL return empty // b. Node with children not named "attribute" SHALL return empty // c. Node with children named "attribute" but without proper attribute SHALL return empty // d. Node with one or more children named "attribute" and proper attribute SHALL return node // --- setup a node used for testing final Node dut = new Node(null, "dut"); // device under test // --- setup a map with attributes for child-nodes final Map<String, String> mapItem = new ConcurrentSkipListMap<>(); mapItem.put("name", "Alfred"); mapItem.put("Name", "foo"); // --- a. Node without children SHALL return empty assertEquals(0, dut.children().size()); assertFalse(insDut.getAttributeNamed(dut, "foo").isPresent()); // --- b. Node with children not named "attribute" SHALL return empty dut.appendNode("Attribute", mapItem); // wrong capitalization dut.appendNode("attributes", mapItem); // extra characters assertFalse(insDut.getAttributeNamed(dut, "foo").isPresent()); // --- c. Node with children named "attribute" but without proper attribute SHALL return empty // c.1 child "attribute" without attributes dut.appendNode(ClasspathFile.NAME_GRAND); assertFalse(insDut.getAttributeNamed(dut, "foo").isPresent()); // c.2 child "attribute" with attributes final Node node1 = dut.appendNode(ClasspathFile.NAME_GRAND, mapItem); // Note: assertions for c.2 are combined with assertions in d, see below // --- d. Node with children named "attribute" and proper attribute SHALL return node // d.1 Just one proper child assertFalse(insDut.getAttributeNamed(dut, "alfred").isPresent()); // wrong capitalization assertFalse(insDut.getAttributeNamed(dut, " Alfred").isPresent()); // extra prefix assertFalse(insDut.getAttributeNamed(dut, "Alfreds").isPresent()); // extra suffix assertSame(node1, insDut.getAttributeNamed(dut, "Alfred").get()); // d.2 More than one proper child final Node node2 = dut.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "Fiedler")); final Node node3 = dut.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "bar")); assertSame(node1, insDut.getAttributeNamed(dut, "Alfred").get()); // match in 1st proper child assertSame(node2, insDut.getAttributeNamed(dut, "Fiedler").get()); // match in 2nd proper child assertSame(node3, insDut.getAttributeNamed(dut, "bar").get()); // match in 3rd proper child }
Example 4
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 4 votes |
/** * Test method for {@link ClasspathFile#hasNoAttributeModule(Node)}. */ @Test void test_hasNoAttributeModule__Node() { // Test strategy: // --- a. "short" node, i.e. node with not enough information (returns always true) // --- b. node with just sufficient information // --- c. node triggering false by first child // --- d. node triggering false by second child // --- e. node triggering false by third child // --- a. "short" node, i.e. node with not enough information (returns always true) // a.1 empty node final Node nodeA = new Node(null, "a"); assertTrue(insDut.hasNoAttributeModule(nodeA)); // a.2 node with empty child final Node childA = nodeA.appendNode(ClasspathFile.NAME_CHILD); assertTrue(insDut.hasNoAttributeModule(nodeA)); // a.3 node with empty grand-child Node grandA = childA.appendNode(ClasspathFile.NAME_GRAND); assertTrue(insDut.hasNoAttributeModule(nodeA)); // a.4 node with non-empty grand-child, but inappropriate attributes childA.remove(grandA); grandA = childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "modul")); // not module // LOGGER.quiet("a.3: {}", nodeA); assertEquals(1, nodeA. children().size()); assertEquals(1, childA.children().size()); assertTrue(insDut.hasNoAttributeModule(nodeA)); childA.remove(grandA); grandA = childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "mOdule")); // not module assertTrue(insDut.hasNoAttributeModule(nodeA)); childA.remove(grandA); grandA = childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("naMe", MODULE)); // not name assertTrue(insDut.hasNoAttributeModule(nodeA)); // --- b. node with just sufficient information childA.remove(grandA); childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", MODULE)); assertFalse(insDut.hasNoAttributeModule(nodeA)); // --- c. node triggering false by first child // two (slightly) different nodes, one returns true, the other false assertTrue(insDut.hasNoAttributeModule(hnam(1, Map.of("name", "modUle")))); assertFalse(insDut.hasNoAttributeModule(hnam(1, Map.of("name", MODULE)))); // --- d. node triggering false by second child assertTrue(insDut.hasNoAttributeModule(hnam(2, Map.of("name", "modUle")))); assertFalse(insDut.hasNoAttributeModule(hnam(2, Map.of("name", MODULE)))); // --- e. node triggering false by third child assertTrue(insDut.hasNoAttributeModule(hnam(3, Map.of("name", "modUle")))); assertFalse(insDut.hasNoAttributeModule(hnam(3, Map.of("name", MODULE)))); }
Example 5
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 4 votes |
/** * Test method for {@link ClasspathFile#hasNoAttributeTest(groovy.util.Node)}. */ @Test void test_hasNoAttributeTest__Node() { // Test strategy: // --- a. "short" node, i.e. node with not enough information (returns always true) // --- b. node with just sufficient information // --- c. node triggering false by first child // --- d. node triggering false by second child // --- e. node triggering false by third child // --- a. "short" node, i.e. node with not enough information (returns always true) // a.1 empty node final Node nodeA = new Node(null, "a"); assertTrue(insDut.hasNoAttributeTest(nodeA)); // a.2 node with empty child final Node childA = nodeA.appendNode(ClasspathFile.NAME_CHILD); assertTrue(insDut.hasNoAttributeTest(nodeA)); // a.3 node with empty grand-child Node grandA = childA.appendNode(ClasspathFile.NAME_GRAND); assertTrue(insDut.hasNoAttributeTest(nodeA)); // a.4 node with non-empty grand-child, but inappropriate attributes childA.remove(grandA); grandA = childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "tes")); // not test // LOGGER.quiet("a.3: {}", nodeA); assertEquals(1, nodeA. children().size()); assertEquals(1, childA.children().size()); assertTrue(insDut.hasNoAttributeTest(nodeA)); childA.remove(grandA); grandA = childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "tEst")); // not test assertTrue(insDut.hasNoAttributeTest(nodeA)); childA.remove(grandA); grandA = childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("naMe", "test")); // not name assertTrue(insDut.hasNoAttributeTest(nodeA)); // --- b. node with just sufficient information childA.remove(grandA); childA.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "test")); assertFalse(insDut.hasNoAttributeTest(nodeA)); // --- c. node triggering false by first child // two (slightly) different nodes, one returns true, the other false assertTrue(insDut.hasNoAttributeTest(hnat(1, Map.of("name", "teSt")))); assertFalse(insDut.hasNoAttributeTest(hnat(1, Map.of("name", "test")))); // --- d. node triggering false by second child assertTrue(insDut.hasNoAttributeTest(hnat(2, Map.of("name", "teSt")))); assertFalse(insDut.hasNoAttributeTest(hnat(2, Map.of("name", "test")))); // --- e. node triggering false by third child assertTrue(insDut.hasNoAttributeTest(hnat(3, Map.of("name", "Test")))); assertFalse(insDut.hasNoAttributeTest(hnat(3, Map.of("name", "test")))); }
Example 6
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 4 votes |
/** * Test method for {@link ClasspathFile#hasAttributeNamed(Node, String)}. */ @Test void test_hasAttributeNamed__Node_String() { // Test strategy: // a. Node without children SHALL return false // b. Node with children not named "attribute" SHALL return false // c. Node with children named "attribute" but without proper attribute SHALL return false // d. Node with one or more children named "attribute" and proper attribute SHALL return true // --- setup a node used for testing final Node dut = new Node(null, "dut"); // device under test // --- setup a map with attributes for child-nodes final Map<String, String> mapItem = new ConcurrentSkipListMap<>(); mapItem.put("name", "Alfred"); mapItem.put("Name", "foo"); // --- a. Node without children SHALL return false assertEquals(0, dut.children().size()); assertFalse(insDut.hasAttributeNamed(dut, "foo")); // --- b. Node with children not named "attribute" SHALL return false dut.appendNode("Attribute", mapItem); // wrong capitalization dut.appendNode("attributes", mapItem); // extra characters assertFalse(insDut.hasAttributeNamed(dut, "foo")); // --- c. Node with children named "attribute" but without proper attribute SHALL return false // c.1 child "attribute" without attributes dut.appendNode(ClasspathFile.NAME_GRAND); assertFalse(insDut.hasAttributeNamed(dut, "foo")); // c.2 child "attribute" with attributes dut.appendNode(ClasspathFile.NAME_GRAND, mapItem); // Note: assertions for c.2 are combined with assertions in d, see below // --- d. Node with children named "attribute" and proper attribute SHALL return true // d.1 Just one proper child assertFalse(insDut.hasAttributeNamed(dut, "alfred")); // wrong capitalization assertFalse(insDut.hasAttributeNamed(dut, " Alfred")); // extra prefix assertFalse(insDut.hasAttributeNamed(dut, "Alfreds")); // extra suffix assertTrue(insDut.hasAttributeNamed(dut, "Alfred")); // d.2 More than one proper child dut.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "Fiedler")); dut.appendNode(ClasspathFile.NAME_GRAND, Map.of("name", "bar")); assertTrue(insDut.hasAttributeNamed(dut, "Alfred")); // match in first proper child assertTrue(insDut.hasAttributeNamed(dut, "Fiedler")); // match in second proper child assertTrue(insDut.hasAttributeNamed(dut, "bar")); // match in third proper child }
Example 7
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 3 votes |
/** * Adds three {@link Node}s to given node. * * <p>If {@code pos} is not in range [1, 3] then no sub-node indicates attribute MODULE: * <ol> * <li>1st node has trailing character ater MODULE * <li>2nd node has wrong capitalization * <li>3rd node has wrong attribute name * </ol> * * @param node * where sub-nodes are added to * * @param pos * value from range [1,3] indicating which child should get attributes from {@code map} * * @param map * with attributes for child at position {@code pos} */ private void addModule( final Node node, final int pos, final Map<String, String> map ) { final Map<String, String> map1 = Map.of("name", "modules"); // not module final Map<String, String> map2 = Map.of("name", "mOdule"); // not module final Map<String, String> map3 = Map.of("Name", MODULE); // not name node.appendNode(ClasspathFile.NAME_GRAND, 1 == pos ? map : map1); node.appendNode(ClasspathFile.NAME_GRAND, 2 == pos ? map : map2); node.appendNode(ClasspathFile.NAME_GRAND, 3 == pos ? map : map3); }
Example 8
Source File: ClasspathFileTest.java From gradle-modules-plugin with MIT License | 3 votes |
/** * Adds three {@link Node}s to given node. * * <p>If {@code pos} is not in range [1, 3] then no sub-node indicates attribute MODULE: * <ol> * <li>1st node has trailing character ater MODULE * <li>2nd node has wrong capitalization * <li>3rd node has wrong attribute name * </ol> * * @param node * where sub-nodes are added to * * @param pos * value from range [1,3] indicating which child should get attributes from {@code map} * * @param map * with attributes for child at position {@code pos} */ private void addTest( final Node node, final int pos, final Map<String, String> map ) { final Map<String, String> map1 = Map.of("name", "tests"); // not test final Map<String, String> map2 = Map.of("name", "tEst"); // not test final Map<String, String> map3 = Map.of("Name", "test"); // not name node.appendNode(ClasspathFile.NAME_GRAND, 1 == pos ? map : map1); node.appendNode(ClasspathFile.NAME_GRAND, 2 == pos ? map : map2); node.appendNode(ClasspathFile.NAME_GRAND, 3 == pos ? map : map3); }