Test Harness driven by scripts


EJB design: Test Harness driven by scripts

  1. Test Harness driven by scripts (1 messages)

    This is marginally off-topic, apologies.

    We are trying to write a test harness to exercise EJBs, driven by test scripts, which determine amongst other things which EJB to call, the method to call etc.

    Typical client code is:

    Object o = context.lookup("someJNDIname");
    XxxHome xxxHome = (XxxHome) PortableRemoteObject.narrow(o,
    Xxx xxx = xxxHome.create();

    Our problem is that we don't know what Xxx represents till runtime, so there is potentially lots of complex reflection type code. Being lazy, I wondered if anyone could point me at some documentation of how this might be done.
  2. Test Harness driven by scripts[ Go to top ]

    OK, the penalty for being lazy is having to write up the answer when it is found. The following seems to work:

    Object o = _context.lookup(jndiName);
    Object o2 = PortableRemoteObject.narrow(o,
    Method m = o2.getClass().getMethod("create",new Class[0]);
    Object o3 = method.invoke(o2,new Object[0]);
    Object[] paramArray = new Object[1];
    paramArray[0] = new String(scriptInput);
    Class[] classArray = new Class[1];
    classArray[0] = String.class;
    method = o3.getClass().getMethod(targetMethod,classArray);
    String returnString = (String) method.invoke(o3,paramArray);

    where jndiName,targetBean,scriptInput and targetMethod are derived from our script and our target methods always expect to receive and return Strings (if you had to determine the paarmeter and return types you'd probably need to examine the list of methods).