@Test
  public void shouldCreateValidUnsubscribeRequest() throws OXFException, XmlException {
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.UNSUBSCRIBE_SES_URL, "http://ses.host");
    parameters.addParameterShell(SESRequestBuilder_00.UNSUBSCRIBE_REFERENCE, "urn:n52:dummy");

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildUnsubscribeRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("Unsubscribe request is not valid: " + errors, errors.isEmpty());

    parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.UNSUBSCRIBE_SES_URL, "http://ses.host");
    parameters.addParameterShell(
        SESRequestBuilder_00.UNSUBSCRIBE_REFERENCE_XML,
        "<muse-wsa:ResourceId "
            + "xmlns:muse-wsa=\"http://ws.apache.org/muse/addressing\" wsa:IsReferenceParameter=\"true\" "
            + " xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
            + "Subscription-2</muse-wsa:ResourceId>");

    asText = request.buildUnsubscribeRequest(parameters);
    envelope = EnvelopeDocument.Factory.parse(asText);

    errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("Unsubscribe request is not valid: " + errors, errors.isEmpty());
  }
  @Test
  public void shouldCreateMinimalSubscribeRequest() throws OXFException, XmlException, IOException {
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.SUBSCRIBE_SES_URL, "http://ses.host");
    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_CONSUMER_REFERENCE_ADDRESS, "http://consum.er");

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildSubscribeRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("SubscribeRequest is not valid: " + errors, errors.isEmpty());
  }
  @Test
  public void shouldCreateValidDestroyRegistrationRequest()
      throws OXFException, XmlException, IOException {
    String sesUrl = "http://ses.host";
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.DESTROY_REGISTRATION_SES_URL, sesUrl);
    parameters.addParameterShell(
        SESRequestBuilder_00.DESTROY_REGISTRATION_REFERENCE, "Publisher-1");

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildDestroyRegistrationRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("DestroyRegistration is not valid: " + errors, errors.isEmpty());
  }
  @Test(expected = IllegalArgumentException.class)
  public void shouldThrowExceptionOnMissingConsumerForSubscription() throws OXFException {
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.SUBSCRIBE_SES_URL, "http://ses.host");

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    request.buildSubscribeRequest(parameters);
  }
  @Test
  public void shouldCreateValidSubscribeRequest() throws OXFException, XmlException, IOException {
    String sesUrl = "http://ses.host";
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.SUBSCRIBE_SES_URL, sesUrl);
    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_CONSUMER_REFERENCE_ADDRESS, "http://consum.er");
    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_INITIAL_TERMINATION_TIME, "2099-12-12");
    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_FILTER_MESSAGE_CONTENT, readFilter(), readFilter());
    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_FILTER_MESSAGE_CONTENT_DIALECT,
        "http://www.opengis.net/ses/filter/level3",
        "http://www.opengis.net/ses/filter/level3");

    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_FILTER_TOPIC, "<start>topic</start>");
    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_FILTER_TOPIC_DIALECT, "http://my-funny/dialect");

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildSubscribeRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("SubscribeRequest is not valid: " + errors, errors.isEmpty());
  }
Esempio n. 6
0
  public String executeGetRecords(int maxRecords, int startPos) throws Exception {

    CSWAdapter adapter = new CSWAdapter();

    ParameterContainer paramCon = new ParameterContainer();
    paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_MAX_RECORDS, maxRecords);
    paramCon.addParameterShell(CSWRequestBuilder.GET_RECORDS_START_POSITION, startPos);
    paramCon.addParameterShell(
        CSWRequestBuilder.GET_RECORDS_RESULT_TYPE, ResultType.RESULTS.toString());
    paramCon.addParameterShell(
        CSWRequestBuilder.GET_RECORDS_OUTPUT_FORMAT_PARAMETER, "application/xml");
    paramCon.addParameterShell(
        CSWRequestBuilder.GET_RECORDS_OUTPUT_SCHEMA_FORMAT, "http://www.opengis.net/cat/csw/2.0.2");
    paramCon.addParameterShell(
        CSWRequestBuilder.GET_RECORDS_QUERY_TYPE_NAMES_PARAMETER, "csw:Record");
    paramCon.addParameterShell(
        CSWRequestBuilder.GET_RECORDS_ELEMENT_SET_NAME_FORMAT, ElementSetNameType.BRIEF.toString());

    OperationResult opResult =
        adapter.doOperation(
            new Operation(
                CSWAdapter.GET_RECORDS,
                Constants.getInstance().getUrlCSW() + "?",
                Constants.getInstance().getUrlCSW()),
            paramCon);

    String result = new String(opResult.getIncomingResult());

    return result;
  }
  @Test(expected = IllegalArgumentException.class)
  public void shouldThrowExceptionOnMissingServiceUrlForSubscription() throws OXFException {
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(
        SESRequestBuilder_00.SUBSCRIBE_CONSUMER_REFERENCE_ADDRESS, "http://test.test");

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    request.buildSubscribeRequest(parameters);
  }
