/**
   * Tests that the service correctly parses a response from an NVCL WFS.
   *
   * @throws Exception the exception
   */
  @Test
  public void testGetHyloggerWithOWSError() throws Exception {
    final CSWRecord mockRecord1 = context.mock(CSWRecord.class, "mockRecord1"); // good record
    final CSWRecord mockRecord2 = context.mock(CSWRecord.class, "mockRecord2"); // has the wrong wfs
    final CSWRecord mockRecord3 = context.mock(CSWRecord.class, "mockRecord3"); // has no wfs
    final CSWCacheService mockCSWService = context.mock(CSWCacheService.class);
    final CSWRecordsHostFilter hostFilter = new CSWRecordsHostFilter("");
    final AbstractCSWOnlineResource mockRecord1Resource1 =
        new CSWOnlineResourceImpl(
            new URL("http://record.1.resource.1"), "wfs", "dne", "description");
    final AbstractCSWOnlineResource mockRecord1Resource2 =
        new CSWOnlineResourceImpl(
            new URL("http://record.1.resource.2"),
            "wfs",
            NVCLNamespaceContext.PUBLISHED_DATASETS_TYPENAME,
            "description");

    final AbstractCSWOnlineResource mockRecord2Resource1 =
        new CSWOnlineResourceImpl(
            new URL("http://record.2.resource.1"), "wfs", "dne", "description");

    final String owsErrorResponse =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/ows/OWSExceptionSample1.xml");

    context.checking(
        new Expectations() {
          {
            oneOf(mockCSWService).getWFSRecords();
            will(returnValue(Arrays.asList(mockRecord1, mockRecord2, mockRecord3)));

            oneOf(mockRecord1).getOnlineResourcesByType(hostFilter, OnlineResourceType.WFS);
            will(
                returnValue(
                    new AbstractCSWOnlineResource[] {mockRecord1Resource1, mockRecord1Resource2}));

            oneOf(mockRecord2).getOnlineResourcesByType(hostFilter, OnlineResourceType.WFS);
            will(returnValue(new AbstractCSWOnlineResource[] {mockRecord2Resource1}));

            oneOf(mockRecord3).getOnlineResourcesByType(hostFilter, OnlineResourceType.WFS);
            will(returnValue(new AbstractCSWOnlineResource[] {}));

            oneOf(mockMethodMaker)
                .makeGetMethod(
                    mockRecord1Resource2.getLinkage().toString(),
                    mockRecord1Resource2.getName(),
                    (Integer) null,
                    null);
            oneOf(mockHttpServiceCaller)
                .getMethodResponseAsString(with(any(HttpRequestBase.class)));
            will(returnValue(owsErrorResponse));
          }
        });

    List<String> restrictedIDs = service.discoverHyloggerBoreholeIDs(mockCSWService, hostFilter);
    Assert.assertNotNull(restrictedIDs);
    Assert.assertEquals(0, restrictedIDs.size());
  }
Esempio 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);
  }
