Search in sources :

Example 1 with ArgsException

use of com.disney.groovity.ArgsException in project groovity by disney.

the class TestCoreGroovity method testArgs.

@Test
public void testArgs() throws Exception {
    Binding binding = new Binding();
    Exception e = null;
    try {
        run("/args", binding);
    } catch (ArgsException me) {
        e = me;
    }
    Assert.assertNotNull(e);
    binding.setProperty("name", "John");
    binding.setProperty("age", "34");
    binding.setProperty("hobby", "abc");
    binding.setProperty("premium", "TRUE");
    String result = run("/args", binding);
    Assert.assertEquals("John java.lang.String [abc] [] [Ljava.lang.String; 34 java.lang.Long [1] [I [2, 4] java.util.ArrayList java.lang.Integer  true 10 java.lang.Integer Always Sometimes", result);
    binding = new Binding();
    binding.setProperty("level", new String[] { "5", "6" });
    binding.setProperty("name", "Jack");
    binding.setProperty("age", new byte[] { (byte) 21, (byte) 99 });
    binding.setProperty("hobby", new String[] { "abc", "def" });
    binding.setProperty("friend", new int[] { 123, 456 });
    Map<String, String> partner = new HashMap<>();
    partner.put("name", "Jill");
    binding.setProperty("partner", partner);
    binding.setProperty("limit", "33");
    binding.setProperty("fixed", "broken");
    binding.setProperty("fluid", "flexible");
    binding.setProperty("premium", "false");
    binding.setProperty("range", Arrays.asList("7", "9"));
    result = run("/args", binding);
    Assert.assertEquals("Jack java.lang.String [abc, def] [123, 456] [Ljava.lang.String; 21 java.lang.Long [5, 6] [I [7, 9] java.util.ArrayList java.lang.Integer {name=Jill} false 33 java.lang.Integer Always flexible", result);
}
Also used : Binding(groovy.lang.Binding) ArgsException(com.disney.groovity.ArgsException) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) ArgsException(com.disney.groovity.ArgsException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 2 with ArgsException

use of com.disney.groovity.ArgsException in project groovity by disney.

the class TestCoreGroovity method testNestedArgs.

@Test
public void testNestedArgs() throws Exception {
    Binding binding = new Binding();
    AssertionError ae = null;
    try {
        run("/argsCaller", binding);
    } catch (AssertionError ae1) {
        ae = ae1;
    }
    Assert.assertNotNull(ae);
    binding = new Binding();
    binding.setProperty("api_key", "user");
    ArgsException me = null;
    try {
        run("/argsCaller", binding);
    } catch (ArgsException me1) {
        me = me1;
    }
    Assert.assertNotNull(me);
    binding = new Binding();
    binding.setProperty("api_key", "admin");
    binding.setProperty("foo", "8172361");
    String result = run("/argsCaller", binding);
    Assert.assertEquals(" 8172361 java.lang.Long says admin ", result);
}
Also used : Binding(groovy.lang.Binding) ArgsException(com.disney.groovity.ArgsException) Test(org.junit.Test)

Aggregations

ArgsException (com.disney.groovity.ArgsException)2 Binding (groovy.lang.Binding)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1