Package org.springsource.loaded.test.infra

Examples of org.springsource.loaded.test.infra.Result


   * <p>
   * What if the super method is deleted in v002?
   */
  @Test
  public void test_callInheritedOverridenDeletedMethod() throws Exception {
    Result r = getDeclaredMethod("overrideMethodDeleted");
    assertMethod("public java.lang.String " + TARGET_CLASS_NAME + ".overrideMethodDeleted()", r);
    Method m = (Method) r.returnValue;

    // Setup subClass and an instance of the subclass
    String subClassName = TARGET_PACKAGE + ".SubClassTarget";
View Full Code Here


  /**
   * Test invoking a static method.
   */
  @Test
  public void test_invokeStaticMethod() throws Exception {
    Result r = getDeclaredMethod("staticMethod");
    assertMethod("public static java.lang.String " + TARGET_CLASS_NAME + ".staticMethod()", r);
    Method m = (Method) r.returnValue;

    // Calling the static method
    r = invokeOn(null, m); //pass in null, it shouldn't need an instance since it's static!
View Full Code Here

   */
  @Test
  public void test_invokeStaticMethodAdded() throws Exception {
    String methodName = "staticMethodAdded";
    try {
      Result r = getDeclaredMethod(methodName);
      fail("Method shouldn't exist at first!\n" + r.toString());
    } catch (ResultException e) {
      assertNoSuchMethodException(TARGET_CLASS_NAME + "." + methodName + "()", e);
    }

    reloadType("002");

    Result r = getDeclaredMethod(methodName);
    assertMethod("public static int " + TARGET_CLASS_NAME + "." + methodName + "()", r);
    Method m = (Method) r.returnValue;

    // Calling the static method
    r = invokeOn(null, m); //pass in null, it shouldn't need an instance since it's static!
View Full Code Here

   */
  @Test
  public void test_invokeStaticMethodAddedWithNullParams() throws Exception {
    String methodName = "staticMethodAdded";
    try {
      Result r = getDeclaredMethod(methodName);
      fail("Method shouldn't exist at first!\n" + r.toString());
    } catch (ResultException e) {
      assertNoSuchMethodException(TARGET_CLASS_NAME + "." + methodName + "()", e);
    }

    reloadType("002");

    Result r = getDeclaredMethod(methodName);
    assertMethod("public static int " + TARGET_CLASS_NAME + "." + methodName + "()", r);
    Method m = (Method) r.returnValue;

    Object[] params = null; // This should be ok, since the method expects no params (should not cause an NPE)

View Full Code Here

   */
  @Test
  public void test_invokeStaticMethodAddedWithArgs() throws Exception {
    String methodName = "staticMethodAddedWithArgs";
    try {
      Result r = getDeclaredMethod(methodName, int.class, String.class);
      fail("Method should not exist initially\n" + r.toString());
    } catch (ResultException e) {
      assertNoSuchMethodException(TARGET_CLASS_NAME + "." + methodName + "(int, java.lang.String)", e);
    }

    reloadType("002");

    Result r = getDeclaredMethod(methodName, int.class, String.class);
    assertMethod("public static java.lang.String " + TARGET_CLASS_NAME + "." + methodName + "(int,java.lang.String)", r);
    Method m = (Method) r.returnValue;

    // Calling the static method
    r = invokeOn(null, m, 123, "Hello"); //pass in null, it shouldn't need an instance since it's static!
View Full Code Here

   */
  @Test
  public void test_invokeStaticMethodOverriden() throws Exception {
    String methodName = "staticMethodAdded";
    try {
      Result r = getDeclaredMethod(methodName);
      fail("Method shouldn't exist at first!\n" + r.toString());
    } catch (ResultException e) {
      assertNoSuchMethodException(TARGET_CLASS_NAME + "." + methodName + "()", e);
    }

    reloadType("002");

    // Setup subClass and an instance of the subclass
    String subClassName = TARGET_PACKAGE + ".SubClassTarget";
    ReloadableType subTarget = registry.addType(subClassName, loadBytesForClass(subClassName));
    Object subInstance = subTarget.getClazz().newInstance();

    //Double check, the subclass 'overrides' the static method
    assertMethod("public static int " + subClassName + "." + methodName + "()",
        getDeclaredMethod(subTarget.getClazz(), methodName));

    Result r = getDeclaredMethod(methodName);
    assertMethod("public static int " + TARGET_CLASS_NAME + "." + methodName + "()", r);
    Method m = (Method) r.returnValue;

    // Calling the static method seemingly on a 'subinstance' the instance should be ignored!
    r = invokeOn(subTarget, m);
View Full Code Here

   * We should be able to invoke methods inherited from non-reloadable types on instances of reloadable types.
   */
  @Test
  public void test_callInheritedNonReloadableMethod() throws Exception {
    //We need a method that is inherited from a non-reloadable type for this scenario
    Result r = getDeclaredMethod(Object.class, "toString");
    assertMethod("public java.lang.String java.lang.Object.toString()", r);
    Method m = (Method) r.returnValue;

    // Setup subClass and an instance of the subclass
    String subClassName = TARGET_PACKAGE + ".SubClassTarget";
View Full Code Here

    // These types relate to one another as follows:

    //1) the method 'm' must be declared in the reloadable interface
    String interfaceMethodName = "interfaceMethod";
    Result r = getDeclaredMethod(interfaceTarget.getClazz(), interfaceMethodName);
    assertMethod("public abstract java.lang.String " + interfaceName + "." + interfaceMethodName + "()", r);
    Method m = (Method) r.returnValue;

    //2) The reloadable type implements this interface (without providing its own implementation of m)
    assertTrue(interfaceTarget.getClazz().isAssignableFrom(subClass.getClazz()));
View Full Code Here

    Assert.assertEquals(expectedSignature, f.toString());
  }

  @Test
  public void test_getDeclaredField() throws Exception {
    Result r = getDeclaredField("myField");
    assertField("public int " + TARGET_CLASS_NAME + ".myField", r);

    reloadType("002");

    r = getDeclaredField("myField");
View Full Code Here

  /**
   * Does getDeclaredMethod/invoke work as expected on non-reloadable types?
   */
  @Test
  public void test_getDeclaredMethodNonReloadable() throws Exception {
    Result r = getDeclaredMethod(String.class, "indexOf", String.class, int.class);
    assertMethod("public int java.lang.String.indexOf(java.lang.String,int)", r);
    r = invokeOn("Some text", (Method) r.returnValue, "ex", 0);
    Assert.assertEquals("Some text".indexOf("ex"), r.returnValue);
  }
View Full Code Here

TOP

Related Classes of org.springsource.loaded.test.infra.Result

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.