Esempio n. 3
0
  @Test
  public void testSuccessfulRequest()
      throws PortalServiceException, IOException, URISyntaxException {
    final String sessionCookie = "sessionCookie";
    final HttpRequestBase insertRecordMethod =
        context.mock(HttpRequestBase.class, "insertRecordMethod");
    final HttpRequestBase recordMetadataShowMethod =
        context.mock(HttpRequestBase.class, "recordMetadataShowMethod");
    final HttpRequestBase recordMetadataGetMethod =
        context.mock(HttpRequestBase.class, "recordMetadataGetMethod");
    final HttpRequestBase recordPublicMethod =
        context.mock(HttpRequestBase.class, "recordPublicMethod");
    final HttpRequestBase loginMethod = context.mock(HttpRequestBase.class, "loginMethod");
    final HttpRequestBase logoutMethod = context.mock(HttpRequestBase.class, "logoutMethod");

    final String uuid = "4cda9dc3-9a0e-40cd-a3a9-64db5ce3c031";
    final String recordId = "21569";
    final String insertResponse =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/geonetwork/GNCSWInsertResponse.xml");
    final String loginResponse =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/geonetwork/GNLoginLogoutSuccessResponse.xml");
    final String logoutResponse =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/geonetwork/GNLoginLogoutSuccessResponse.xml");
    final String recordPublicResponse =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/geonetwork/GNRecordPublicResponse.xml");
    final String recordGetMetadata =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/geonetwork/GNMetadataGetXMLResponse.xml");

    final CSWRecord record =
        new CSWRecord("a", "b", "c", "", new CSWOnlineResourceImpl[0], new CSWGeographicElement[0]);
    final URI responseUri = new URI("http://foo.bar.baz");

    try (final HttpClientResponse mockLoginResponse = context.mock(HttpClientResponse.class)) {

      context.checking(
          new Expectations() {
            {
              allowing(gnMethodMaker)
                  .makeInsertRecordMethod(
                      with(any(String.class)), with(any(String.class)), with(any(String.class)));
              will(returnValue(insertRecordMethod));
              allowing(gnMethodMaker).makeRecordMetadataGetMethod(endpoint, uuid, sessionCookie);
              will(returnValue(recordMetadataGetMethod));
              allowing(gnMethodMaker).makeRecordMetadataShowMethod(endpoint, uuid, sessionCookie);
              will(returnValue(recordMetadataShowMethod));
              allowing(gnMethodMaker).makeRecordPublicMethod(endpoint, recordId, sessionCookie);
              will(returnValue(recordPublicMethod));
              allowing(gnMethodMaker).makeUserLoginMethod(endpoint, userName, password);
              will(returnValue(loginMethod));
              allowing(gnMethodMaker).makeUserLogoutMethod(endpoint, sessionCookie);
              will(returnValue(logoutMethod));

              allowing(mockLoginResponse).getFirstHeader("Set-Cookie");
              will(returnValue(new BasicHeader("Set-Cookie", sessionCookie)));

              oneOf(serviceCaller).getMethodResponseAsString(insertRecordMethod);
              will(returnValue(insertResponse));
              oneOf(serviceCaller).getMethodResponseAsString(recordMetadataGetMethod);
              will(returnValue(recordGetMetadata));
              oneOf(serviceCaller).getMethodResponseAsString(recordPublicMethod);
              will(returnValue(recordPublicResponse));
              oneOf(serviceCaller).getMethodResponseAsHttpResponse(loginMethod);
              will(returnValue(mockLoginResponse));
              oneOf(serviceCaller).responseToString(mockLoginResponse);
              will(returnValue(loginResponse));
              oneOf(serviceCaller).getMethodResponseAsString(logoutMethod);
              will(returnValue(logoutResponse));

              allowing(recordMetadataShowMethod).getURI();
              will(returnValue(responseUri));

              allowing(mockLoginResponse).close();
            }
          });

      Assert.assertEquals(responseUri.toString(), service.makeCSWRecordInsertion(record));
    }
  }
