コード例 #1
0
 private Map<String, Object> makeMap(Object[][] entries) {
   Map<String, Object> result = new HashMap<String, Object>();
   if (entries == null) {
     return result;
   }
   for (int i = 0; i < entries.length; i++) {
     result.put((String) entries[i][0], entries[i][1]);
   }
   return result;
 }
コード例 #2
0
 private Map<String, Object> makeMap(String nameValuePairs) {
   Map<String, Object> result = new HashMap<String, Object>();
   String[] elements = nameValuePairs.split(",");
   for (int i = 0; i < elements.length; i++) {
     String[] pair = elements[i].split("=");
     if (pair.length == 2) {
       result.put(pair[0], pair[1]);
     }
   }
   return result;
 }
コード例 #3
0
 private Object getNestedKey(Object[] array, int index, String keyTwo, String keyThree) {
   Map map = (Map) array[index];
   map = (Map) map.get(keyTwo);
   return map.get(keyThree);
 }
コード例 #4
0
  public void testMappedProperty() {
    EPServiceProvider epService = getEngineInitialized(null, null, null);

    // test map containing first-level property that is an array of primitive or Class
    Map<String, Object> mappedDef = makeMap(new Object[][] {{"p0", Map.class}});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyMappedPropertyMap", mappedDef);

    EPStatement stmt =
        epService.getEPAdministrator().createEPL("select p0('k1') as a from MyMappedPropertyMap");
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    Map<String, Object> eventVal = new HashMap<String, Object>();
    eventVal.put("k1", "v1");
    Map<String, Object> theEvent = makeMap(new Object[][] {{"p0", eventVal}});
    epService.getEPRuntime().sendEvent(theEvent, "MyMappedPropertyMap");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"v1"});
    assertEquals(Object.class, stmt.getEventType().getPropertyType("a"));
    stmt.destroy();

    // test map at the second level of a nested map that is an array of primitive or Class
    Map<String, Object> mappedDefOuter = makeMap(new Object[][] {{"outer", mappedDef}});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyMappedPropertyMapOuter", mappedDefOuter);

    stmt =
        epService
            .getEPAdministrator()
            .createEPL("select outer.p0('k1') as a from MyMappedPropertyMapOuter");
    stmt.addListener(listener);

    Map<String, Object> eventOuter = makeMap(new Object[][] {{"outer", theEvent}});
    epService.getEPRuntime().sendEvent(eventOuter, "MyMappedPropertyMapOuter");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"v1"});
    assertEquals(Object.class, stmt.getEventType().getPropertyType("a"));

    // test map that contains a bean which has a map property
    Map<String, Object> mappedDefOuterTwo =
        makeMap(new Object[][] {{"outerTwo", SupportBeanComplexProps.class}});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyMappedPropertyMapOuterTwo", mappedDefOuterTwo);

    stmt =
        epService
            .getEPAdministrator()
            .createEPL("select outerTwo.mapProperty('xOne') as a from MyMappedPropertyMapOuterTwo");
    stmt.addListener(listener);

    Map<String, Object> eventOuterTwo =
        makeMap(new Object[][] {{"outerTwo", SupportBeanComplexProps.makeDefaultBean()}});
    epService.getEPRuntime().sendEvent(eventOuterTwo, "MyMappedPropertyMapOuterTwo");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"yOne"});
    assertEquals(String.class, stmt.getEventType().getPropertyType("a"));
  }