Java Code Examples for nu.xom.Nodes#get()

The following examples show how to use nu.xom.Nodes#get() . 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 6 votes vote down vote up
@Test
public void testVersionIndex()
    throws IOException, TemplateException, URISyntaxException, ParsingException {
  Path output =
      DashboardMain.generateVersionIndex(
          "com.google.cloud",
          "libraries-bom",
          ImmutableList.of("1.0.0", "2.0.0", "2.1.0-SNAPSHOT"));
  Assert.assertTrue(
      output.endsWith(Paths.get("target", "com.google.cloud", "libraries-bom", "index.html")));
  Assert.assertTrue(Files.isRegularFile(output));

  Document document = builder.build(output.toFile());
  Nodes links = document.query("//a/@href");
  Assert.assertEquals(3, links.size());
  Node snapshotLink = links.get(2);
  // 2.1.0-SNAPSHOT has directory 'snapshot'
  Assert.assertEquals("snapshot/index.html", snapshotLink.getValue());
}
 
Example 2
Source File: DashboardTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testLinkageReports() {
  Nodes reports = details.query("//p[@class='jar-linkage-report']");
  // appengine-api-sdk, shown as first item in linkage errors, has these errors
  Truth.assertThat(trimAndCollapseWhiteSpace(reports.get(0).getValue()))
      .isEqualTo(
          "91 target classes causing linkage errors referenced from 501 source classes.");

  Nodes dependencyPaths = details.query("//p[@class='linkage-check-dependency-paths']");
  Node dependencyPathMessageOnProblem = dependencyPaths.get(dependencyPaths.size() - 4);
  Assert.assertEquals(
      "The following paths contain com.google.guava:guava-jdk5:13.0:",
      trimAndCollapseWhiteSpace(dependencyPathMessageOnProblem.getValue()));

  Node dependencyPathMessageOnSource = dependencyPaths.get(dependencyPaths.size() - 3);
  Assert.assertEquals(
      "The following paths contain com.google.guava:guava:27.1-android:",
      trimAndCollapseWhiteSpace(dependencyPathMessageOnSource.getValue()));

  Nodes nodesWithPathsSummary = details.query("//p[@class='linkage-check-dependency-paths']");
  Truth.assertWithMessage("The dashboard should not show repetitive dependency paths")
      .that(nodesWithPathsSummary)
      .comparingElementsUsing(
          Correspondence.<Node, String>transforming(
              node -> trimAndCollapseWhiteSpace(node.getValue()), "has text"))
      .contains(
          "Dependency path 'commons-logging:commons-logging > javax.servlet:servlet-api' exists"
              + " in all 1337 dependency paths. Example path:"
              + " com.google.http-client:google-http-client:1.29.1 (compile) /"
              + " org.apache.httpcomponents:httpclient:4.5.5 (compile) /"
              + " commons-logging:commons-logging:1.2 (compile) / javax.servlet:servlet-api:2.3"
              + " (provided, optional)");
}
 
Example 3
Source File: XmlUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
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 4
Source File: XmlUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
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 5
Source File: DashboardUnavailableArtifactTest.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testDashboardWithRepositoryException()
    throws IOException, TemplateException, ParsingException {
  Configuration configuration = DashboardMain.configureFreemarker();

  Artifact validArtifact = new DefaultArtifact("io.grpc:grpc-context:1.15.0");
  ArtifactResults validArtifactResult = new ArtifactResults(validArtifact);
  validArtifactResult.addResult(DashboardMain.TEST_NAME_UPPER_BOUND, 0);
  validArtifactResult.addResult(DashboardMain.TEST_NAME_DEPENDENCY_CONVERGENCE, 0);
  validArtifactResult.addResult(DashboardMain.TEST_NAME_GLOBAL_UPPER_BOUND, 0);

  Artifact invalidArtifact = new DefaultArtifact("io.grpc:nonexistent:jar:1.15.0");
  ArtifactResults errorArtifactResult = new ArtifactResults(invalidArtifact);
  errorArtifactResult.setExceptionMessage(
      "Could not find artifact io.grpc:nonexistent:jar:1.15.0 in central"
          + " (https://repo1.maven.org/maven2/)");

  List<ArtifactResults> table = new ArrayList<>();
  table.add(validArtifactResult);
  table.add(errorArtifactResult);

  DashboardMain.generateDashboard(
      configuration,
      outputDirectory,
      table,
      ImmutableList.of(),
      ImmutableMap.of(),
      new ClassPathResult(LinkedListMultimap.create(), ImmutableList.of()),
      bom);

  Path generatedHtml = outputDirectory.resolve("artifact_details.html");
  Assert.assertTrue(Files.isRegularFile(generatedHtml));
  Document document = builder.build(generatedHtml.toFile());
  Assert.assertEquals("en-US", document.getRootElement().getAttribute("lang").getValue());
  Nodes tr = document.query("//tr");

  Assert.assertEquals(
      "The size of rows in table should match the number of artifacts + 1 (header)",
      tr.size(),table.size() + 1);

  Nodes tdForValidArtifact = tr.get(1).query("td");
  Assert.assertEquals(
      Artifacts.toCoordinates(validArtifact), tdForValidArtifact.get(0).getValue());
  Element firstResult = (Element) (tdForValidArtifact.get(2));
  Truth.assertThat(firstResult.getValue().trim()).isEqualTo("PASS");
  Truth.assertThat(firstResult.getAttributeValue("class")).isEqualTo("pass");

  Nodes tdForErrorArtifact = tr.get(2).query("td");
  Assert.assertEquals(
      Artifacts.toCoordinates(invalidArtifact), tdForErrorArtifact.get(0).getValue());
  Element secondResult = (Element) (tdForErrorArtifact.get(2));
  Truth.assertThat(secondResult.getValue().trim()).isEqualTo("UNAVAILABLE");
  Truth.assertThat(secondResult.getAttributeValue("class")).isEqualTo("unavailable");
}