Esempio n. 8
0
  public String executeGetRecordsById(String recordID) throws Exception {
    LOGGER.info("Calling GetRecordsById for record '" + recordID + "'");

    CSWAdapter adapter = new CSWAdapter();

    String elementSetName = "full";
    String outputSchema = Constants.getInstance().getNsGMD();
    // String outputSchema = Constants.NS_CSW;

    ParameterContainer paramCon = new ParameterContainer();
    paramCon.addParameterShell(
        CSWRequestBuilder.GET_RECORD_BY_ID_REQUEST, CSWAdapter.GET_RECORD_BY_ID);
    paramCon.addParameterShell(
        CSWRequestBuilder.GET_RECORD_BY_ID_VERSION, CSWAdapter.SUPPORTED_VERSIONS[0]);
    paramCon.addParameterShell(CSWRequestBuilder.GET_RECORD_BY_ID_SERVICE, CSWAdapter.SERVICE_TYPE);
    paramCon.addParameterShell(CSWRequestBuilder.GET_RECORD_BY_ID_ID, recordID);
    paramCon.addParameterShell(CSWRequestBuilder.GET_RECORD_BY_ID_ELEMENT_SET_NAME, elementSetName);
    paramCon.addParameterShell(CSWRequestBuilder.GET_RECORD_BY_ID_OUTPUT_SCHEMA, outputSchema);

    OperationResult opResult =
        adapter.doOperation(
            new Operation(
                CSWAdapter.GET_RECORD_BY_ID,
                Constants.getInstance().getUrlCSW() + "?",
                Constants.getInstance().getUrlCSW()),
            paramCon);

    String result = new String(opResult.getIncomingResult());

    return result;
  }
  @Test
  public void shouldCreateValidDescribeSensorRequest() throws OXFException, XmlException {
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.DESCRIBE_SENSOR_SES_URL, "http://ses.host");
    parameters.addParameterShell(SESRequestBuilder_00.DESCRIBE_SENSOR_SENSOR_ID, "urn:n52:dummy");

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildDescribeSensorRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("DescribeSensor request is not valid: " + errors, errors.isEmpty());
  }
  @Test
  public void shouldCreateValidNotification() throws XmlException, IOException, OXFException {
    String sesUrl = "http://ses.host";
    String dialect = "http://my-funny/dialect";
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.NOTIFY_SES_URL, sesUrl);
    parameters.addParameterShell(SESRequestBuilder_00.NOTIFY_TOPIC_DIALECT, dialect);
    parameters.addParameterShell(SESRequestBuilder_00.NOTIFY_TOPIC, "<start>topic</start>");
    parameters.addParameterShell(SESRequestBuilder_00.NOTIFY_XML_MESSAGE, readMessage());

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildNotifyRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    XMLBeansParser.registerLaxValidationCase(SASamplingPointCase.getInstance());
    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("Notification is not valid: " + errors, errors.isEmpty());

    XmlCursor bodyCur = envelope.getEnvelope().getBody().newCursor();
    bodyCur.toFirstChild();
    Assert.assertTrue(bodyCur.getObject() instanceof Notify);
    XmlCursor tmpCur =
        ((Notify) bodyCur.getObject()).getNotificationMessageArray()[0].getMessage().newCursor();
    tmpCur.toFirstChild();
    Assert.assertTrue(tmpCur.getObject() instanceof ObservationType);

    Assert.assertTrue(
        ((Notify) bodyCur.getObject())
            .getNotificationMessageArray()[0]
            .getTopic()
            .getDialect()
            .trim()
            .equals(dialect));

    tmpCur = ((Notify) bodyCur.getObject()).getNotificationMessageArray()[0].getTopic().newCursor();

    Assert.assertTrue(tmpCur.getObject().xmlText().contains("<start>"));
  }
  @Test
  public void shouldCreateValidCapabilitiesRequest()
      throws OXFException, XmlException, IOException {
    String sesUrl = "http://ses.host";
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.GET_CAPABILITIES_SES_URL, sesUrl);

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildGetCapabilitiesRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("GetCapabilities is not valid: " + errors, errors.isEmpty());
  }
  @Test
  public void shouldCreateValidRegisterPublisherRequest()
      throws OXFException, XmlException, IOException {
    String sesUrl = "http://ses.host";
    ParameterContainer parameters = new ParameterContainer();
    parameters.addParameterShell(SESRequestBuilder_00.REGISTER_PUBLISHER_SES_URL, sesUrl);
    parameters.addParameterShell(
        SESRequestBuilder_00.REGISTER_PUBLISHER_FROM, "http://my-funny/sender/address");
    parameters.addParameterShell(
        SESRequestBuilder_00.REGISTER_PUBLISHER_LIFETIME_DURATION, "2012-12-02");
    parameters.addParameterShell(
        SESRequestBuilder_00.REGISTER_PUBLISHER_TOPIC_DIALECT, "http://my-funny/dialect");
    parameters.addParameterShell(
        SESRequestBuilder_00.REGISTER_PUBLISHER_TOPIC, "<start>topic</start>");
    parameters.addParameterShell(SESRequestBuilder_00.REGISTER_PUBLISHER_SENSORML, readSensorML());

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildRegisterPublisherRequest(parameters);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("RegisterPublisher is not valid: " + errors, errors.isEmpty());
  }
  @Test
  public void shouldCreateValidLevel1SubscribeRequest() throws OXFException, XmlException {
    String consumer = "http://*****:*****@xlink:href='urn:ogc:object:procedure:CITE:WeatherService:LGA'";

    ParameterContainer parameter = new ParameterContainer();
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_SES_URL, host);
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_CONSUMER_REFERENCE_ADDRESS, consumer);
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_FILTER_TOPIC, topicString);
    parameter.addParameterShell(
        ISESRequestBuilder.SUBSCRIBE_FILTER_MESSAGE_CONTENT_DIALECT, dialect);
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_FILTER_MESSAGE_CONTENT, xpath);

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildSubscribeRequest(parameter);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("SubscribeRequest is not valid: " + errors, errors.isEmpty());

    Body body = envelope.getEnvelope().getBody();
    XmlCursor cur = body.newCursor();
    cur.toFirstChild();
    XmlObject subscribeRequestObject = cur.getObject();
    cur.dispose();

    if (!(subscribeRequestObject instanceof Subscribe))
      throw new IllegalStateException("Body does not contain a Subscribe request.");

    Subscribe subscribeRequest = (Subscribe) subscribeRequestObject;
    Assert.assertTrue(
        subscribeRequest
            .getConsumerReference()
            .getAddress()
            .getStringValue()
            .trim()
            .equals(consumer.trim()));

    cur = subscribeRequest.getFilter().newCursor();
    cur.toFirstChild();
    do {
      XmlObject filterElement = cur.getObject();
      if (filterElement instanceof QueryExpressionType) {
        QueryExpressionType qet = (QueryExpressionType) filterElement;
        Assert.assertTrue(qet.getDialect().trim().equals(dialect.trim()));
        XmlCursor tmpCur = qet.newCursor();
        Assert.assertTrue(tmpCur.toFirstContentToken() == TokenType.TEXT);
        Assert.assertTrue(tmpCur.getChars().trim().equals(xpath.trim()));
      } else if (filterElement instanceof TopicExpressionType) {
        TopicExpressionType tet = (TopicExpressionType) filterElement;
        Assert.assertTrue(
            tet.getDialect().trim().equals(SESRequestBuilder_00.DEFAULT_TOPIC_DIALECT));
        XmlCursor tmpCur = tet.newCursor();
        Assert.assertTrue(tmpCur.toFirstContentToken() == TokenType.TEXT);
        Assert.assertTrue(tmpCur.getChars().trim().equals(topicString.trim()));
      }
    } while (cur.toNextSibling());
  }