Example #1
0
  @Test(
      groups = {"wso2.cep"},
      description = "Testing HTTP publisher with JSON formatted event with default mapping")
  public void httpJSONTestWithDefaultMappingScenario() throws Exception {
    String samplePath = "outputflows" + File.separator + "sample0062";
    int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
    int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

    EventDto eventDto = new EventDto();
    eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto.setAttributeValues(
        new String[] {
          "199008131245", "false", "100", "temperature", "23.45656", "7.12324", "100.34", "23.4545"
        });

    // Add StreamDefinition
    String streamDefinitionAsString =
        getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json");
    eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
    Assert.assertEquals(
        eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

    // Add ActiveMQ JMS EventPublisher
    String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "httpJson.xml");
    eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
    Assert.assertEquals(
        eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

    Thread.sleep(10000);
    WireMonitorServer wireMonitorServer = new WireMonitorServer(9445);
    Thread wireMonitorServerThread = new Thread(wireMonitorServer);
    wireMonitorServerThread.start();

    Thread.sleep(3000);

    eventSimulatorAdminServiceClient.sendEvent(eventDto);
    // wait while all stats are published
    Thread.sleep(30000);

    wireMonitorServer.shutdown();

    String receivedEvent = wireMonitorServer.getCapturedMessage().replaceAll("\\s+", "");
    log.info(receivedEvent);

    String sentEvent =
        "{\"event\":{\"metaData\":{\"timestamp\":199008131245,\"isPowerSaverEnabled\":false,"
            + "\"sensorId\":100,\"sensorName\":\"temperature\"},\"correlationData\":{\"longitude\":23.45656,"
            + "\"latitude\":7.12324},\"payloadData\":{\"humidity\":100.34,\"sensorValue\":23.4545}}}";

    eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
    eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("httpJson.xml");

    try {
      Assert.assertTrue(receivedEvent.contains(sentEvent), "Incorrect mapping has occurred!");
    } catch (Throwable e) {
      log.error("Exception thrown: " + e.getMessage(), e);
      Assert.fail("Exception: " + e.getMessage());
    }
  }
Example #2
0
  @Test(
      groups = {"wso2.cep"},
      description = "Testing HTTP publisher with Text formatted event with custom mapping",
      dependsOnMethods = {"httpJSONTestWithDefaultMappingScenario"})
  public void httpTextTestWithDefaultMappingScenario() throws Exception {
    String samplePath = "outputflows" + File.separator + "sample0062";
    int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
    int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

    EventDto eventDto = new EventDto();
    eventDto.setEventStreamId("org.wso2.event.message.stream:1.0.0");
    eventDto.setAttributeValues(
        new String[] {"199008131245", "Lasantha Fernando", "2321.56", "BATA", "199008031245"});

    // Add StreamDefinition
    String streamDefinitionAsString =
        getJSONArtifactConfiguration(samplePath, "org.wso2.event.message.stream_1.0.0.json");
    eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
    Assert.assertEquals(
        eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

    // Add ActiveMQ JMS EventPublisher
    String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "httpText.xml");
    eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
    Assert.assertEquals(
        eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

    Thread.sleep(10000);
    WireMonitorServer wireMonitorServer = new WireMonitorServer(9445);
    Thread wireMonitorServerThread = new Thread(wireMonitorServer);
    wireMonitorServerThread.start();

    Thread.sleep(3000);

    eventSimulatorAdminServiceClient.sendEvent(eventDto);
    // wait while all stats are published
    Thread.sleep(30000);

    wireMonitorServer.shutdown();

    String receivedEvent = wireMonitorServer.getCapturedMessage();
    log.info(receivedEvent);

    String sentEvent =
        "Hello Lasantha Fernando, "
            + "You have done transaction with your credit card for an amount Rs. 2321.56 with vendor: BATA.";

    eventStreamManagerAdminServiceClient.removeEventStream(
        "org.wso2.event.message.stream", "1.0.0");
    eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("httpText.xml");

    try {
      Assert.assertTrue(receivedEvent.contains(sentEvent), "Incorrect mapping has occurred!");
    } catch (Throwable e) {
      log.error("Exception thrown: " + e.getMessage(), e);
      Assert.fail("Exception: " + e.getMessage());
    }
  }
Example #3
0
  @Test(
      groups = {"wso2.cep"},
      description = "Testing HTTP publisher with XML formatted event with default mapping",
      dependsOnMethods = {"httpTextTestWithDefaultMappingScenario"})
  public void httpXMLTestWithDefaultMappingScenario() throws Exception {
    String samplePath = "outputflows" + File.separator + "sample0062";
    int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
    int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();

    EventDto eventDto = new EventDto();
    eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
    eventDto.setAttributeValues(
        new String[] {
          "199008131245", "false", "100", "temperature", "23.45656", "7.12324", "100.34", "23.4545"
        });

    // Add StreamDefinition
    String streamDefinitionAsString =
        getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json");
    eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
    Assert.assertEquals(
        eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);

    // Add ActiveMQ JMS EventPublisher
    String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "httpXml.xml");
    eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
    Assert.assertEquals(
        eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);

    Thread.sleep(10000);
    WireMonitorServer wireMonitorServer = new WireMonitorServer(9445);
    Thread wireMonitorServerThread = new Thread(wireMonitorServer);
    wireMonitorServerThread.start();

    Thread.sleep(3000);

    eventSimulatorAdminServiceClient.sendEvent(eventDto);
    // wait while all stats are published
    Thread.sleep(30000);

    wireMonitorServer.shutdown();

    String receivedEvent = wireMonitorServer.getCapturedMessage().replaceAll("\\s+", "");
    log.info(receivedEvent);

    String sentEvent =
        "<events><event><metaData><timestamp>199008131245</timestamp>"
            + "<isPowerSaverEnabled>false</isPowerSaverEnabled><sensorId>100</sensorId>"
            + "<sensorName>temperature</sensorName></metaData><correlationData><longitude>23.45656</longitude>"
            + "<latitude>7.12324</latitude></correlationData><payloadData><humidity>100.34</humidity>"
            + "<sensorValue>23.4545</sensorValue></payloadData></event></events>";

    eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
    eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("httpXml.xml");

    try {
      Assert.assertTrue(receivedEvent.contains(sentEvent), "Incorrect mapping has occurred!");
    } catch (Throwable e) {
      log.error("Exception thrown: " + e.getMessage(), e);
      Assert.fail("Exception: " + e.getMessage());
    }
  }