Java Code Examples for nu.xom.Nodes#size()
The following examples show how to use
nu.xom.Nodes#size() .
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: FreemarkerTest.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
@Test public void testCountFailures() throws IOException, TemplateException, ParsingException { Configuration configuration = DashboardMain.configureFreemarker(); Artifact artifact1 = new DefaultArtifact("io.grpc:grpc-context:1.15.0"); ArtifactResults results1 = new ArtifactResults(artifact1); results1.addResult("Linkage Errors", 56); Artifact artifact2 = new DefaultArtifact("grpc:grpc:1.15.0"); ArtifactResults results2 = new ArtifactResults(artifact2); results2.addResult("Linkage Errors", 0); List<ArtifactResults> table = ImmutableList.of(results1, results2); List<DependencyGraph> globalDependencies = ImmutableList.of(); DashboardMain.generateDashboard( configuration, outputDirectory, table, globalDependencies, symbolProblemTable, new ClassPathResult(LinkedListMultimap.create(), ImmutableList.of()), new Bom("mock:artifact:1.6.7", null)); Path dashboardHtml = outputDirectory.resolve("index.html"); Assert.assertTrue(Files.isRegularFile(dashboardHtml)); Document document = builder.build(dashboardHtml.toFile()); // xom's query cannot specify partial class field, e.g., 'statistic-item' Nodes counts = document.query("//div[@class='container']/div/h2"); Assert.assertTrue(counts.size() > 0); for (int i = 0; i < counts.size(); i++) { Integer.parseInt(counts.get(i).getValue().trim()); } // Linkage Errors Truth.assertThat(counts.get(1).getValue().trim()).isEqualTo("1"); }
Example 2
Source File: DashboardTest.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
@Test public void testArtifactDetails() throws IOException, ArtifactDescriptorException { List<Artifact> artifacts = Bom.readBom("com.google.cloud:libraries-bom:1.0.0") .getManagedDependencies(); Assert.assertTrue("Not enough artifacts found", artifacts.size() > 1); Assert.assertEquals("en-US", dashboard.getRootElement().getAttribute("lang").getValue()); Nodes tr = details.query("//tr"); Assert.assertEquals(artifacts.size() + 1, tr.size()); // header row adds 1 for (int i = 1; i < tr.size(); i++) { // start at 1 to skip header row Nodes td = tr.get(i).query("td"); Assert.assertEquals(Artifacts.toCoordinates(artifacts.get(i - 1)), td.get(0).getValue()); for (int j = 1; j < 5; ++j) { // start at 1 to skip the leftmost artifact coordinates column assertValidCellValue((Element) td.get(j)); } } Nodes href = details.query("//tr/td[@class='artifact-name']/a/@href"); for (int i = 0; i < href.size(); i++) { String fileName = href.get(i).getValue(); Artifact artifact = artifacts.get(i); Assert.assertEquals( Artifacts.toCoordinates(artifact).replace(':', '_') + ".html", URLDecoder.decode(fileName, "UTF-8")); Path componentReport = outputDirectory.resolve(fileName); Assert.assertTrue(fileName + " is missing", Files.isRegularFile(componentReport)); try { Document report = builder.build(componentReport.toFile()); Assert.assertEquals("en-US", report.getRootElement().getAttribute("lang").getValue()); } catch (ParsingException ex) { byte[] data = Files.readAllBytes(componentReport); String message = "Could not parse " + componentReport + " at line " + ex.getLineNumber() + ", column " + ex.getColumnNumber() + "\r\n"; message += ex.getMessage() + "\r\n"; message += new String(data, StandardCharsets.UTF_8); Assert.fail(message); } } }
Example 3
Source File: DashboardTest.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
@Test public void testDashboard_unstableDependencies() { // Pre 1.0 version section Nodes li = unstable.query("//ul[@id='unstable']/li"); Assert.assertTrue(li.size() > 1); for (int i = 0; i < li.size(); i++) { String value = li.get(i).getValue(); Assert.assertTrue(value, value.contains(":0")); } // This element appears only when every dependency becomes stable Nodes stable = dashboard.query("//p[@id='stable-notice']"); Assert.assertEquals(0, stable.size()); }
Example 4
Source File: DashboardTest.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
@Test public void testLinkageErrors_ensureNoDuplicateSymbols() throws IOException, ParsingException { Document document = parseOutputFile("com.google.http-client_google-http-client-appengine_1.29.1.html"); Nodes linkageCheckMessages = document.query("//p[@class='jar-linkage-report-cause']"); Truth.assertThat(linkageCheckMessages.size()).isGreaterThan(0); List<String> messages = new ArrayList<>(); for (int i = 0; i < linkageCheckMessages.size(); ++i) { messages.add(linkageCheckMessages.get(i).getValue()); } // When uniqueness of SymbolProblem and Symbol classes are incorrect, dashboard has duplicates. Truth.assertThat(messages).containsNoDuplicates(); }
Example 5
Source File: XmlUtils.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public static Node getNode(Document doc, String entityType, String entityName) { String query = createQueryStringByName(entityType, entityName); Nodes nodes = doc.query(query); if (nodes != null && nodes.size() > 0) { return nodes.get(0); } return null; }
Example 6
Source File: XmlEntity.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Use the CacheXmlGenerator to create XML from the entity associated with * the current cache. * * @param element Name of the XML element to search for. * @param attributes * Attributes of the element that should match, for example "name" or * "id" and the value they should equal. * * @return XML string representation of the entity. */ private final String loadXmlDefinition(final String element, final Map<String, String> attributes) { final Cache cache = CacheFactory.getAnyInstance(); Document document = null; try { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); CacheXmlGenerator.generate(cache, printWriter, false, false, false); printWriter.close(); // Remove the DOCTYPE line when getting the string to prevent // errors when trying to locate the DTD. String xml = stringWriter.toString().replaceFirst("<!DOCTYPE.*>", ""); document = new Builder(false).build(xml, null); } catch (ValidityException vex) { cache.getLogger().error("Could not parse XML when creating XMLEntity", vex); } catch (ParsingException pex) { cache.getLogger().error("Could not parse XML when creating XMLEntity", pex); } catch (IOException ioex) { cache.getLogger().error("Could not parse XML when creating XMLEntity", ioex); } Nodes nodes = document.query(createQueryString(element, attributes)); if (nodes.size() != 0) { return nodes.get(0).toXML(); } cache.getLogger().warning("No XML definition could be found with name=" + element + " and attributes=" + attributes); return null; }
Example 7
Source File: XmlUtils.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public static Node getNode(Document doc, String entityType, String entityName) { String query = createQueryStringByName(entityType, entityName); Nodes nodes = doc.query(query); if (nodes != null && nodes.size() > 0) { return nodes.get(0); } return null; }
Example 8
Source File: XmlEntity.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Use the CacheXmlGenerator to create XML from the entity associated with * the current cache. * * @param element Name of the XML element to search for. * @param attributes * Attributes of the element that should match, for example "name" or * "id" and the value they should equal. * * @return XML string representation of the entity. */ private final String loadXmlDefinition(final String element, final Map<String, String> attributes) { final Cache cache = CacheFactory.getAnyInstance(); Document document = null; try { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); CacheXmlGenerator.generate(cache, printWriter, false, false, false); printWriter.close(); // Remove the DOCTYPE line when getting the string to prevent // errors when trying to locate the DTD. String xml = stringWriter.toString().replaceFirst("<!DOCTYPE.*>", ""); document = new Builder(false).build(xml, null); } catch (ValidityException vex) { cache.getLogger().error("Could not parse XML when creating XMLEntity", vex); } catch (ParsingException pex) { cache.getLogger().error("Could not parse XML when creating XMLEntity", pex); } catch (IOException ioex) { cache.getLogger().error("Could not parse XML when creating XMLEntity", ioex); } Nodes nodes = document.query(createQueryString(element, attributes)); if (nodes.size() != 0) { return nodes.get(0).toXML(); } cache.getLogger().warning("No XML definition could be found with name=" + element + " and attributes=" + attributes); return null; }
Example 9
Source File: XOMTreeBuilder.java From caja with Apache License 2.0 | 5 votes |
@Override protected void appendChildrenToNewParent(Element oldParent, Element newParent) throws SAXException { try { Nodes children = oldParent.removeChildren(); for (int i = 0; i < children.size(); i++) { newParent.appendChild(children.get(i)); } } catch (XMLException e) { fatal(e); } }