@Test public void testStringStringFunction() throws Exception { FunctionInterface fi = fff.getInstance(cl, "StringFunction"); fi.reset(); fi.insertOperand("indexOf"); fi.insertOperand("Apenoot"); fi.insertOperand("n"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); fi.reset(); fi.insertOperand("substring"); fi.insertOperand("Apenoot"); fi.insertOperand(new Integer(0)); fi.insertOperand(new Integer(4)); o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(String.class, o.getClass()); }
@Test public void testSize() throws Exception { FunctionInterface fi = fff.getInstance(cl, "Size"); fi.reset(); fi.insertOperand("NOOT"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); assertEquals("4", o.toString()); fi.reset(); fi.insertOperand(createTestNavajo().getMessage("Aap")); o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); assertEquals("1", o.toString()); ArrayList<Integer> list = new ArrayList<Integer>(); list.add(new Integer(10)); list.add(new Integer(10)); fi.reset(); fi.insertOperand(list); o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); assertEquals("2", o.toString()); }
@Test public void testDateField() throws Exception { FunctionInterface fi = fff.getInstance(cl, "DateField"); fi.reset(); fi.insertOperand(new java.util.Date()); fi.insertOperand("YEAR"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); }
@Test public void testZip() throws Exception { Binary b = new Binary(new byte[] {1, 1, 1}); FunctionInterface fi = fff.getInstance(cl, "Zip"); fi.reset(); fi.insertOperand(b); fi.insertOperand("aap"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(o.getClass(), Binary.class); }
@Test public void testStringDistance() throws Exception { FunctionInterface fi = fff.getInstance(cl, "StringDistance"); fi.reset(); fi.insertOperand("AAP"); fi.insertOperand("NOOT"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); }
@Test public void testScaleImageFree() throws Exception { FunctionInterface fi = fff.getInstance(cl, "ScaleImageFree"); fi.reset(); fi.insertOperand(null); fi.insertOperand(10); fi.insertOperand(10); Object o = fi.evaluateWithTypeChecking(); assertNull(o); }
@Test public void testCheckUniqueness() throws Exception { FunctionInterface fi = fff.getInstance(cl, "CheckUniqueness"); fi.reset(); fi.setInMessage(createTestNavajo()); fi.insertOperand("Aap"); fi.insertOperand("Noot"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Boolean.class, o.getClass()); }
@Test public void testEqualsPattern() throws Exception { FunctionInterface fi = fff.getInstance(cl, "EqualsPattern"); fi.reset(); fi.insertOperand("apenoot"); fi.insertOperand("[A-z]*"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Boolean.class, o.getClass()); assertEquals("true", o.toString()); }
@Test public void testExists() throws Exception { FunctionInterface fi = fff.getInstance(cl, "Exists"); fi.reset(); fi.setInMessage(createTestNavajo()); fi.insertOperand(createTestNavajo().getMessage("Aap")); fi.insertOperand("true"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals("true", o.toString()); }
@Test public void testForAll() throws Exception { FunctionInterface fi = fff.getInstance(cl, "ForAll"); fi.reset(); fi.setInMessage(createTestNavajo()); fi.insertOperand("/Aap"); fi.insertOperand("[Noot] != 20"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); }
@Test public void testFormatDate() throws Exception { FunctionInterface fi = fff.getInstance(cl, "FormatDate"); fi.reset(); fi.insertOperand(new java.util.Date()); fi.insertOperand("yyyy-MM-dd"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); }
@Test public void testRound() throws Exception { FunctionInterface fi = fff.getInstance(cl, "Round"); fi.reset(); fi.insertOperand(new Double(10.5)); fi.insertOperand(0); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Double.class, o.getClass()); }
@Test public void testParseStringList() throws Exception { FunctionInterface fi = fff.getInstance(cl, "ParseStringList"); fi.reset(); fi.insertOperand("aap,noot,mies"); fi.insertOperand(","); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertTrue(List.class.isInstance(o)); }
@Test public void testGetWeekDayDate2() throws Exception { FunctionInterface fi = fff.getInstance(cl, "GetWeekDayDate"); fi.reset(); fi.insertOperand("SUN"); fi.insertOperand("forward"); // fi.insertOperand(new java.util.Date()); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(java.util.Date.class, o.getClass()); }
@Test public void testGetPropertySubType() throws Exception { FunctionInterface fi = fff.getInstance(cl, "GetPropertySubType"); fi.reset(); fi.setInMessage(createTestNavajo()); Navajo doc = createTestNavajo(); fi.insertOperand("/Single/Selectie"); fi.insertOperand("testsub"); Object o = fi.evaluateWithTypeChecking(); assertNull(o); }
@Test public void testInMonthTurnInterval() throws Exception { FunctionInterface fi = fff.getInstance(cl, "InMonthTurnInterval"); fi.reset(); fi.insertOperand(new java.util.Date()); fi.insertOperand(5); fi.insertOperand(true); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Boolean.class, o.getClass()); }
@Test public void testRandomString2() throws Exception { FunctionInterface fi = fff.getInstance(cl, "RandomString"); fi.reset(); fi.insertOperand(10); fi.insertOperand("abcdef"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(String.class, o.getClass()); assertEquals(o.toString().indexOf("g"), -1); }
@Test public void testSetAllProperties() throws Exception { FunctionInterface fi = fff.getInstance(cl, "SetAllProperties"); fi.reset(); fi.setInMessage(createTestNavajo()); fi.insertOperand(createTestNavajo().getMessage("Aap")); fi.insertOperand("Noot"); fi.insertOperand(new Integer(2)); Object o = fi.evaluateWithTypeChecking(); assertNull(o); }
@Test public void testStringPadding3() throws Exception { FunctionInterface fi = fff.getInstance(cl, "StringPadding"); fi.reset(); fi.insertOperand("aap"); fi.insertOperand(new Integer(10)); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(String.class, o.getClass()); assertEquals("aap ", o.toString()); }
@Test public void testGetMessage() throws Exception { FunctionInterface fi = fff.getInstance(cl, "GetMessage"); Navajo doc = createTestNavajo(); fi.setInMessage(doc); fi.reset(); fi.insertOperand(doc.getMessage("Aap")); fi.insertOperand(0); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); }
@Test public void testGetProperty() throws Exception { FunctionInterface fi = fff.getInstance(cl, "GetProperty"); fi.reset(); fi.setInMessage(createTestNavajo()); Navajo doc = createTestNavajo(); fi.insertOperand(doc.getMessage("Single")); fi.insertOperand("Selectie"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertTrue(Property.class.isInstance(o)); }
@Test public void testSumProperties() throws Exception { FunctionInterface fi = fff.getInstance(cl, "SumProperties"); fi.setInMessage(createTestNavajo()); fi.reset(); fi.insertOperand("Aap"); fi.insertOperand("Noot"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); assertEquals("10", o.toString()); }
@Test public void testIsServiceCached() throws Exception { FunctionInterface fi = fff.getInstance(cl, "IsServiceCached"); fi.reset(); fi.insertOperand("aap"); fi.insertOperand("noot"); try { Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); } catch (NullPointerException n) { } }
@Test public void testFormatStringList() throws Exception { FunctionInterface fi = fff.getInstance(cl, "FormatStringList"); fi.reset(); ArrayList<String> list = new ArrayList<String>(); list.add(new String("10")); list.add(new String("20")); fi.insertOperand(list); fi.insertOperand("&"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals("10&20", o.toString()); }
@Test public void testArraySelection() throws Exception { FunctionInterface fi = fff.getInstance(cl, "ArraySelection"); fi.reset(); fi.setInMessage(createTestNavajo()); fi.insertOperand("Aap"); fi.insertOperand("Noot"); fi.insertOperand("10"); try { Object o = fi.evaluateWithTypeChecking(); } catch (Exception e) { } }
@Test public void testToMilliseconds() throws Exception { FunctionInterface fi = fff.getInstance(cl, "ToMilliseconds"); fi.reset(); fi.insertOperand(new StopwatchTime(20)); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Integer.class, o.getClass()); fi.reset(); fi.insertOperand(new ClockTime(new java.util.Date())); o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(Long.class, o.getClass()); }
@Test public void testAbs() throws Exception { FunctionInterface fi = fff.getInstance(cl, "Abs"); // Test Integer. fi.reset(); fi.insertOperand(new Integer(-10)); Object o = fi.evaluateWithTypeChecking(); assertEquals(o.getClass(), Integer.class); assertEquals(((Integer) o).intValue(), 10); // Test Double. fi.reset(); fi.insertOperand(new Double(-10)); o = fi.evaluateWithTypeChecking(); assertEquals(o.getClass(), Double.class); assertEquals(((Double) o).intValue(), 10); // Test bogus. boolean bogus = false; fi.reset(); fi.insertOperand(new String("-10")); try { o = fi.evaluateWithTypeChecking(); } catch (TMLExpressionException e) { bogus = true; } assertTrue(bogus); // Test null. fi.reset(); fi.insertOperand(null); o = fi.evaluateWithTypeChecking(); assertNull(o); // Test empty parameters. boolean empty = false; fi.reset(); try { o = fi.evaluateWithTypeChecking(); } catch (TMLExpressionException e) { empty = true; } assertTrue(empty); }
@Test public void testTrunc() throws Exception { FunctionInterface fi = fff.getInstance(cl, "Trunc"); fi.reset(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date d1 = sdf.parse("2009-12-01 12:34"); Date d2 = sdf.parse("2009-12-01 14:54"); fi.insertOperand(d1); Date d3 = (Date) fi.evaluate(); fi.reset(); fi.insertOperand(d2); Date d4 = (Date) fi.evaluate(); assertEquals(sdf.format(d3), sdf.format(d4)); }
@Test public void testOffsetDate() throws Exception { FunctionInterface fi = fff.getInstance(cl, "OffsetDate"); fi.reset(); fi.insertOperand(new java.util.Date()); fi.insertOperand(10); fi.insertOperand(6); fi.insertOperand(17); fi.insertOperand(12); fi.insertOperand(0); fi.insertOperand(0); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); assertEquals(java.util.Date.class, o.getClass()); }
@Test public void testUnicode() throws Exception { FunctionInterface fi = fff.getInstance(cl, "Unicode"); fi.reset(); fi.insertOperand("10"); Object o = fi.evaluateWithTypeChecking(); assertNotNull(o); }