org.testng.AssertJUnit Java Examples

The following examples show how to use org.testng.AssertJUnit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RTabbedPaneTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void selectANoIconAndTextTab() throws Throwable {
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            tabbedPane = (JTabbedPane) ComponentUtils.findComponent(JTabbedPane.class, frame);
            tabbedPane.setTitleAt(3, null);
            tabbedPane.setIconAt(3, null);
            RTabbedPane rtp = new RTabbedPane(tabbedPane, null, null, lr);
            tabbedPane.setSelectedIndex(3);
            rtp.stateChanged(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("tabIndex-3", call.getState());
}
 
Example #2
Source File: BigNumberTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testMinus() throws Exception
{
	Template t = gt.getTemplate("/exp/bignumber/number_minus_template.html");
	this.bind(t, "d1", d1, "d2", d2);
	String str = t.render();
	String expected = getFileContent("/exp/bignumber/number_minus_expected.html");
	AssertJUnit.assertEquals(expected, str);

	t = gt.getTemplate("/exp/bignumber/number_minus_template.html");
	this.bind(t, "d1", d1, "d2", d2);
	str = t.render();

	AssertJUnit.assertEquals(this.getFileContent("/exp/bignumber/number_minus_expected.html"), str);

}
 
Example #3
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void getAttribute() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    AssertJUnit.assertTrue(Boolean.valueOf(element1.getAttribute("enabled")));
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            button.setEnabled(false);
        }
    });
    EventQueueWait.waitTillDisabled(button);
    AssertJUnit.assertFalse(Boolean.valueOf(element1.getAttribute("enabled")));
}
 
Example #4
Source File: RListTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void selectMultipleItemSelection() {
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            list = (JList) ComponentUtils.findComponent(JList.class, frame);
            list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            list.setSelectedIndices(new int[] { 0, 2 });
            RList rList = new RList(list, null, null, lr);
            rList.focusLost(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("[Jane Doe, Kathy Green]", call.getState());
}
 
Example #5
Source File: OnDemandQueryTableTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiParserException.class)
public void test6() throws InterruptedException {
    log.info("Test5 table");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "define table StockTable (symbol string, price float, volume long); ";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    try {
        siddhiAppRuntime.start();
        Event[] events = siddhiAppRuntime.query("" +
                "from StockTable1 " +
                "on price > 5 " +
                "select symbol1, sum(volume)  totalVolume " +
                "group by symbol " +
                "having totalVolume >150 ");
        EventPrinter.print(events);
        AssertJUnit.assertEquals(1, events.length);
        AssertJUnit.assertEquals(200L, events[0].getData(1));

    } finally {
        siddhiAppRuntime.shutdown();
    }
}
 
Example #6
Source File: RFXTreeTableViewTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void selectACell() {
    TreeTableView<?> treeTableView = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        TreeTableViewSelectionModel<?> selectionModel = treeTableView.getSelectionModel();
        selectionModel.setCellSelectionEnabled(true);
        Point2D point = getPoint(treeTableView, 1, 0);
        RFXTreeTableView rfxTreeTableView = new RFXTreeTableView(treeTableView, null, point, lr);
        rfxTreeTableView.focusGained(null);
        @SuppressWarnings("rawtypes")
        TreeTableColumn column = getTreeTableColumnAt(treeTableView, 0);
        selectionModel.select(1, column);
        rfxTreeTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("{\"cells\":[[\"/Sales Department/Ethan Williams\",\"Employee\"]]}", recording.getParameters()[0]);
}
 
Example #7
Source File: LayoutTagTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testLayout() throws Exception
{

	User user = User.getTestUser();

	Template t = gt.getTemplate("/tag/layout_template.html");
	this.bind(t, "user", user);
	String str = t.render();
	AssertJUnit.assertEquals(this.getFileContent("/tag/layout_expected.html"), str);
	
			t = gt.getTemplate("/tag/layout_template.html");
			this.bind(t, "user", user);
			str = t.render();
			AssertJUnit.assertEquals(this.getFileContent("/tag/layout_expected.html"), str);
	
}
 
