public AppModule fillInMissingType(AppModule appModule) throws OpenEJBException {

    for (ClientModule module : appModule.getClientModules()) {
      final JndiConsumer consumer = module.getApplicationClient();
      if (consumer == null) continue;

      fillInMissingType(consumer, module);
    }

    for (WebModule module : appModule.getWebModules()) {
      final JndiConsumer consumer = module.getWebApp();
      if (consumer == null) continue;

      fillInMissingType(consumer, module);
    }

    for (EjbModule module : appModule.getEjbModules()) {
      final EjbJar ejbJar = module.getEjbJar();
      if (ejbJar == null) continue;

      for (EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
        fillInMissingType(consumer, module);
      }
    }

    return appModule;
  }
  protected void setUp() throws Exception {
    super.setUp();

    System.setProperty(
        javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());

    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();

    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    // containers
    final StatelessSessionContainerInfo statelessContainerInfo =
        config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "10");
    statelessContainerInfo.properties.setProperty("MaxSize", "0");
    statelessContainerInfo.properties.setProperty("StrictPooling", "false");
    assembler.createContainer(statelessContainerInfo);

    // Setup the descriptor information

    final StatelessBean bean = new StatelessBean(WidgetBean.class);
    bean.addBusinessLocal(Widget.class.getName());
    bean.addBusinessRemote(RemoteWidget.class.getName());

    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);

    assembler.createApplication(config.configureApplication(ejbJar));
  }
  public AppModule removeUnsetEnvEntries(AppModule appModule) throws OpenEJBException {

    for (ClientModule module : appModule.getClientModules()) {
      final JndiConsumer consumer = module.getApplicationClient();
      if (consumer == null) continue;

      removeUnsetEnvEntries(consumer);
    }

    for (WebModule module : appModule.getWebModules()) {
      final JndiConsumer consumer = module.getWebApp();
      if (consumer == null) continue;

      removeUnsetEnvEntries(consumer);
    }

    for (EjbModule module : appModule.getEjbModules()) {
      final EjbJar ejbJar = module.getEjbJar();
      if (ejbJar == null) continue;

      for (EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
        removeUnsetEnvEntries(consumer);
      }
    }

    return appModule;
  }
  protected void setUp() throws Exception {
    super.setUp();

    System.setProperty(
        javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());

    ConfigurationFactory config = new ConfigurationFactory();
    Assembler assembler = new Assembler();

    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    // containers
    assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));

    // Setup the descriptor information

    SingletonBean bean = new SingletonBean(WidgetBean.class);
    bean.addBusinessLocal(Widget.class.getName());
    bean.addBusinessRemote(RemoteWidget.class.getName());
    bean.addPostConstruct("init");
    bean.addPreDestroy("destroy");
    bean.setLocalBean(new Empty());

    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);

    assembler.createApplication(config.configureApplication(ejbJar));
  }
  public void test() throws Exception {
    ConfigurationFactory config = new ConfigurationFactory();
    Assembler assembler = new Assembler();

    // System services
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    // JMS persistence datasource
    ResourceInfo dataSourceInfo =
        config.configureService("Default Unmanaged JDBC Database", ResourceInfo.class);
    dataSourceInfo.properties.setProperty("JdbcUrl", "jdbc:hsqldb:mem:MdbConfigTest");
    assembler.createResource(dataSourceInfo);

    // JMS
    assembler.createResource(
        config.configureService("Default JMS Resource Adapter", ResourceInfo.class));

    // JMS Container
    MdbContainerInfo mdbContainerInfo = config.configureService(MdbContainerInfo.class);
    assembler.createContainer(mdbContainerInfo);

    // FakeRA
    ResourceInfo resourceInfo = new ResourceInfo();
    resourceInfo.service = "Resource";
    resourceInfo.className = FakeRA.class.getName();
    resourceInfo.id = "FakeRA";
    resourceInfo.properties = new Properties();
    assembler.createResource(resourceInfo);

    // FakeRA container
    ContainerInfo containerInfo = config.configureService(MdbContainerInfo.class);
    containerInfo.id = "FakeContainer";
    containerInfo.displayName = "Fake Container";
    containerInfo.properties.setProperty("ResourceAdapter", "FakeRA");
    containerInfo.properties.setProperty(
        "MessageListenerInterface", FakeMessageListener.class.getName());
    containerInfo.properties.setProperty("ActivationSpecClass", FakeActivationSpec.class.getName());
    assembler.createContainer(containerInfo);

    // generate ejb jar application
    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(
        createJaxbMdb("JmsMdb", BasicMdbBean.class.getName(), MessageListener.class.getName()));
    ejbJar.addEnterpriseBean(
        createJaxbMdb("FakeMdb", FakeMdb.class.getName(), FakeMessageListener.class.getName()));
    EjbModule ejbModule =
        new EjbModule(getClass().getClassLoader(), "FakeEjbJar", "fake.jar", ejbJar, null);

    // configure and deploy it
    EjbJarInfo info = config.configureApplication(ejbModule);
    assembler.createEjbJar(info);
  }
 @Keys({
   @Key(value = "aroundInvoke.invalidArguments", count = 2),
   @Key(value = "aroundInvoke.badReturnType", count = 2)
 })
 public EjbJar testInvalidAroundTimeoutParameter() throws Exception {
   final EjbJar ejbJar = new EjbJar();
   ejbJar.addEnterpriseBean(
       new StatelessBean(
           "TestInvalidAroundTimeoutParameterBean", TestInvalidAroundTimeoutParameterBean.class));
   ejbJar.addInterceptor(new Interceptor(TestInvalidAroundTimeoutParameterInterceptor.class));
   return ejbJar;
 }
