コード例 #1
0
  @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());
  }
コード例 #2
0
  @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());
  }
コード例 #3
0
  @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());
  }
コード例 #4
0
  @Test
  public void testWeekday() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "WeekDay");
    fi.reset();
    fi.insertOperand(new java.util.Date());
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(o.getClass(), String.class);

    fi.reset();
    Object o2 = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(o.getClass(), String.class);

    assertEquals(o.toString(), o2.toString());
  }
コード例 #5
0
  @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);
  }
コード例 #6
0
  @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));
  }
コード例 #7
0
  @Test
  public void testUnicode() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "Unicode");
    fi.reset();
    fi.insertOperand("10");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
  }
コード例 #8
0
  @Test
  public void testWait() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "Wait");
    fi.reset();
    fi.insertOperand(new Integer(10));
    Object o = fi.evaluateWithTypeChecking();
    assertNull(o);
  }
コード例 #9
0
 @Test
 public void testNavajoRequestToString() throws Exception {
   Navajo n = createTestNavajo();
   FunctionInterface fi = fff.getInstance(cl, "NavajoRequestToString");
   fi.setInMessage(n);
   fi.reset();
   Object o = fi.evaluate();
   assertTrue(((String) o).indexOf("Aap") != -1);
 }
コード例 #10
0
  @Test
  public void testToBinaryFromUrl() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToBinaryFromUrl");
    fi.reset();
    fi.insertOperand("http://www.google.com/google.jpg");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Binary.class, o.getClass());
  }
コード例 #11
0
  @Test
  public void testToLower() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToLower");
    fi.reset();
    fi.insertOperand("AAP");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals("aap", o.toString());
  }
コード例 #12
0
  @Test
  public void testToMemo() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToMemo");
    fi.reset();
    fi.insertOperand(new String("20"));
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Memo.class, o.getClass());
  }
コード例 #13
0
  @Test
  public void testToStopwatchTime() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToStopwatchTime");
    fi.reset();
    fi.insertOperand(new java.util.Date());
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(StopwatchTime.class, o.getClass());
  }
コード例 #14
0
  @Test
  public void testToBinaryFromPath() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToBinaryFromPath");
    fi.reset();
    fi.insertOperand("/aeap");
    Object o = fi.evaluateWithTypeChecking();

    assertNotNull(o);
  }
コード例 #15
0
  @Test
  public void testCurrentTimeMillis() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "CurrentTimeMillis");
    fi.reset();

    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(String.class, o.getClass());
  }
コード例 #16
0
  @Test
  public void testXmlEscape() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "XmlEscape");
    fi.reset();
    fi.insertOperand("aap");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(o.getClass(), String.class);
  }
コード例 #17
0
  @Test
  public void testToClockTime() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToClockTime");
    fi.reset();
    fi.insertOperand("10:00");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals("10:00:00", o.toString());
    assertEquals(ClockTime.class, o.getClass());
  }
コード例 #18
0
  @Test
  public void testEuro() throws Exception {

    DispatcherFactory df = new DispatcherFactory(new TestDispatcher(new TestNavajoConfig()));

    FunctionInterface fi = fff.getInstance(cl, "Euro");
    fi.reset();

    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
  }
コード例 #19
0
  @Test
  public void testDecimalChar() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "DecimalChar");
    fi.reset();
    fi.insertOperand(10046);

    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(String.class, o.getClass());
  }
コード例 #20
0
  @Test
  public void testGetMimeType() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "GetMimeType");
    fi.reset();
    fi.insertOperand(null);

    Object o = fi.evaluateWithTypeChecking();

    assertNull(o);
  }
コード例 #21
0
  @Test
  public void testDate() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "Date");
    fi.reset();
    fi.insertOperand("2008-01-01");

    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(java.util.Date.class, o.getClass());
  }
コード例 #22
0
  @Test
  public void testCheckUrl() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "CheckUrl");
    fi.reset();
    fi.insertOperand("http://www.dexels.com");

    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Boolean.class, o.getClass());
  }
コード例 #23
0
  @Test
  public void testCreateExpression() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "CreateExpression");
    fi.reset();
    fi.insertOperand("aap");

    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(String.class, o.getClass());
  }
コード例 #24
0
  @Test
  public void testGetUrlMimeType() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "GetUrlMimeType");
    fi.reset();
    fi.insertOperand("http://www.dexels.com/index.php");

    Object o = fi.evaluateWithTypeChecking();

    assertNotNull(o);
  }
コード例 #25
0
  @Test
  public void testRandom() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "Random");
    fi.reset();

    Object o = fi.evaluateWithTypeChecking();

    assertNotNull(o);
    assertEquals(Integer.class, o.getClass());
  }
コード例 #26
0
  @Test
  public void testIsNull() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "IsNull");
    fi.reset();
    fi.insertOperand(null);

    Object o = fi.evaluateWithTypeChecking();

    assertNotNull(o);
    assertEquals("true", o.toString());
  }
コード例 #27
0
  @Test
  public void testParseSelection() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ParseSelection");
    fi.reset();
    fi.insertOperand("aap,noot,mies");

    Object o = fi.evaluateWithTypeChecking();

    assertNotNull(o);
    assertTrue(o.getClass().isArray());
  }
コード例 #28
0
  @Test
  public void testXmlUnescape() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "XmlUnescape");
    fi.reset();
    fi.insertOperand("<><>");
    Object o = fi.evaluate();
    assertNotNull(o);
    assertEquals(o.getClass(), String.class);

    boolean exception = false;
    try {
      fi.reset();
      fi.insertOperand(new Integer(10));
      fi.evaluateWithTypeChecking();
    } catch (Exception e) {
      exception = true;
    }

    assertTrue(exception);
  }
コード例 #29
0
  @Test
  public void testAge() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "Age");
    fi.reset();
    fi.setInMessage(createTestNavajo());
    fi.insertOperand(new java.util.Date());

    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Integer.class, o.getClass());
  }
コード例 #30
0
  @Test
  public void testToSecureImage() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToSecureImage");
    fi.reset();
    fi.insertOperand("SECURE");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Binary.class, o.getClass());

    fi.reset();
    fi.insertOperand(null);
    o = fi.evaluateWithTypeChecking();
    assertNull(o);

    System.err.println(System.currentTimeMillis());
    long l = (new Long("1234567890000").longValue() - System.currentTimeMillis());
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MILLISECOND, (int) l);
    System.err.println(SimpleDateFormat.getInstance().format(c.getTime()));
  }