Example #8
Source File: RFXTreeTableViewTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void getText() {
    TreeTableView<?> treeTableView = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    Platform.runLater(() -> {
        RFXTreeTableView rfxTreeTableView = new RFXTreeTableView(treeTableView, null, null, lr);
        treeTableView.getSelectionModel().select(2);
        rfxTreeTableView.focusLost(null);
        text.add(rfxTreeTableView.getAttribute("text"));
    });
    new Wait("Waiting for tree table view text.") {
        @Override
        public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals("{\"rows\":[\"/Sales Department/Emma Jones\"]}", text.get(0));
}
 
Example #9
Source File: TimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void timeWindowBatchTest19() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" +
            "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.timeBatch(1 sec, 123L, true) " +
            "select symbol, sum(price) as total " +
            "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"IBM", 700f, 1});
    Thread.sleep(1100);
    inputHandler.send(new Object[]{"WSO2", 60.5f, 2});
    inputHandler.send(new Object[]{"IBM", 700f, 3});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 4});
    Thread.sleep(1100);
    inputHandler.send(new Object[]{"IBM", 700f, 5});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 6});
    Thread.sleep(1200);
    AssertJUnit.assertEquals(6, inEventCount);
    AssertJUnit.assertEquals(3, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
 
Example #10
Source File: TimestampInequalityRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuleMinus2Hours() throws IOException, ClassNotFoundException {
  Rule rule = TimestampInequalityRule.getRule(">", "-2h");
  Calendar cal = new GregorianCalendar();
  cal.setTime(new Date(System.currentTimeMillis()));
  cal.add(Calendar.HOUR_OF_DAY, -1);
  LogData logData = createLogData(cal);
  AssertJUnit.assertTrue(rule.evaluate(logData, null));
}
 
Example #11
Source File: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent2"})
public void testQueryAbsent3() throws InterruptedException {
    log.info("Test the query not e1 and e2 -> e3 with e2 and e3 within 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from not Stream1[price>10] and e2=Stream2[price>20] -> e3=Stream3[price>30] " +
            "select e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"IBM",
            "GOOGLE"});

    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();

    stream2.send(new Object[]{"IBM", 25.0f, 100});
    Thread.sleep(100);
    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});
    Thread.sleep(100);

    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #12
Source File: EventTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryParser() {
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT);
    Query query = new Query();
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.NOT_EQUAL, Expression.value(50))));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")));
    query.insertInto("outputStream");
    Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
    Map<String, Table> tableMap = new HashMap<String, Table>();
    Map<String, Window> eventWindowMap = new HashMap<String, Window>();
    Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
    Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
    Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
    Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
    LockSynchronizer lockSynchronizer = new LockSynchronizer();
    streamDefinitionMap.put("cseEventStream", streamDefinition);
    streamDefinitionMap.put("outputStream", outStreamDefinition);
    SiddhiContext siddhicontext = new SiddhiContext();
    SiddhiAppContext context = new SiddhiAppContext();
    context.setSiddhiContext(siddhicontext);
    context.setIdGenerator(new IdGenerator());
    context.setSnapshotService(new SnapshotService(context));
    QueryRuntimeImpl runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap,
            windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap,
            lockSynchronizer, "1", false, SiddhiConstants.PARTITION_ID_DEFAULT);
    AssertJUnit.assertNotNull(runtime);
    AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
    AssertJUnit.assertNotNull(runtime.getSelector());
    AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
 
Example #13
Source File: BatchProcessingContextTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLogDataStoreFile() throws IOException {
  LogDataStore createLogDataStore = batchProcessingContext.createLogDataStore(LogDataStoreType.FILE);

  AssertJUnit.assertEquals(FileLogDataStore.class.getName(), createLogDataStore.getClass().getName());
  AssertJUnit.assertEquals(createLogDataStore, batchProcessingContext.getDataStore());
}
 
Example #14
Source File: JComboBoxTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void getAllOptions() throws Throwable {
    driver = new JavaDriver();
    String[] patternExamples = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };

    List<WebElement> options = driver.findElements(By.cssSelector("combo-box::all-options"));
    AssertJUnit.assertEquals(patternExamples.length, options.size());
    for (int i = 0; i < patternExamples.length; i++) {
        AssertJUnit.assertEquals(patternExamples[i], options.get(i).getText());
    }
}
 
Example #15
Source File: LogDataTableModelTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarkRowsIntMarkerColors() {
  AssertJUnit.assertFalse(dataTableModel.isMarked(2));
  AssertJUnit.assertFalse(dataTableModel.isMarked(3));
  AssertJUnit.assertTrue(dataTableModel.isMarked(4));
  dataTableModel.markRows(MarkerColors.Yellow, 2, 3, 4);
  AssertJUnit.assertEquals(MarkerColors.Yellow, dataTableModel.getMarkerColors(2));
  AssertJUnit.assertEquals(MarkerColors.Yellow, dataTableModel.getMarkerColors(3));
  AssertJUnit.assertEquals(MarkerColors.Yellow, dataTableModel.getMarkerColors(4));
  dataTableModel.markRows(MarkerColors.Aqua, 2);
  AssertJUnit.assertEquals(MarkerColors.Aqua, dataTableModel.getMarkerColors(2));
}
 
