Esempio n. 1
0
  public void test52_returnNestedHandle() {
    try {
      final Object obj = initialContext.lookup("client/tests/entity/bmp/EncBean");
      final EncBmpHome home =
          (EncBmpHome) javax.rmi.PortableRemoteObject.narrow(obj, EncBmpHome.class);
      assertNotNull("The EJBHome returned from JNDI is null", home);

      final EncBmpObject object = home.create("test_52 BmpBean");
      assertNotNull("The EJBObject created is null", object);

      final Handle expected = object.getHandle();
      assertNotNull("The EJBObject Handle returned is null", expected);
      assertNotNull("The EJBObject in the Handle is null", expected.getEJBObject());

      final ObjectGraph graph = ejbObject.returnObjectGraph(new ObjectGraph(expected));
      assertNotNull("The ObjectGraph is null", graph);

      final Handle actual = (Handle) graph.getObject();
      assertNotNull("The EJBObject Handle returned is null", actual);
      assertNotNull("The EJBObject in the Handle is null", actual.getEJBObject());

      final EJBObject exp = expected.getEJBObject();
      final EJBObject act = actual.getEJBObject();

      assertTrue("The EJBObjects in the Handles are not identical", exp.isIdentical(act));

    } catch (final Exception e) {
      fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
  }
Esempio n. 2
0
  public void test51_returnHandle() {
    try {
      final Handle actual = ejbObject.returnHandle();
      assertNotNull("The EJBObject Handle returned is null", actual);
      assertNotNull("The EJBObject in the Handle is null", actual.getEJBObject());

    } catch (final Exception e) {
      fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
  }
Esempio n. 3
0
  public void test53_returnNestedHandle2() {
    try {
      final ObjectGraph graph = ejbObject.returnNestedHandle();
      assertNotNull("The ObjectGraph is null", graph);

      final Handle actual = (Handle) graph.getObject();
      assertNotNull("The EJBObject Handle returned is null", actual);
      assertNotNull("The EJBObject in the Handle is null", actual.getEJBObject());
    } catch (final Exception e) {
      fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
  }
  /** all processing methods end up here */
  private void startHereCommon() throws BeanException {
    // try to get the linkKey if already set in input properties
    try {
      hPubLinkKey = inputProps.getHPubLinkKey();
    } catch (Exception e) {
    }

    // if running in Web environment and either the ejb access handle or
    // the linkKey are null, try to get them from the HttpSession
    if (oHttpServletRequest != null) {
      HttpSession theWebsession = oHttpServletRequest.getSession(false);
      if (theWebsession != null) {
        synchronized (theWebsession) {
          try {
            if (tracing == true) {
              traceArgs[0] = this;
              traceArgs[1] = "HttpSession.getId()=" + theWebsession.getId();
              try {
                traceMethod.invoke(o, traceArgs);
              } catch (Exception x) {
              }
            }
            String theKey = KEY_WEBCONN + inputProps.getHPubStartChainName();
            // if linkKey or access handle is null try to get it from Websession
            HPubEJB2HttpSessionBindingListener sbl =
                (HPubEJB2HttpSessionBindingListener) theWebsession.getAttribute(theKey);
            if ((hPubLinkKey == null) && (sbl != null)) {
              hPubLinkKey = sbl.getLinkKey();
              if (tracing == true) {
                traceArgs[0] = this;
                traceArgs[1] = "HttpSession.getAttribute(hPubLinkKey)=" + hPubLinkKey;
                try {
                  traceMethod.invoke(o, traceArgs);
                } catch (Exception x) {
                }
              }
              inputProps.setHPubLinkKey(hPubLinkKey);
            }
            if ((hPubAccessHandle == null) && (sbl != null)) {
              hPubAccessHandle = sbl.getEjbHandle();
              if (tracing == true) {
                traceArgs[0] = this;
                traceArgs[1] = "HttpSession.getAttribute(hPubAccessHandle)=" + hPubAccessHandle;
                try {
                  traceMethod.invoke(o, traceArgs);
                } catch (Exception x) {
                }
              }
            }
            // set the ejb handle to null before removing the Session Binding
            // Listener object
            if (auditing == true) {
              if (sbl != null)
                auditArgs[0] =
                    "\n---\nOUT:"
                        + this.getClass().getName()
                        + " "
                        + theKey
                        + " "
                        + hPubAccessHandle
                        + " "
                        + hPubLinkKey
                        + " "
                        + theWebsession.getId();
              else // error - object not found in HttpSession
              auditArgs[0] =
                    "\n---\nERR:"
                        + this.getClass().getName()
                        + " "
                        + theKey
                        + " "
                        + theWebsession.getId();

              auditArgs[1] = theWebsession;
              try {
                auditMethod.invoke(o, auditArgs);
              } catch (Exception x) {
              }
            }
            if (sbl != null) sbl.setEjbHandle(null);
            theWebsession.removeAttribute(theKey);
          } catch (IllegalStateException e) {
          }
        }
      }
    }
    // if either of required properties are still null then the ejb cannot
    // be accessed - throw an exception.
    if ((hPubAccessHandle == null) || (hPubLinkKey == null)) {
      String errMsg =
          (new Date(System.currentTimeMillis())).toString()
              + " HPS5951 "
              + this.getClass().getName()
              + ": hPubAccessHandle==null || hPubLinkKey==null";
      System.err.println(errMsg);
      if (tracing == true) {
        traceArgs[0] = this;
        traceArgs[1] = errMsg;
        try {
          traceMethod.invoke(o, traceArgs);
        } catch (Exception x) {
        }
      }
      throw new BeanException(errMsg);
    } else {
      if (tracing == true) {
        traceArgs[0] = this;
        traceArgs[1] = "hPubAccessHandle=" + hPubAccessHandle + ",hPubLinkKey=" + hPubLinkKey;
        try {
          traceMethod.invoke(o, traceArgs);
        } catch (Exception x) {
        }
      }
    }

    // get the EJB object from the handle
    try {
      ejb =
          (com.ibm.HostPublisher.EJB.HPubEJB2)
              javax.rmi.PortableRemoteObject.narrow(
                  hPubAccessHandle.getEJBObject(), com.ibm.HostPublisher.EJB.HPubEJB2.class);
    } catch (Exception e) {
      String errMsg =
          (new Date(System.currentTimeMillis())).toString()
              + " HPS5952 "
              + this.getClass().getName()
              + ": getEJBObject(): "
              + e.getClass().getName()
              + ": "
              + e.getMessage();
      System.err.println(errMsg);
      if (tracing == true) {
        traceArgs[0] = this;
        traceArgs[1] = errMsg;
        try {
          traceMethod.invoke(o, traceArgs);
        } catch (Exception x) {
        }
      }
      throw new BeanException(errMsg);
    }
    // if ejb handle, go invoke the HPubEJB's main business method.
    if (ejb != null) {
      try {
        outputProps = (CrownCounselIndexGetList_Properties) ejb.processIO(inputProps);
        inputProps = outputProps;
        inputProps.setInitialCall(false);
      } catch (Exception e) {
        String errMsg =
            (new Date(System.currentTimeMillis())).toString()
                + " HPS5953 "
                + this.getClass().getName()
                + ": processIO("
                + inputProps.getClass().getName()
                + "): "
                + e.getClass().getName()
                + ": "
                + e.getMessage();
        System.err.println(errMsg);
        if (tracing == true) {
          traceArgs[0] = this;
          traceArgs[1] = errMsg;
          try {
            traceMethod.invoke(o, traceArgs);
          } catch (Exception x) {
          }
        }
        throw new BeanException(errMsg);
      }
    }
    endHereCommon();
    return;
  }
  public void testAllTypesBean() throws Exception {

    try {
      Context ctx = new InitialContext();

      getLog().debug("");
      getLog().debug("");
      getLog().debug("Test AllTypesBean");
      getLog().debug("=================");
      getLog().debug("");
      getLog().debug(++test + "- " + "Looking up the home AllTypes...");
      AllTypesHome allTypesHome = (AllTypesHome) ctx.lookup("AllTypes");
      if (allTypesHome != null) getLog().debug("ok");

      getLog().debug(++test + "- " + "Getting the home handle...");
      HomeHandle homeHandle = allTypesHome.getHomeHandle();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Getting the home back from the handle...");
      EJBHome aHome = homeHandle.getEJBHome();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Getting metadata from home...");
      EJBMetaData aMetaData = aHome.getEJBMetaData();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Getting home from metadata...");
      aHome = aMetaData.getEJBHome();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Calling findByPrimaryKey on AllTypesHome with name seb...");

      AllTypes allTypes = null;
      try {
        allTypes = allTypesHome.findByPrimaryKey("seb");
      } catch (Exception e) {
        getLog().debug(e.getMessage());
      }
      if (allTypes == null) {

        getLog().debug("not found OK");
        getLog().debug(++test + "- " + "Calling create on AllTypesHome with name seb...");
        allTypes = allTypesHome.create("seb");
      }

      if (allTypes != null) getLog().debug("ok");

      getLog()
          .debug(
              ++test
                  + "- "
                  + "Calling business method A an AllTypes (B2B with external ejb-ref)...");
      getLog().debug("OK, result is" + allTypes.callBusinessMethodA());

      getLog().debug("Getting all the fields");
      getLog().debug(++test + "- " + "boolean " + allTypes.getBoolean() + " Ok");
      getLog().debug(++test + "- " + "byte " + allTypes.getByte() + " Ok");
      getLog().debug(++test + "- " + "short " + allTypes.getShort() + " Ok");
      getLog().debug(++test + "- " + "int " + allTypes.getInt() + " Ok");
      getLog().debug(++test + "- " + "long " + allTypes.getLong() + " Ok");
      getLog().debug(++test + "- " + "float " + allTypes.getFloat() + " Ok");
      getLog().debug(++test + "- " + "double " + allTypes.getDouble() + " Ok");
      getLog().debug("No char test yet, bug in jdk");
      getLog().debug(++test + "- " + "String " + allTypes.getString() + " Ok");
      getLog().debug(++test + "- " + "Date " + allTypes.getDate() + " Ok");
      getLog().debug(++test + "- " + "Timestamp " + allTypes.getTimestamp() + " Ok");

      getLog().debug(++test + "- " + "MyObject ");
      MyObject obj = allTypes.getObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting handle of stateful...");
      Handle sfHandle = allTypes.getStateful();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting the bean back from the handle...");
      StatefulSession sfBean = (StatefulSession) sfHandle.getEJBObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "comparing serialized handles...");
      assertTrue(
          Arrays.equals(
              new MarshalledValue(sfHandle).toByteArray(),
              new MarshalledValue(sfBean.getHandle()).toByteArray()));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "calling business method A on stateful: ");
      getLog().debug("OK, result is " + sfBean.callBusinessMethodA());

      getLog().debug(++test + "- " + "adding the stateful bean as an object in AllTypes..");
      allTypes.addObjectToList(sfBean);
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting handle of stateless...");
      Handle slHandle = allTypes.getStateless();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting the bean back from the handle...");
      StatelessSession slBean = (StatelessSession) slHandle.getEJBObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "comparing serialized handles...");
      assertTrue(
          Arrays.equals(
              new MarshalledValue(slHandle).toByteArray(),
              new MarshalledValue(slBean.getHandle()).toByteArray()));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "calling business method B on stateless: ");
      getLog().debug("OK, result is " + slBean.callBusinessMethodB());

      getLog().debug(++test + "- " + "adding the stateless bean as an object in AllTypes..");
      allTypes.addObjectToList(slBean);
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting handle of entity...");
      Handle eeHandle = allTypes.getEntity();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting the bean back from the handle...");
      EnterpriseEntity eeBean = (EnterpriseEntity) eeHandle.getEJBObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "comparing serialized handles...");
      assertTrue(
          Arrays.equals(
              new MarshalledValue(eeHandle).toByteArray(),
              new MarshalledValue(eeBean.getHandle()).toByteArray()));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "calling business method A on stateless: ");
      getLog().debug("OK, result is" + eeBean.callBusinessMethodA());

      getLog().debug(++test + "- " + "adding the entity bean as an object in AllTypes..");
      allTypes.addObjectToList(eeBean);
      getLog().debug("OK");

      getLog()
          .debug(
              ++test + "- " + "Getting the list of objects back (should contain the 3 beans)...");
      Collection coll = allTypes.getObjectList();
      assertEquals(coll.size(), 3);
      getLog().debug("OK");
      getLog().debug(++test + "- " + "stateful bean ");
      assertTrue(coll.contains(sfBean));
      getLog().debug("OK");
      getLog().debug(++test + "- " + "stateless bean ");
      assertTrue(coll.contains(slBean));
      getLog().debug("OK");
      getLog().debug(++test + "- " + "entity bean ");
      assertTrue(coll.contains(eeBean));
      getLog().debug("OK");

      getLog().debug("Testing automatically generated finders");

      getLog().debug(++test + "- " + "findAll()..");
      coll = allTypesHome.findAll();
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByPrimaryKey()...");
      AllTypes result = allTypesHome.findByPrimaryKey("seb");
      assertTrue(result.equals(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByABoolean()..");
      coll = allTypesHome.findByABoolean(allTypes.getBoolean());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAByte()..");
      coll = allTypesHome.findByAByte(allTypes.getByte());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAShort()..");
      coll = allTypesHome.findByAShort(allTypes.getShort());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAnInt()..");
      coll = allTypesHome.findByAnInt(allTypes.getInt());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByALong()..");
      coll = allTypesHome.findByALong(allTypes.getLong());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAFloat()..");
      coll = allTypesHome.findByAFloat(allTypes.getFloat());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByADouble()..");
      coll = allTypesHome.findByADouble(allTypes.getDouble());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug("No Char test yet, bug in jdk");

      getLog().debug(++test + "- " + "findByAString()..");
      coll = allTypesHome.findByAString(allTypes.getString());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByADate()..");
      coll = allTypesHome.findByADate(allTypes.getDate());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByATimestamp()..");
      coll = allTypesHome.findByATimestamp(allTypes.getTimestamp());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAnObject()..");
      coll = allTypesHome.findByAnObject(allTypes.getObject());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByStatefulSession()..");
      coll =
          allTypesHome.findByStatefulSession(
              (StatefulSession) allTypes.getStateful().getEJBObject());
      getLog().debug("size=" + coll.size());
      for (Iterator i = coll.iterator(); i.hasNext(); ) {
        Object o = i.next();
        getLog().debug("o=" + o);
      }
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByStatelessSession()..");
      coll =
          allTypesHome.findByStatelessSession(
              (StatelessSession) allTypes.getStateless().getEJBObject());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByEnterpriseEntity()..");
      coll =
          allTypesHome.findByEnterpriseEntity(
              (EnterpriseEntity) allTypes.getEntity().getEJBObject());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug("Testing finders defined in jaws.xml");

      getLog().debug(++test + "- " + "findByMinInt()..");
      coll = allTypesHome.findByMinInt(0);
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByIntAndDouble()..");
      coll = allTypesHome.findByIntAndDouble(allTypes.getInt(), allTypes.getDouble());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

    } catch (Exception e) {
      getLog().debug("Exception: ", e);
      throw e;
    }
  }
  public void testEntityBeanCMP() throws Exception {
    Context ctx = new InitialContext();

    getLog().debug("testEntityBeanCMP");
    getLog().debug(++test + "- " + "Looking up the home nextgen.EnterpriseEntity...ok");

    EnterpriseEntityHome enterpriseEntityHome =
        (EnterpriseEntityHome) ctx.lookup("nextgen.EnterpriseEntity");
    getLog().debug(++test + "- " + "Calling find on EnterpriseEntityHome with name Marc...");
    EnterpriseEntity enterpriseEntity = null;
    try {
      enterpriseEntity = enterpriseEntityHome.findByPrimaryKey("Marc");
    } catch (Exception e) {
      getLog().debug("findByPrimaryKey(Marc) failed", e);
    }
    if (enterpriseEntity == null) {
      getLog().debug("not found OK");
      getLog().debug(++test + "- " + "Calling create on EnterpriseEntityHome with name Marc...");
      enterpriseEntity = enterpriseEntityHome.create("Marc");
    }

    if (enterpriseEntity != null)
      getLog()
          .debug(
              "ok, enterpriseEntity"
                  + enterpriseEntity
                  + ", hashCode="
                  + enterpriseEntity.hashCode());

    getLog().debug(++test + "- " + "Calling for duplicate create and DuplicateKeyException...");
    try {
      Object e = enterpriseEntityHome.create("Marc");
      getLog().debug("I Really should not make it here, e=" + e + ", hashCode=" + e.hashCode());
      throw new Exception("DuplicateKey not seen");
    } catch (DuplicateKeyException dke) {
      getLog().debug("DuplicateKeyException ok");
    }

    getLog().debug(++test + "- " + "Calling getEJBHome() on EntityCMP...");
    assertTrue("enterpriseEntity.getEJBHome() != null", enterpriseEntity.getEJBHome() != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Getting a new reference with findByPK...");
    EnterpriseEntity enterpriseEntity2 = null;
    try {
      enterpriseEntity2 = enterpriseEntityHome.findByPrimaryKey("Marc");
    } catch (Exception re) {
      getLog().debug("Exception: ", re);
    }
    assertTrue("enterpriseEntity2 != null", enterpriseEntity2 != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling Business Method A on enterpriseEntity... ");
    getLog().debug(enterpriseEntity.callBusinessMethodA());

    getLog()
        .debug(
            ++test
                + "- "
                + "Calling Business Method A (again to ejbLoad if TypeC) on enterpriseEntity... ");
    getLog().debug(enterpriseEntity.callBusinessMethodA());

    getLog()
        .debug(
            ++test
                + "- "
                + "Calling Business Method B (EJBObject from entity) on enterpriseEntity...");
    getLog().debug(enterpriseEntity.callBusinessMethodB());

    getLog().debug(++test + "- " + "Calling Business Method B(String) on EnterpriseEntity... ");
    getLog().debug(enterpriseEntity.callBusinessMethodB("of wisdom"));

    getLog().debug(++test + "- " + "Calling getOtherField (non pk) on enterpriseEntity...");
    getLog().debug("value: " + enterpriseEntity.getOtherField());

    getLog().debug(++test + "- " + "Calling setOtherField(4) on enterpriseEntity...");
    enterpriseEntity.setOtherField(4);
    getLog().debug("OK");

    getLog().debug(++test + "- " + "Calling getOtherField() on enterpriseEntity (should be 4)...");
    int value = enterpriseEntity.getOtherField();
    assertTrue("enterpriseEntity.getOtherField() == 4", value == 4);
    getLog().debug("value is " + value + ", OK");

    getLog().debug("***Testing the various local Object class calls");
    getLog().debug(++test + "- " + "toString ... " + enterpriseEntity);

    getLog().debug(++test + "- " + "hashCode ... " + enterpriseEntity.hashCode());

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (same object) ... "
                + enterpriseEntity.equals(enterpriseEntity));

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (another object) (true for this case)... "
                + enterpriseEntity.equals(enterpriseEntity2));

    getLog().debug("***Testing the various local EJBObject class calls");
    getLog().debug(++test + "- " + "Get Primary Key ... " + enterpriseEntity.getPrimaryKey());

    getLog().debug(++test + "- " + "Get Handle ... ");
    Handle entityHandle = enterpriseEntity.getHandle();
    assertTrue("entityHandle != null", entityHandle != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Serialize handle and deserialize....");
    MarshalledObject mo3 = new MarshalledObject(entityHandle);
    Handle entityHandle3 = (Handle) mo3.get();
    EnterpriseEntity enterpriseEntity3 = (EnterpriseEntity) entityHandle3.getEJBObject();
    if (enterpriseEntity3 != null) getLog().debug("OK");
    getLog().debug(++test + "- " + "Calling businessMethodA on it...");
    getLog().debug(enterpriseEntity3.callBusinessMethodB());
    getLog()
        .debug(
            ++test
                + "- "
                + "They should be identical..."
                + enterpriseEntity.isIdentical(enterpriseEntity3));
    getLog().debug(++test + "- " + "Calling entityHome.remove(Handle)...");
    enterpriseEntityHome.remove(enterpriseEntity3.getHandle());
    getLog().debug("OK");

    getLog().debug(++test + "- " + "Calling enterpriseEntity.remove() (should fail)...");
    try {
      enterpriseEntity.remove();
      fail("enterpriseEntity.remove() did not fail");
    } catch (Exception e) {
      getLog().debug("OK");
    }

    getLog().debug(++test + "- " + "Calling EnterpriseEntity.create() for marc6...");
    EnterpriseEntity marc6 = enterpriseEntityHome.create("marc6");
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling method createEntity on enterpriseEntity... ");
    EnterpriseEntity marc2 = marc6.createEntity("marc2");
    getLog().debug("OK");

    getLog().debug(++test + "- " + "removing by PK on home (marc2)...");
    enterpriseEntityHome.remove(marc2.getPrimaryKey());
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling enterpriseEntity.remove()  (marc6)...");
    marc6.remove();
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling EnterpriseEntity.create<METHOD>() for marc7...");
    EnterpriseEntity marc7 = enterpriseEntityHome.createMETHOD("marc7");
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling enterpriseEntity.remove()  (marc7)...");
    marc7.remove();
    getLog().debug("ok");

    getLog().debug("");
    getLog().debug("");
    getLog().debug("");
  }
  public void testStatefulBean() throws Exception {
    Context ctx = new InitialContext();

    getLog().debug("");
    getLog().debug("Test Stateful Bean");
    getLog().debug("==================");
    getLog().debug("");
    getLog().debug(++test + "- " + "Looking up the home nextgen.StatefulSession...");
    StatefulSessionHome statefulSessionHome =
        (StatefulSessionHome) ctx.lookup("nextgen.StatefulSession");
    assertTrue("statefulSessionHome!= null", statefulSessionHome != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling create on StatefulSessionHome with name Marc...");
    StatefulSession statefulSession = statefulSessionHome.create("Marc");
    assertTrue("statefulSession != null", statefulSession != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling getEJBHome() on StatefulSession...");
    assertTrue("statefulSession.getEJBHome() != null", statefulSession.getEJBHome() != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling Business Method A on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling Business Method A (state) on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling Business Method B (EJBObject) on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodB());

    getLog().debug(++test + "- " + "Calling Business Method B(String) on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodB("of wisdom"));

    getLog().debug("***Testing the various local Object class calls");
    getLog().debug(++test + "- " + "toString ... ");
    getLog().debug(statefulSession.toString());
    getLog().debug(++test + "- " + "hashCode ... " + statefulSession.hashCode());

    getLog()
        .debug(
            ++test + "- " + "equals (same object) ... " + statefulSession.equals(statefulSession));

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (another object) (false under same home)... "
                + statefulSession.equals(statefulSessionHome.create("marc4")));

    getLog().debug("***Testing the various local EJBObject class calls");

    getLog().debug(++test + "- " + "Get Handle ... ");
    Handle statefulHandle = statefulSession.getHandle();
    assertTrue("statefulHandle != null", statefulHandle != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Serialize handle and deserialize....");
    MarshalledObject mo2 = new MarshalledObject(statefulHandle);
    Handle statefulHandle2 = (Handle) mo2.get();
    StatefulSession statefulSession2 = (StatefulSession) statefulHandle2.getEJBObject();
    assertTrue("statefulSession2 != null", statefulSession2 != null);
    getLog().debug("OK");
    getLog()
        .debug(
            ++test
                + "- "
                + "Calling businessMethodB on it..."
                + statefulSession2.callBusinessMethodB());

    getLog()
        .debug(
            ++test
                + "- "
                + "They should be identical..."
                + statefulSession.isIdentical(statefulSession2));

    getLog().debug(++test + "- " + "Calling StatefulSession.remove()...");
    statefulSession.remove();
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling StatefulHome.remove(Handle) (this should fail)...");
    try {
      statefulSessionHome.remove(statefulSession2.getHandle());
      fail("statefulSessionHome.remove did not fail");
    } catch (Exception e) {
      getLog().debug("not found OK");
    }
    getLog().debug(++test + "- " + "Creating a 3rd bean and calling it...");
    StatefulSession ss3 = statefulSessionHome.create("marc3");
    getLog().debug(ss3.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling StatefulSession.remove(Handle) on a third bean...");
    Handle statefulHandle3 = ss3.getHandle();
    statefulSessionHome.remove(statefulHandle3);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "I should not be able to remove it directly...");
    try {
      ss3.remove();
      fail("ss3.remove() did not fail");
    } catch (Exception e) {
      getLog().debug("OK");
    }

    getLog().debug(++test + "- " + "Creating a 4th bean using create<METHOD> and calling it...");
    StatefulSession ss4 = statefulSessionHome.createMETHOD("marc4", "address");
    getLog().debug(ss4.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling StatefulSession.remove(Handle) on a fourth bean...");
    Handle statefulHandle4 = ss4.getHandle();
    statefulSessionHome.remove(statefulHandle4);
  }
  public void testStatelessBean() throws Exception {

    getLog().debug(++test + "- " + "Trying the context...");

    Context ctx = new InitialContext();
    getLog().debug("OK");

    /// *
    getLog().debug("");
    getLog().debug("Test Stateless Bean");
    getLog().debug("===================");
    getLog().debug("");
    getLog().debug(++test + "- " + "Looking up the home nextgen.StatelessSession...");
    StatelessSessionHome statelessSessionHome =
        (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession");
    if (statelessSessionHome != null) getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling create on StatelessSessionHome...");
    StatelessSession statelessSession = statelessSessionHome.create();
    assertTrue("statelessSessionHome.create() != null", statelessSession != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling getEJBHome() on StatelessSession...");
    assertTrue("statelessSession.getEJBHome() != null", statelessSession.getEJBHome() != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling Business Method A on StatelessSession... ");
    statelessSession.callBusinessMethodA();
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling Business Method B on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodB());
    getLog().debug(++test + "- " + "Calling Business Method B(String) on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodB("of wisdom"));
    getLog().debug(++test + "- " + "Calling Business Method C on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodC());
    getLog().debug(++test + "- " + "Calling Business Method D on StatelessSession... ");
    try {
      statelessSession.callBusinessMethodD();
      fail("callBusinessMethodD, no exception was thrown");
    } catch (BusinessMethodException e) {
      getLog().debug("Caught BusinessMethodException OK");
    }
    getLog()
        .debug(++test + "- " + "Calling Business Method E (getEJBObject) on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodE());

    getLog().debug(++test + "- " + "Calling testClassLoading on StatelessSession... ");
    statelessSession.testClassLoading();
    getLog().debug("OK");

    getLog().debug("***Testing the various local Object class calls");
    getLog().debug(++test + "- " + "toString ... " + statelessSession.toString());

    getLog().debug(++test + "- " + "hashCode ... " + statelessSession.hashCode());

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (same object) ... "
                + statelessSession.equals(statelessSession));

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (another object) (true under same home)... "
                + statelessSession.equals(statelessSessionHome.create()));

    getLog().debug("***Testing the various local EJBObject class calls");

    getLog().debug(++test + "- " + "Get Handle ... ");
    Handle statelessHandle = statelessSession.getHandle();
    assertTrue("statelessHandle != null", statelessHandle != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Serialize handle and deserialize..");
    MarshalledObject mo = new MarshalledObject(statelessHandle);
    Handle handle2 = (Handle) mo.get();
    StatelessSession statelessSession2 = (StatelessSession) handle2.getEJBObject();
    assertTrue("statelessSession2 != null", statelessSession2 != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Calling businessMethodB on it...");
    getLog().debug(statelessSession2.callBusinessMethodB());
    getLog()
        .debug(
            ++test
                + "- "
                + "They should be identical..."
                + statelessSession.isIdentical(statelessSession2));
    getLog().debug("***Testing the various local EJBHome class calls");
    getLog().debug(++test + "- " + "Getting the metaData...");
    EJBMetaData statelessMetaData = statelessSessionHome.getEJBMetaData();
    assertTrue("statelessMetaData != null", statelessMetaData != null);
    getLog().debug("OK");
    getLog()
        .debug(++test + "- " + "Is stateless Session? " + statelessMetaData.isStatelessSession());
    getLog()
        .debug(
            ++test + "- " + "The remote class is " + statelessMetaData.getRemoteInterfaceClass());

    getLog().debug("");
    getLog().debug(++test + "- " + "Calling StatelessSession.remove()...");
    statelessSession.remove();
    getLog().debug("ok");
  }
Esempio n. 9
0
  public void doTest() {

    try {

      File handleFile = new File(HANDLE_FILE_NAME);

      if (handleFile.exists()) {

        System.out.println("handle file already exists.  reconstituting stateful reference");

        FileInputStream fis = new FileInputStream(handleFile);

        ObjectInputStream ois = new ObjectInputStream(fis);

        for (int i = 0; i < sfuls.length; i++) {

          Handle sfulHandle = (Handle) ois.readObject();

          sfuls[i] = (Sful) sfulHandle.getEJBObject();

          System.out.println("invoking stateful" + i);

          sfuls[i].hello();

          System.out.println("successfully invoked stateful" + i);
        }

        ois.close();

        stat.addStatus("dcodewithhandles main", stat.PASS);

      } else {

        System.out.println("handle file doesn't exist.  Creating sful" + " bean");

        FileOutputStream fos = new FileOutputStream(handleFile);
        ObjectOutputStream oos = new ObjectOutputStream(fos);

        for (int i = 0; i < sfuls.length; i++) {

          sfuls[i] = sfulHome.create();

          System.out.println("invoking stateful" + i);
          sfuls[i].hello();

          Handle handle = sfuls[i].getHandle();
          oos.writeObject(handle);
        }

        oos.close();

        System.out.println("test complete");

        stat.addStatus("dcodenohandles main", stat.PASS);
      }

    } catch (Exception e) {
      e.printStackTrace();
      stat.addStatus("local main", stat.FAIL);
    }

    return;
  }