Esempio n. 4
0
  /** Runs the factory through a standard SISSVoc response XML */
  @Test
  public void testSISSVocRDF() throws Exception {
    // Build our expectation
    Concept concept1 = new Concept("urn:concept:1");
    Concept concept2 = new Concept("urn:concept:2");
    Concept concept3 = new Concept("urn:concept:3");
    Concept concept4 = new Concept("urn:concept:4");
    NamedIndividual ni1 = new NamedIndividual("urn:ni:1");
    NamedIndividual ni2 = new NamedIndividual("urn:ni:2");
    NamedIndividual ni3 = new NamedIndividual("urn:ni:3");

    concept1.setNarrower(new Concept[] {concept2, concept3, ni2});
    concept1.setLabel("LabelConcept1");
    concept1.setPreferredLabel("PrefLabelConcept1");

    concept2.setBroader(new Concept[] {concept1});
    concept2.setRelated(new Concept[] {concept3});
    concept2.setLabel("LabelConcept2");
    concept2.setPreferredLabel("PrefLabelConcept2");
    concept2.setDefinition("DefinitionConcept2");

    concept3.setBroader(new Concept[] {concept1});
    concept3.setRelated(new Concept[] {concept2});
    concept3.setNarrower(new Concept[] {ni1});
    concept3.setLabel("LabelConcept3");
    concept3.setPreferredLabel("PrefLabelConcept3");

    concept4.setNarrower(new Concept[] {ni3});
    concept4.setLabel("LabelConcept4");
    concept4.setPreferredLabel("PrefLabelConcept4");
    concept4.setDefinition("DefinitionConcept4");

    ni1.setBroader(new Concept[] {concept3});
    ni1.setLabel("LabelNamedIndividual1");
    ni1.setPreferredLabel("PrefLabelNamedIndividual1");

    ni2.setBroader(new Concept[] {concept1});
    ni2.setLabel("LabelNamedIndividual2");
    ni2.setPreferredLabel("PrefLabelNamedIndividual2");

    ni3.setBroader(new Concept[] {concept4});
    ni3.setLabel("LabelNamedIndividual3");
    ni3.setPreferredLabel("PrefLabelNamedIndividual3");

    Concept[] expectation = new Concept[] {concept1, concept4};

    // Build our actual list
    String responseXml =
        ResourceUtil.loadResourceAsString(
            "org/auscope/portal/core/test/responses/sissvoc/SISSVocResponse.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.assertNotNull(actualConcepts);
    assertSameConcept(expectation, actualConcepts, new ArrayList<String>());
  }
  /**
   * Tests that the service correctly parses a response from an NVCL WFS (even when there is an
   * error).
   *
   * @throws Exception the exception
   */
  @Test
  public void testGetHyloggerIDsWithError() throws Exception {
    final CSWRecord mockRecord1 =
        context.mock(CSWRecord.class, "mockRecord1"); // will return failure
    final CSWRecord mockRecord2 = context.mock(CSWRecord.class, "mockRecord2"); // good record
    final CSWCacheService mockCSWService = context.mock(CSWCacheService.class);
    final HttpRequestBase mockRecord1Method = context.mock(HttpRequestBase.class, "rec1method");
    final HttpRequestBase mockRecord2Method = context.mock(HttpRequestBase.class, "rec2method");
    final CSWRecordsHostFilter hostFilter = new CSWRecordsHostFilter("");
    final AbstractCSWOnlineResource mockRecord1Resource1 =
        new CSWOnlineResourceImpl(
            new URL("http://record.1.resource.1"),
            "wfs",
            NVCLNamespaceContext.PUBLISHED_DATASETS_TYPENAME,
            "description");
    final AbstractCSWOnlineResource mockRecord2Resource1 =
        new CSWOnlineResourceImpl(
            new URL("http://record.2.resource.1"),
            "wfs",
            NVCLNamespaceContext.PUBLISHED_DATASETS_TYPENAME,
            "description");

    final String successResponse = ResourceUtil.loadResourceAsString(GETSCANNEDBOREHOLEXML);

    context.checking(
        new Expectations() {
          {
            oneOf(mockCSWService).getWFSRecords();
            will(returnValue(Arrays.asList(mockRecord1, mockRecord2)));

            oneOf(mockRecord1).getOnlineResourcesByType(hostFilter, OnlineResourceType.WFS);
            will(returnValue(new AbstractCSWOnlineResource[] {mockRecord1Resource1}));

            oneOf(mockRecord2).getOnlineResourcesByType(hostFilter, OnlineResourceType.WFS);
            will(returnValue(new AbstractCSWOnlineResource[] {mockRecord2Resource1}));

            oneOf(mockMethodMaker)
                .makeGetMethod(
                    mockRecord1Resource1.getLinkage().toString(),
                    mockRecord1Resource1.getName(),
                    (Integer) null,
                    null);
            will(returnValue(mockRecord1Method));

            oneOf(mockMethodMaker)
                .makeGetMethod(
                    mockRecord2Resource1.getLinkage().toString(),
                    mockRecord2Resource1.getName(),
                    (Integer) null,
                    null);
            will(returnValue(mockRecord2Method));

            oneOf(mockHttpServiceCaller).getMethodResponseAsString(mockRecord1Method);
            will(throwException(new Exception("I'm an exception!")));

            oneOf(mockHttpServiceCaller).getMethodResponseAsString(mockRecord2Method);
            will(returnValue(successResponse));
          }
        });

    List<String> restrictedIDs = service.discoverHyloggerBoreholeIDs(mockCSWService, hostFilter);
    Assert.assertNotNull(restrictedIDs);
    Assert.assertArrayEquals(HOLEIDS, restrictedIDs.toArray(new String[restrictedIDs.size()]));
  }