Example #16
Source File: ExistsRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * getRule with "msg".
 */
@Test public void test5() throws IOException, ClassNotFoundException {
    Stack<Object> stack = new Stack<>();
    stack.push("msg");
    Rule rule = (Rule) SerializationTestHelper.serializeClone(ExistsRule.getRule(stack));
    AssertJUnit.assertEquals(0, stack.size());
    LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
            Logger.getRootLogger(), System.currentTimeMillis(), Level.INFO,
            "Hello, World", null);
    AssertJUnit.assertTrue(rule.evaluate(Log4jUtil.translateLog4j(event), null));
}
 
Example #17
Source File: NotRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * Test Not of LevelEqualsRule.
 */
@Test public void test3() {
    Stack<Object> stack = new Stack<>();
    stack.push(LevelEqualsRule.getRule("INFO"));
    Rule rule = NotRule.getRule(stack);
    AssertJUnit.assertEquals(0, stack.size());
    Calendar cal = new GregorianCalendar(2008, 4, 21, 0, 45, 44);
    LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
            Logger.getRootLogger(), cal.getTimeInMillis(), Level.INFO,
            "Hello, World", null);
    AssertJUnit.assertFalse(rule.evaluate(Log4jUtil.translateLog4j(event), null));
}
 
Example #18
Source File: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent25"})
public void testQueryAbsent26() throws InterruptedException {
    log.info("Test the query e1 -> (not e2 for 1 sec and not e3 for 1 sec) within 2 sec with e1 and e2");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10] -> (not Stream2[price>20] for 1 sec and not Stream3[price>30] for 1 sec) " +
            "within 2 sec " +
            "select e1.symbol as symbol1 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.0f, 100});
    Thread.sleep(100);
    stream2.send(new Object[]{"IBM", 25.0f, 101});
    Thread.sleep(1100);

    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #19
Source File: JPasswordFieldTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void clear() throws Throwable {
    driver = new JavaDriver();
    WebElement passField = driver.findElement(By.cssSelector("password-field"));
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
    passField.sendKeys("password");
    AssertJUnit.assertEquals("password", passField.getText());
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
}
 
Example #20
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void findElementByTagName() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element = driver.findElement(By.tagName("menu"));
    AssertJUnit.assertNotNull(element);
    AssertJUnit.assertEquals("File", element.getText());
}
 
Example #21
Source File: TimestampInequalityRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuleWithTimeOnly3() throws IOException, ClassNotFoundException {
  Rule rule = TimestampInequalityRule.getRule(">", "16:22:20");
  Calendar cal = new GregorianCalendar();
  cal.setTime(new Date(System.currentTimeMillis()));
  cal.set(Calendar.HOUR_OF_DAY, 18);
  LogData logData = createLogData(cal);
  AssertJUnit.assertTrue(rule.evaluate(logData, null));
}
 
Example #22
Source File: AndRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
    * Test And of Level and Time when Time does not match.
    */
   @Test
   public void test5() {
Stack<Object> stack = new Stack<>();
stack.push(LevelEqualsRule.getRule("INFO"));
stack.push(TimestampInequalityRule.getRule(">=", "2009-05-21 00:44:45"));
Rule rule = AndRule.getRule(stack);
AssertJUnit.assertEquals(0, stack.size());
Calendar cal = new GregorianCalendar(2008, 4, 21, 0, 45, 44);
// LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger", Logger.getRootLogger(), cal.getTimeInMillis(), Level.INFO,
// "Hello, World", null);
LogData event = new LogDataBuilder().withClass("org.apache.log4j.Logger").withLoggerName("")
	.withDate(new Date(cal.getTimeInMillis())).withLevel(java.util.logging.Level.INFO).withMessage("Hello, World").build();
AssertJUnit.assertFalse(rule.evaluate(event, null));
   }
 
