Java Code Examples for org.testng.AssertJUnit

The following examples show how to use org.testng.AssertJUnit. These examples are extracted from open source projects. 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 Project: marathonv5   Source File: RListTest.java    License: 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 2
@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 3
Source Project: marathonv5   Source File: RTabbedPaneTest.java    License: 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 4
Source Project: marathonv5   Source File: RFXTreeTableViewTest.java    License: 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 5
Source Project: marathonv5   Source File: RFXTreeTableViewTest.java    License: 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 6
@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 7
Source Project: marathonv5   Source File: JavaDriverTest.java    License: 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 8
Source Project: siddhi   Source File: OnDemandQueryTableTestCase.java    License: 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 9
Source Project: siddhi   Source File: LogicalAbsentSequenceTestCase.java    License: 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 10
Source Project: vesta-id-generator   Source File: CustomIdMetaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(groups = {"idService"})
public void testSimple() {
    IdService idService = (IdService) applicationContext.getBean("idService");

    long id = idService.genId();
    Id ido = idService.expId(id);
    long id1 = idService.makeId(ido.getVersion(), ido.getType(),
            ido.getGenMethod(), ido.getTime(), ido.getSeq(),
            ido.getMachine());

    System.out.println(id + ":" + ido);

    AssertJUnit.assertEquals(id, id1);
}
 
Example 11
Source Project: siddhi   Source File: LogicalAbsentPatternTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent20"})
public void testQueryAbsent21() throws InterruptedException {
    log.info("Test the query e1 -> (not e2 and e3) within 1 sec with e1 and e3 after 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");

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

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

    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 12
Source Project: otroslogviewer   Source File: OrRuleTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test deserialized Or.
 */
@Test public void test7() throws IOException, ClassNotFoundException {
    Stack<Object> stack = new Stack<>();
    stack.push(LevelEqualsRule.getRule("INFO"));
    stack.push(TimestampInequalityRule.getRule(">=", "2008-05-21 00:44:45"));
    Rule rule = (Rule) SerializationTestHelper.serializeClone(OrRule.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.assertTrue(rule.evaluate(Log4jUtil.translateLog4j(event), null));
}
 
Example 13
Source Project: otroslogviewer   Source File: NotRuleTest.java    License: 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 14
Source Project: otroslogviewer   Source File: LogDataTableModelTest.java    License: 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 15
Source Project: marathonv5   Source File: JComboBox2Test.java    License: Apache License 2.0 5 votes vote down vote up
public void clickItem() throws Throwable {
    driver = new JavaDriver();
    @SuppressWarnings("unused")
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z", "EEE, MMM d, ''yy",
            "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    WebElement combo = driver.findElement(By.cssSelector("combo-box"));
    AssertJUnit.assertEquals("" + 0, combo.getAttribute("selectedIndex"));
    WebElement option = driver.findElement(By.cssSelector("combo-box::nth-option(3)"));
    option.click();
    AssertJUnit.assertEquals("" + 2, combo.getAttribute("selectedIndex"));
}
 
Example 16
@Test
public void testRuleWithDateOnly() throws IOException, ClassNotFoundException {
  Rule rule = TimestampInequalityRule.getRule(">=", "2008-05-21");
  Calendar cal = new GregorianCalendar(2008, Calendar.MAY, 21, 23, 45, 44);
  LogData logData = new LogDataBuilder().withClass("a.B").withLoggerName(Logger.getRootLogger().getName()).withDate(cal.getTime()).withMessage("Hi")
      .withLevel(java.util.logging.Level.INFO).build();
  AssertJUnit.assertTrue(rule.evaluate(logData, null));
}
 
Example 17
Source Project: otroslogviewer   Source File: AndRuleTest.java    License: 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 18
@Test
public void testExtraLoader() throws Exception
{

	Map data = getData();
	MapResourceLoader strLoader = new MapResourceLoader(data);
	Template t = gt.getTemplate("db:1", strLoader);
	t.binding("a", "abc");
	String result = t.render();
	AssertJUnit.assertEquals("abc", result);

}
 
Example 19
Source Project: siddhi   Source File: TimeBatchWindowTestCase.java    License: 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 20
Source Project: otroslogviewer   Source File: BatchProcessingContextTest.java    License: 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 21
Source Project: siddhi   Source File: EventTestCase.java    License: 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 22
@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 23
Source Project: marathonv5   Source File: JPasswordFieldTest.java    License: 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 24
Source Project: marathonv5   Source File: JavaDriverTest.java    License: 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 25
@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 26
Source Project: siddhi   Source File: LogicalAbsentSequenceTestCase.java    License: 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 27
Source Project: otroslogviewer   Source File: NotEqualsRuleTest.java    License: 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));
}
 
Example 28
Source Project: siddhi   Source File: LogicalAbsentSequenceTestCase.java    License: 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 29
Source Project: siddhi   Source File: LogicalAbsentPatternTestCase.java    License: 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 30
@Test
public void testRuleWithTBetweenDateAndTime3() throws IOException, ClassNotFoundException {
  Rule rule = TimestampInequalityRule.getRule(">=", "2008-05-21T00:44");
  Calendar cal = new GregorianCalendar(2008, Calendar.MAY, 21, 0, 45, 44);
  LogData logData = createLogData(cal);
  AssertJUnit.assertTrue(rule.evaluate(logData, null));
}