Ejemplo n.º 1
0
  private void assertSameConcept(Concept expected, Concept actual, List<String> traversedUrns) {
    String errMsg = String.format("%1$s != %2$s", expected, actual);

    Assert.assertEquals(errMsg, expected, actual);
    Assert.assertEquals(errMsg, expected.getLabel(), actual.getLabel());
    Assert.assertEquals(errMsg, expected.getPreferredLabel(), actual.getPreferredLabel());
    Assert.assertEquals(errMsg, expected.isHref(), actual.isHref());
    Assert.assertEquals(errMsg, expected.getDefinition(), actual.getDefinition());

    // To deal with cycles in the hierarchy
    if (traversedUrns.contains(expected.getUrn())) {
      return;
    } else {
      traversedUrns.add(expected.getUrn());
    }

    assertSameConcept(expected.getBroader(), actual.getBroader(), traversedUrns);
    assertSameConcept(expected.getNarrower(), actual.getNarrower(), traversedUrns);
    assertSameConcept(expected.getRelated(), actual.getRelated(), traversedUrns);
  }
Ejemplo n.º 2
0
  /**
   * This is a legacy test for the older vocabularyServiceResponse.xml
   *
   * <p>It tests our concepts still return EVEN if we don't define top level concepts
   */
  @Test
  public void testGetConcepts() throws Exception {
    String responseXml =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/sissvoc/vocabularyServiceResponse.xml");
    Document responseDoc = DOMUtil.buildDomFromString(responseXml);
    Node rdfNode =
        (Node)
            DOMUtil.compileXPathExpr("rdf:RDF", new VocabNamespaceContext())
                .evaluate(responseDoc, XPathConstants.NODE);

    ConceptFactory cf = new ConceptFactory();
    Concept[] actualConcepts = cf.parseFromRDF(rdfNode);

    Assert.assertEquals("There are 27 concepts", 27, actualConcepts.length);

    // Must contain: Siltstone - concrete aggregate
    boolean found = false;
    for (Concept concept : actualConcepts) {
      if (concept.getPreferredLabel().equals("Siltstone - concrete aggregate")) {
        found = true;
        break;
      }
    }
    Assert.assertTrue("Must contain: Siltstone - concrete aggregate", found);

    // Must contain: Gneiss - crusher dust
    found = false;
    for (Concept concept : actualConcepts) {
      if (concept.getPreferredLabel().equals("Gneiss - crusher dust")) {
        found = true;
        break;
      }
    }
    Assert.assertTrue("Must contain: Gneiss - crusher dust", found);
  }