Example #23
Source File: RTreeTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void nodeModification() throws Throwable, InvocationTargetException {
    final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            Rectangle rowBounds = tree.getRowBounds(0);
            RTree rTree = new RTree(tree, null, rowBounds.getLocation(), lr);
            tree.expandRow(0);
            tree.setSelectionRow(0);
            rTree.mouseButton1Pressed(null);
            DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
            root.setUserObject("Root Node - modified");
            rTree.focusGained(null);
            tree.expandRow(0);
            tree.setSelectionRow(0);
            rTree.mouseButton1Pressed(null);
        }
    });
    List<Call> calls = lr.getCalls();
    Call call = calls.get(0);
    AssertJUnit.assertEquals("click", call.getFunction());
    AssertJUnit.assertEquals("/Root Node", call.getCellinfo());
    call = calls.get(1);
    AssertJUnit.assertEquals("click", call.getFunction());
    AssertJUnit.assertEquals("/Root Node - modified", call.getCellinfo());
}
 
Example #24
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent19"})
public void testQueryAbsent20() throws InterruptedException {
    log.info("Test the query e1, (not e2 and e3) within 1 sec with e1 and e3 within 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10], (not Stream2[price>20] and e3=Stream3[price>30]) within 1 sec " +
            "select e1.symbol as symbol1, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2",
            "GOOGLE"});

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.0f, 100});
    Thread.sleep(100);
    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #25
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent8"})
public void testQueryAbsent9() throws InterruptedException {
    log.info("Test the query not e1 for 1 sec and e2, e3 with e2 and e3 within 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from not Stream1[price>10] for 1 sec and e2=Stream2[price>20], e3=Stream3[price>30] " +
            "select e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();

    stream2.send(new Object[]{"IBM", 25.0f, 100});
    Thread.sleep(100);
    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});

    TestUtil.waitForInEvents(1000, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #26
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent11"})
public void testQueryAbsent12() throws InterruptedException {
    log.info("Test the query e1, not e2 for 1 sec or e3 with e1 and e3 with extra 1 sec to make sure no " +
            "duplicates");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10], not Stream2[price>20] for 1 sec or e3=Stream3[price>30] " +
            "select e1.symbol as symbol1, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2",
            "GOOGLE"});

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 15.0f, 100});
    Thread.sleep(100);
    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});

    TestUtil.waitForInEvents(1000, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #27
Source File: SelectTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDefault() throws Exception
{
	Template t = gt.getTemplate("/control/select/default_template.html");
	this.bind(t, "dataList", data);
	String str = t.render();
	AssertJUnit.assertEquals(this.getFileContent("/control/select/default_expected.html"), str);

	t = gt.getTemplate("/control/select/default_template.html");
	this.bind(t, "dataList", data);
	str = t.render();
	AssertJUnit.assertEquals(this.getFileContent("/control/select/default_expected.html"), str);

}
 
Example #28
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent47"})
public void testQueryAbsent48() throws InterruptedException {
    log.info("Test the query every (not e1 for 1 sec or not e2 for 1 sec), e3 with only e3 after 2 seconds");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from every (not Stream1[price>10] for 1 sec or not Stream2[price>20] for 1 sec), " +
            "e3=Stream3[price>30] " +
            "select e3.symbol as symbol " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2"});

    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();
    Thread.sleep(2100);
    stream3.send(new Object[]{"WSO2", 35.0f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #29
Source File: LogicalAbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent16"})
public void testQueryAbsent17() throws InterruptedException {
    log.info("Test the query not e1 for 1 sec or e2, e3 with e1 and e3 within 1 sec");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from not Stream1[price>10] for 1 sec or e2=Stream2[price>20], e3=Stream3[price>30] " +
            "select e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2",
            "GOOGLE"});

    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();

    stream2.send(new Object[]{"WSO2", 25.0f, 100});
    Thread.sleep(100);
    stream3.send(new Object[]{"GOOGLE", 35.0f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example #30
Source File: NotEqualsRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * getRule with "timestamp" and time.
 */
@Test public void test4() {
    Stack<Object> stack = new Stack<>();
    stack.push("timestamp");
    stack.push("2008-05-21 00:45:44");
    Rule rule = NotEqualsRule.getRule(stack);
    AssertJUnit.assertEquals(0, stack.size());
    Calendar cal = new GregorianCalendar(2009, 4, 21, 0, 45, 44);
    LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
            Logger.getRootLogger(), cal.getTimeInMillis(), Level.INFO,
            "Hello, World", null);
    AssertJUnit.assertTrue(rule.evaluate(Log4jUtil.translateLog4j(event), null));
}