Esempio n. 1
0
  public void testSchemaXMLWSchemaWithAll() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("event-page-visit");
    String schemaUri =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResource(CLASSLOADER_SCHEMA_WITH_ALL_URI)
            .toString();
    eventTypeMeta.setSchemaResource(schemaUri);
    eventTypeMeta.addNamespacePrefix("ss", "samples:schemas:simpleSchemaWithAll");
    eventTypeMeta.addXPathProperty("url", "/ss:event-page-visit/ss:url", XPathConstants.STRING);
    config.addEventType("PageVisitEvent", eventTypeMeta);

    epService = EPServiceProviderManager.getProvider("TestSchemaXML", config);
    epService.initialize();
    updateListener = new SupportUpdateListener();

    // url='page4'
    String text = "select a.url as sesja from pattern [ every a=PageVisitEvent(url='page1') ]";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(updateListener);

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n"
            + "<url>page1</url>"
            + "</event-page-visit>");
    EventBean theEvent = updateListener.getLastNewData()[0];
    assertEquals("page1", theEvent.get("sesja"));
    updateListener.reset();

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n"
            + "<url>page2</url>"
            + "</event-page-visit>");
    assertFalse(updateListener.isInvoked());

    EventType type =
        epService.getEPAdministrator().createEPL("select * from PageVisitEvent").getEventType();
    EPAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor(
              "sessionId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor(
              "customerId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor("url", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("method", Node.class, null, false, false, false, false, true),
        },
        type.getPropertyDescriptors());
  }
Esempio n. 2
0
  public void testSchemaXMLWSchemaWithRestriction() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("order");
    InputStream schemaStream =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI);
    assertNotNull(schemaStream);
    String schemaText = ParserTool.linesToText(ParserTool.readFile(schemaStream));
    eventTypeMeta.setSchemaText(schemaText);
    config.addEventType("OrderEvent", eventTypeMeta);

    epService = EPServiceProviderManager.getProvider("TestSchemaXML", config);
    epService.initialize();
    updateListener = new SupportUpdateListener();

    String text = "select order_amount from OrderEvent";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(updateListener);

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<order>\n"
            + "<order_amount>202.1</order_amount>"
            + "</order>");
    EventBean theEvent = updateListener.getLastNewData()[0];
    assertEquals(Double.class, theEvent.get("order_amount").getClass());
    assertEquals(202.1d, theEvent.get("order_amount"));
    updateListener.reset();
  }
Esempio n. 3
0
  public void testSchemaXMLQuery_DOMGetterBacked() throws Exception {
    epService = EPServiceProviderManager.getProvider("TestSchemaXML", getConfig(false));
    epService.initialize();
    updateListener = new SupportUpdateListener();

    String stmtSelectWild = "select * from TestXMLSchemaType";
    EPStatement wildStmt = epService.getEPAdministrator().createEPL(stmtSelectWild);
    EventType type = wildStmt.getEventType();
    EventTypeAssertionUtil.assertConsistency(type);

    EPAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor(
              "nested1", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor(
              "prop4", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "nested3", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor(
              "customProp", Double.class, null, false, false, false, false, false),
        },
        type.getPropertyDescriptors());

    String stmt =
        "select nested1 as nodeProp,"
            + "prop4 as nested1Prop,"
            + "nested1.prop2 as nested2Prop,"
            + "nested3.nested4('a').prop5[1] as complexProp,"
            + "nested1.nested2.prop3[2] as indexedProp,"
            + "customProp,"
            + "prop4.attr2 as attrOneProp,"
            + "nested3.nested4[2].id as attrTwoProp"
            + " from TestXMLSchemaType.win:length(100)";

    EPStatement selectStmt = epService.getEPAdministrator().createEPL(stmt);
    selectStmt.addListener(updateListener);
    type = selectStmt.getEventType();
    EventTypeAssertionUtil.assertConsistency(type);
    EPAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor(
              "nodeProp", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor(
              "nested1Prop", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "nested2Prop", Boolean.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "complexProp", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "indexedProp", Integer.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "customProp", Double.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "attrOneProp", Boolean.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "attrTwoProp", String.class, null, false, false, false, false, false),
        },
        type.getPropertyDescriptors());

    Document eventDoc = SupportXML.sendDefaultEvent(epService.getEPRuntime(), "test");

    assertNotNull(updateListener.getLastNewData());
    EventBean theEvent = updateListener.getLastNewData()[0];

    assertSame(eventDoc.getDocumentElement().getChildNodes().item(1), theEvent.get("nodeProp"));
    assertEquals("SAMPLE_V6", theEvent.get("nested1Prop"));
    assertEquals(true, theEvent.get("nested2Prop"));
    assertEquals("SAMPLE_V8", theEvent.get("complexProp"));
    assertEquals(5, theEvent.get("indexedProp"));
    assertEquals(3.0, theEvent.get("customProp"));
    assertEquals(true, theEvent.get("attrOneProp"));
    assertEquals("c", theEvent.get("attrTwoProp"));

    /**
     * Comment-in for performance testing long start = System.nanoTime(); for (int i = 0; i < 1000;
     * i++) { sendEvent("test"); } long end = System.nanoTime(); double delta = (end - start) /
     * 1000d / 1000d / 1000d; System.out.println(delta);
     */
  }