SiddhiHandler implements RestListener, EventHandler<MapEvent> { @Override public void add(Map<String, Object> element) throws RestException { try { SiddhiPlan siddhiPlan = SiddhiPlan.fromMap(element); add(siddhiPlan); } catch (ExecutionPlanException e) { throw new RestInvalidException(e.getMessage(), e); } } SiddhiHandler(Sink eventReceiver);  SiddhiHandler(); void stop(); Map<String, SiddhiPlan> getSiddhiPlans(); @Override void onEvent(MapEvent mapEvent, long sequence, boolean endOfBatch); @Override void add(Map<String, Object> element); synchronized void add(SiddhiPlan siddhiPlan); @Override synchronized void remove(String id); @Override synchronized void synchronize(List<Map<String, Object>> elements); @Override List<Map<String, Object>> list(); synchronized void save(); synchronized void restore();  }
@Test public void add() throws RestException { SiddhiHandler siddhiHandler = new SiddhiHandler(); Map<String, Object> executionPlanMap = new HashMap<>(); Map<String, String> outputTopics = new HashMap<>(); outputTopics.put("testOutput", "outputTopic"); executionPlanMap.put("id", "testID"); executionPlanMap.put("input", Arrays.asList("test", "test2")); executionPlanMap.put("output", outputTopics); executionPlanMap.put("executionPlan", "from test select a insert into testOutput"); siddhiHandler.add(executionPlanMap); assertTrue(siddhiHandler.getSiddhiPlans().containsKey("testID")); }
@Test(expected=RestException.class) public void addPresent() throws RestException { SiddhiHandler siddhiHandler = new SiddhiHandler(); Map<String, Object> executionPlanMap = new HashMap<>(); Map<String, String> outputTopics = new HashMap<>(); outputTopics.put("testOutput", "outputTopic"); executionPlanMap.put("id", "testID"); executionPlanMap.put("input", Arrays.asList("test", "test2")); executionPlanMap.put("output", outputTopics); executionPlanMap.put("executionPlan", "from test select a insert into testOutput"); siddhiHandler.add(executionPlanMap); siddhiHandler.add(executionPlanMap); }
@Test public void addPresentWithHigherVersion() throws RestException { SiddhiHandler siddhiHandler = new SiddhiHandler(); Map<String, Object> executionPlanMap = new HashMap<>(); Map<String, String> outputTopics = new HashMap<>(); outputTopics.put("testOutput", "outputTopic"); executionPlanMap.put("id", "testID"); executionPlanMap.put("input", Arrays.asList("test", "test2")); executionPlanMap.put("output", outputTopics); executionPlanMap.put("executionPlan", "from test select a insert into testOutput"); siddhiHandler.add(executionPlanMap); executionPlanMap.put("version", 1); siddhiHandler.add(executionPlanMap); }
@Test(expected=RestException.class) public void addInvalid() throws RestException { SiddhiHandler siddhiHandler = new SiddhiHandler(); Map<String, Object> executionPlanMap = new HashMap<>(); Map<String, String> outputTopics = new HashMap<>(); outputTopics.put("testOutput", "outputTopic"); executionPlanMap.put("id", "testID"); executionPlanMap.put("input", Arrays.asList("test", "test2")); executionPlanMap.put("output", outputTopics); executionPlanMap.put("executionPlan", "from test select **ERROR** insert into testOutput"); siddhiHandler.add(executionPlanMap); }
@Test(expected=RestException.class) public void addInvalidMap() throws RestException { SiddhiHandler siddhiHandler = new SiddhiHandler(); Map<String, Object> executionPlanMap = new HashMap<>(); Map<String, String> outputTopics = new HashMap<>(); outputTopics.put("testOutput", "outputTopic"); executionPlanMap.put("input", Arrays.asList("test", "test2")); executionPlanMap.put("output", outputTopics); executionPlanMap.put("executionPlan", "from test select a insert into testOutput"); siddhiHandler.add(executionPlanMap); }