@Test public void testHelloWorld() throws Exception { // read in the source final Reader reader = new InputStreamReader(getClass().getResourceAsStream("test_mvel.drl")); RuleBase ruleBase = loadRuleBase(reader); final WorkingMemory workingMemory = ruleBase.newStatefulSession(); final List list = new ArrayList(); workingMemory.setGlobal("list", list); final List list2 = new ArrayList(); workingMemory.setGlobal("list2", list2); Cheese c = new Cheese("stilton", 10); workingMemory.insert(c); workingMemory.fireAllRules(); assertEquals(2, list.size()); assertEquals(BigInteger.valueOf(30), list.get(0)); assertEquals(Integer.valueOf(22), list.get(1)); assertEquals("hello world", list2.get(0)); Date dt = DateUtils.parseDate("10-Jul-1974", new DateFormatsImpl()); assertEquals(dt, c.getUsedBy()); }
@Test public void testString() throws Exception { MVELDateCoercion co = new MVELDateCoercion(); assertTrue(co.canConvertFrom(Date.class)); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK); String dt = df.format(df.parse("10-Jul-1974")); Date dt_ = DateUtils.parseDate(dt, new DateFormatsImpl()); assertEquals(dt_, co.convertFrom(dt)); }
private String makeNewAssetName(final String baseName, final ResourceTypeDefinition type) { Calendar now = Calendar.getInstance(); StringBuilder sb = new StringBuilder(baseName); sb.append(" (converted on "); sb.append(DateUtils.format(now.getTime())); sb.append(" "); sb.append(now.get(Calendar.HOUR_OF_DAY)); sb.append("-"); sb.append(now.get(Calendar.MINUTE)); sb.append("-"); sb.append(now.get(Calendar.SECOND)); sb.append(")"); sb.append(".").append(type.getSuffix()); return sb.toString(); }
@Test public void testHelloWorld() throws Exception { // read in the source KieBase kbase = loadKnowledgeBase("test_mvel.drl"); KieSession ksession = kbase.newKieSession(); final List list = new ArrayList(); ksession.setGlobal("list", list); final List list2 = new ArrayList(); ksession.setGlobal("list2", list2); Cheese c = new Cheese("stilton", 10); ksession.insert(c); ksession.fireAllRules(); assertEquals(2, list.size()); assertEquals(BigInteger.valueOf(30), list.get(0)); assertEquals(Integer.valueOf(22), list.get(1)); assertEquals("hello world", list2.get(0)); Date dt = DateUtils.parseDate("10-Jul-1974"); assertEquals(dt, c.getUsedBy()); }
private static long getTimeAsLong(String value) { return DateUtils.parseDate(value).getTime(); }