Beispiel #7
0
 @Override
 public <T extends EnterpriseBean> T addEnterpriseBean(final T bean) {
   if (CompManagedBean.class.isInstance(bean)) {
     super.addEnterpriseBean(bean);
   }
   return bean;
 }
  @Override
  protected void setUp() throws Exception {

    System.setProperty(
        javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());

    ConfigurationFactory config = new ConfigurationFactory();
    Assembler assembler = new Assembler();

    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(ChildBean.class));

    assembler.createApplication(config.configureApplication(ejbJar));
  }
 @Keys({
   @Key(value = "no.home.create", count = 4),
   @Key(value = "unused.ejb.create", count = 2, type = KeyType.WARNING),
   @Key(value = "unused.ejbPostCreate", type = KeyType.WARNING),
   @Key("entity.no.ejb.create"),
   @Key(value = "session.no.ejb.create", count = 2)
 })
 public EjbJar noCreateMethod() throws OpenEJBException {
   System.setProperty("openejb.validation.output.level", "VERBOSE");
   EjbJar ejbJar = new EjbJar();
   StatelessBean stateless = new StatelessBean(FooStateless.class);
   stateless.setHomeAndRemote(FooStatelessHome.class, FooStatelessRemote.class);
   stateless.setHomeAndLocal(FooStatelessLocalHome.class, FooStatelessLocal.class);
   ejbJar.addEnterpriseBean(stateless);
   StatefulBean stateful = new StatefulBean(FooStateful.class);
   stateful.setHomeAndRemote(FooStatefulHome.class, FooStatefulRemote.class);
   stateful.setHomeAndLocal(FooStatefulLocalHome.class, FooStatefulLocal.class);
   ejbJar.addEnterpriseBean(stateful);
   org.apache.openejb.jee.EntityBean bean =
       new org.apache.openejb.jee.EntityBean(MyEntity.class, PersistenceType.BEAN);
   bean.setLocalHome(MyLocalHome.class.getName());
   bean.setLocal(MyLocal.class.getName());
   ejbJar.addEnterpriseBean(bean);
   org.apache.openejb.jee.EntityBean bean1 =
       new org.apache.openejb.jee.EntityBean(YourEntity.class, PersistenceType.BEAN);
   bean1.setLocalHome(MyLocalHome.class.getName());
   bean1.setLocal(MyLocal.class.getName());
   ejbJar.addEnterpriseBean(bean1);
   StatelessBean bar = new StatelessBean(BarStateless.class);
   bar.setHomeAndRemote(BarStatelessHome.class, BarStatelessRemote.class);
   ejbJar.addEnterpriseBean(bar);
   StatefulBean bazStateful = new StatefulBean(BazStateful.class);
   ejbJar.addEnterpriseBean(bazStateful);
   return ejbJar;
 }
  public void test() throws Exception {
    System.setProperty(
        javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());

    ConfigurationFactory config = new ConfigurationFactory();
    Assembler assembler = new Assembler();

    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    // containers
    StatefulSessionContainerInfo statefulContainerInfo =
        config.configureService(StatefulSessionContainerInfo.class);
    statefulContainerInfo.properties.setProperty("PoolSize", "0");
    statefulContainerInfo.properties.setProperty("BulkPassivate", "1");
    statefulContainerInfo.properties.setProperty("Frequency", "0");
    assembler.createContainer(statefulContainerInfo);

    EjbJar ejbJar = new EjbJar();
    StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(TargetBean.class));
    bean.setHomeAndRemote(TargetHome.class, Target.class);

    assembler.createApplication(
        config.configureApplication(
            new EjbModule(
                getClass().getClassLoader(), getClass().getSimpleName(), "test", ejbJar, null)));

    calls.clear();

    InitialContext ctx = new InitialContext();
    TargetHome home = (TargetHome) ctx.lookup("TargetBeanRemoteHome");
    assertNotNull(home);

    Target target = home.create("Fuzz");
    assertNotNull(target);

    String name = target.getName();
    assertEquals("Fuzz", name);

    target.remove();

    assertCalls(Call.values());
  }
  public void testInject() throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Widget.class));
    map.put(EJBContainer.MODULES, ejbJar);

    OpenEjbContainer openEjbContainer = (OpenEjbContainer) EJBContainer.createEJBContainer(map);

    openEjbContainer.inject(this);

    assertNotNull(widget);

    widget = null;

    openEjbContainer.getContext().bind("inject", this);

    openEjbContainer.close();
  }
 private StatelessBean addBean(Class<?> orangeBeanClass) {
   return ejbJar.addEnterpriseBean(new StatelessBean(orangeBeanClass));
 }
 @Keys(@Key(value = "ignoredMethodAnnotation", type = KeyType.WARNING))
 public EjbJar testIgnoredAroundTimeout() throws Exception {
   final EjbJar ejbJar = new EjbJar();
   ejbJar.addEnterpriseBean(new StatefulBean("TestAroundTimeout", TestAroundTimeout.class));
   return ejbJar;
 }
  public void test() throws Exception {
    System.setProperty(
        javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();

    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    final EjbJar ejbJar = new EjbJar();
    final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();

    final Interceptor interceptor = new Interceptor(SimpleInterceptor.class);
    ejbJar.addInterceptor(interceptor);

    // Test SessionSynchronization interface
    final StatefulBean subBeanA = new StatefulBean(SubBeanA.class);
    ejbJar.addEnterpriseBean(subBeanA);
    assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptor));

    // Test configure session synchronization callback methods in deployment plan
    final StatefulBean subBeanB = new StatefulBean(SubBeanB.class);
    subBeanB.setAfterBeginMethod(new NamedMethod(SubBeanB.class.getDeclaredMethod("afterBegin")));
    subBeanB.setBeforeCompletionMethod(
        new NamedMethod(SubBeanB.class.getDeclaredMethod("beforeCompletion")));
    subBeanB.setAfterCompletionMethod(
        new NamedMethod(SubBeanB.class.getDeclaredMethod("afterCompletion", boolean.class)));
    ejbJar.addEnterpriseBean(subBeanB);
    assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptor));

    // Test session synchronization methods via annotations
    final StatefulBean subBeanC = new StatefulBean(SubBeanC.class);
    ejbJar.addEnterpriseBean(subBeanC);
    assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptor));

    // Test override the annotations by deployment plan
    final StatefulBean subBeanD = new StatefulBean(SubBeanD.class);
    subBeanD.setAfterBeginMethod(
        new NamedMethod(SubBeanD.class.getDeclaredMethod("afterBeginNew")));
    subBeanD.setBeforeCompletionMethod(
        new NamedMethod(SubBeanD.class.getDeclaredMethod("beforeCompletionNew")));
    subBeanD.setAfterCompletionMethod(
        new NamedMethod(SubBeanD.class.getDeclaredMethod("afterCompletionNew", boolean.class)));
    ejbJar.addEnterpriseBean(subBeanD);
    assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanD, interceptor));

    // Test only one session synchronization method @AfterBegin
    final StatefulBean subBeanE = new StatefulBean(SubBeanE.class);
    ejbJar.addEnterpriseBean(subBeanE);
    assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanE, interceptor));

    // Test only one session synchronization method @AfterCompletion
    final StatefulBean subBeanF = new StatefulBean(SubBeanF.class);
    ejbJar.addEnterpriseBean(subBeanF);
    assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanF, interceptor));

    // Test only one session synchronization method @BeforeCompletion
    final StatefulBean subBeanG = new StatefulBean(SubBeanG.class);
    ejbJar.addEnterpriseBean(subBeanG);
    assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanG, interceptor));

    // Test SessionSynchronization interface but methods are in the parent class
    // Interceptor is declared on the bean method
    final StatefulBean subBeanH = new StatefulBean(SubBeanH.class);
    ejbJar.addEnterpriseBean(subBeanH);

    // Test SessionSynchronization interface but methods are in the parent class
    // using @LocalBean
    final StatefulBean subBeanI = new StatefulBean(SubBeanI.class);
    ejbJar.addEnterpriseBean(subBeanI);

    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    final InitialContext context = new InitialContext();

    final List<Call> expectedResult =
        Arrays.asList(
            Call.INTERCEPTOR_AFTER_BEGIN,
            Call.BEAN_AFTER_BEGIN,
            Call.INTERCEPTOR_AROUND_INVOKE_BEGIN,
            Call.BEAN_AROUND_INVOKE_BEGIN,
            Call.BEAN_METHOD,
            Call.BEAN_AROUND_INVOKE_AFTER,
            Call.INTERCEPTOR_AROUND_INVOKE_AFTER,
            Call.INTERCEPTOR_BEFORE_COMPLETION,
            Call.BEAN_BEFORE_COMPLETION,
            Call.INTERCEPTOR_AFTER_COMPLETION,
            Call.BEAN_AFTER_COMPLETION);

    {
      final BeanInterface beanA = (BeanInterface) context.lookup("SubBeanALocal");
      beanA.simpleMethod();
      assertEquals(expectedResult, result);
      result.clear();
    }

    {
      final BeanInterface beanB = (BeanInterface) context.lookup("SubBeanBLocal");
      beanB.simpleMethod();
      assertEquals(expectedResult, result);
      result.clear();
    }

    {
      final BeanInterface beanC = (BeanInterface) context.lookup("SubBeanCLocal");
      beanC.simpleMethod();
      assertEquals(expectedResult, result);
      result.clear();
    }

    {
      final BeanInterface beanD = (BeanInterface) context.lookup("SubBeanDLocal");
      beanD.simpleMethod();
      assertEquals(expectedResult, result);
      result.clear();
    }

    {
      final BeanInterface beanE = (BeanInterface) context.lookup("SubBeanELocal");
      beanE.simpleMethod();
      assertEquals(
          Arrays.asList(
              Call.INTERCEPTOR_AFTER_BEGIN,
              Call.BEAN_AFTER_BEGIN,
              Call.INTERCEPTOR_AROUND_INVOKE_BEGIN,
              Call.BEAN_AROUND_INVOKE_BEGIN,
              Call.BEAN_METHOD,
              Call.BEAN_AROUND_INVOKE_AFTER,
              Call.INTERCEPTOR_AROUND_INVOKE_AFTER,
              Call.INTERCEPTOR_BEFORE_COMPLETION,
              Call.INTERCEPTOR_AFTER_COMPLETION),
          result);
      result.clear();
    }

    {
      final BeanInterface beanF = (BeanInterface) context.lookup("SubBeanFLocal");
      beanF.simpleMethod();
      assertEquals(
          Arrays.asList(
              Call.INTERCEPTOR_AFTER_BEGIN,
              Call.INTERCEPTOR_AROUND_INVOKE_BEGIN,
              Call.BEAN_AROUND_INVOKE_BEGIN,
              Call.BEAN_METHOD,
              Call.BEAN_AROUND_INVOKE_AFTER,
              Call.INTERCEPTOR_AROUND_INVOKE_AFTER,
              Call.INTERCEPTOR_BEFORE_COMPLETION,
              Call.INTERCEPTOR_AFTER_COMPLETION,
              Call.BEAN_AFTER_COMPLETION),
          result);
      result.clear();
    }

    {
      final BeanInterface beanG = (BeanInterface) context.lookup("SubBeanGLocal");
      beanG.simpleMethod();
      assertEquals(
          Arrays.asList(
              Call.INTERCEPTOR_AFTER_BEGIN,
              Call.INTERCEPTOR_AROUND_INVOKE_BEGIN,
              Call.BEAN_AROUND_INVOKE_BEGIN,
              Call.BEAN_METHOD,
              Call.BEAN_AROUND_INVOKE_AFTER,
              Call.INTERCEPTOR_AROUND_INVOKE_AFTER,
              Call.INTERCEPTOR_BEFORE_COMPLETION,
              Call.BEAN_BEFORE_COMPLETION,
              Call.INTERCEPTOR_AFTER_COMPLETION),
          result);
      result.clear();
    }

    final List<Call> synchAndArroundInvokeResult =
        Arrays.asList(
            Call.BEAN_AFTER_BEGIN,
            Call.INTERCEPTOR_AROUND_INVOKE_BEGIN,
            Call.BEAN_AROUND_INVOKE_BEGIN,
            Call.BEAN_METHOD,
            Call.BEAN_AROUND_INVOKE_AFTER,
            Call.INTERCEPTOR_AROUND_INVOKE_AFTER,
            Call.BEAN_BEFORE_COMPLETION,
            Call.BEAN_AFTER_COMPLETION);
    {
      final BeanInterface beanH = (BeanInterface) context.lookup("SubBeanHLocal");
      beanH.simpleMethod();
      assertEquals(synchAndArroundInvokeResult, result);
      result.clear();
    }

    {
      final BeanInterface beanI = (BeanInterface) context.lookup("SubBeanILocalBean");
      beanI.simpleMethod();
      assertEquals(synchAndArroundInvokeResult, result);
      result.clear();
    }
  }