Resource implements JsonSerializable, Serializable { public Object invokeMethod(String methodName) { return invokeMethod(methodName, (Class []) null, (Object []) null); } Resource(LocalResourcePool pool, ResourceId resourceId, Object r);   Resource(LocalResourcePool pool, ResourceId resourceId, boolean serializable, String className); ResourceId getResourceId(); String getClassName(); Object get(); T get(Class<T> clazz); boolean isSerializable(); boolean isRemote(); boolean isLocal(); Object invokeMethod(String methodName); Resource invokeMethod(String methodName, String returnResourceName); Object invokeMethod(String methodName, Object [] params); Object invokeMethod(
          String methodName, ArrayList params); Resource invokeMethod(String methodName, Object [] params, String returnResourceName); Resource invokeMethod(
          String methodName, ArrayList params, String returnResourceName); Object invokeMethod(
          String methodName, String[] paramTypes, Object[] params); Object invokeMethod(
          String methodName, ArrayList<String> paramTypes, ArrayList params); Resource invokeMethod(
          String methodName, String[] paramTypes, Object[] params, String returnResourceName); Resource invokeMethod(
          String methodName, ArrayList<String> paramTypes, ArrayList params, String returnResourceName); Object invokeMethod(
          String methodName, Type[] types, Object[] params); Object invokeMethod(
          String methodName, Type[] types, Object[] params, String returnResourceName); Object invokeMethod(
      String methodName, Class[] paramTypes, Object[] params); Resource invokeMethod(
      String methodName, Class[] paramTypes, Object[] params, String returnResourceName); static ByteBuffer serializeObject(Object o); static Object deserializeObject(ByteBuffer buf); String toJson(); static Resource fromJson(String json);  }
@Test public void testInvokeMethod_shouldAbleToInvokeMethodWithNoParams() { Resource r = new Resource(null, new ResourceId("pool1", "name1"), "object"); assertEquals(6, r.invokeMethod("length")); assertEquals(6, r.invokeMethod("length", new Class[]{}, new Object[]{})); }
@Test public void testInvokeMethod_shouldAbleToInvokeMethodWithTypeInference() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Resource r = new Resource(null, new ResourceId("pool1", "name1"), "object"); assertEquals("ect", r.invokeMethod("substring", new Object[]{3})); assertEquals("obj", r.invokeMethod("substring", new Object[]{0,3})); assertEquals(true, r.invokeMethod("startsWith", new Object[]{"obj"})); assertEquals(2, r.invokeMethod("indexOf", new Object[]{'j'})); assertEquals(4, r.invokeMethod("indexOf", new Object[]{"ct",3})); assertEquals("ect", r.invokeMethod("substring", new ArrayList<>(Arrays.asList(3)))); assertEquals("ec", r.invokeMethod("substring", new ArrayList<>(Arrays.asList(3,5)))); assertEquals(true, r.invokeMethod("startsWith", new ArrayList<>(Arrays.asList("obj")))); }
@Test(expected = ClassNotFoundException.class) public void testInvokeMethod_shouldNotAbleToInvokeMethodWithTypeInference() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Resource r = new Resource(null, new ResourceId("pool1", "name1"), "object"); r.invokeMethod("indexOf", new Object[]{"ct",3,4}); }
@Test public void testInvokeMethod_shouldAbleToInvokeMethodWithParamClassName() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Resource r = new Resource(null, new ResourceId("pool1", "name1"), "object"); assertEquals("ect", r.invokeMethod("substring", new String[]{"int"}, new Object[]{3})); assertEquals(true, r.invokeMethod("startsWith", new String[]{"java.lang.String"}, new Object[]{"obj"})); assertEquals("ect", r.invokeMethod("substring", new ArrayList<>(Arrays.asList("int")), new ArrayList<>(Arrays.asList(3)))); assertEquals(true, r.invokeMethod("startsWith", new ArrayList<>(Arrays.asList("java.lang.String")), new ArrayList<>(Arrays.asList("obj")))); }
@Test public void testInvokeMethod_shouldAbleToInvokeMethodWithClass() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Resource r = new Resource(null, new ResourceId("pool1", "name1"), "object"); assertEquals(true, r.invokeMethod("startsWith", new Class[]{ java.lang.String.class }, new Object[]{"obj"})); }