Search in sources :

Example 31 with StatefulBean

use of org.apache.openejb.jee.StatefulBean in project tomee by apache.

the class XmlOverridesTest method test.

public void test() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(AnnotatedBean.class));
    bean.getEjbLocalRef().add(new EjbLocalRef(name("annotatedLocal"), "BarBean"));
    bean.getEnvEntry().add(new EnvEntry(name("striing"), "java.lang.Integer", "2"));
    bean.getEnvEntry().add(new EnvEntry(name("doouble"), "java.lang.String", "two"));
    bean.getEnvEntry().add(new EnvEntry(name("loong"), "java.lang.String", "three"));
    bean.getEnvEntry().add(new EnvEntry(name("flooat"), "java.lang.String", "four"));
    bean.getEnvEntry().add(new EnvEntry(name("inteeger"), "java.lang.String", "five"));
    bean.getEnvEntry().add(new EnvEntry(name("shoort"), "java.lang.String", "six"));
    bean.getEnvEntry().add(new EnvEntry(name("booolean"), "java.lang.String", "seven"));
    bean.getEnvEntry().add(new EnvEntry(name("byyte"), "java.lang.String", "eight"));
    bean.getEnvEntry().add(new EnvEntry(name("chaaracter"), "java.lang.String", "nine"));
    final EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
    lookupEntry.setLookupName("java:app/AppName");
    bean.getEnvEntry().add(lookupEntry);
    bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));
    bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));
    bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
    final org.apache.openejb.jee.jpa.unit.PersistenceUnit persistenceUnit = new org.apache.openejb.jee.jpa.unit.PersistenceUnit("yellow");
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
    app.getEjbModules().add(new EjbModule(ejbJar));
    app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
    final AppInfo appInfo = config.configureApplication(app);
    final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    final JndiEncInfo enc = beanInfo.jndiEnc;
    assertEquals("Enc.ejbLocalReferences.size()", 1, enc.ejbLocalReferences.size());
    assertEquals("Enc.ejbLocalReferences.get(0).link", "BarBean", enc.ejbLocalReferences.get(0).link);
    assertEquals("Enc.ejbReferences.size()", 0, enc.ejbReferences.size());
    // 10 + ComponentName
    assertEquals("Enc.envEntries.size()", 11, enc.envEntries.size());
    final Map<String, EnvEntryInfo> entries = map(enc.envEntries);
    assertEnvEntry(entries, name("striing"), "java.lang.Integer", "2");
    assertEnvEntry(entries, name("doouble"), "java.lang.String", "two");
    assertEnvEntry(entries, name("loong"), "java.lang.String", "three");
    assertEnvEntry(entries, name("flooat"), "java.lang.String", "four");
    assertEnvEntry(entries, name("inteeger"), "java.lang.String", "five");
    assertEnvEntry(entries, name("shoort"), "java.lang.String", "six");
    assertEnvEntry(entries, name("booolean"), "java.lang.String", "seven");
    assertEnvEntry(entries, name("byyte"), "java.lang.String", "eight");
    assertEnvEntry(entries, name("chaaracter"), "java.lang.String", "nine");
    assertEnvEntryLookup(entries, name("lookup"), "java.lang.String", "java:app/AppName");
    assertEquals("Enc.persistenceContextRefs.size()", 1, enc.persistenceContextRefs.size());
    final PersistenceContextReferenceInfo context = enc.persistenceContextRefs.get(0);
    assertEquals("Context.extended", false, context.extended);
    assertEquals("Context.persistenceUnitName", "yellow", context.persistenceUnitName);
    assertEquals("Context.properties.size()", 1, context.properties.size());
    assertEquals("Context.properties.getProperty(\"zzzz\")", "AAAA", context.properties.getProperty("zzzz"));
    assertEquals("Enc.persistenceUnitRefs.size()", 1, enc.persistenceUnitRefs.size());
    final PersistenceUnitReferenceInfo unit = enc.persistenceUnitRefs.get(0);
    assertEquals("Unit.persistenceUnitName", "yellow", unit.persistenceUnitName);
    assertEquals("Enc.resourceRefs.size()", 1, enc.resourceRefs.size());
    final ResourceReferenceInfo resource = enc.resourceRefs.get(0);
    assertEquals("Resource.referenceAuth", "CONTAINER", resource.referenceAuth);
}
Also used : PersistenceContextRef(org.apache.openejb.jee.PersistenceContextRef) ArrayList(java.util.ArrayList) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) PersistenceUnit(javax.persistence.PersistenceUnit) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) Property(org.apache.openejb.jee.Property) PersistenceUnitRef(org.apache.openejb.jee.PersistenceUnitRef) EjbJar(org.apache.openejb.jee.EjbJar) EnvEntry(org.apache.openejb.jee.EnvEntry) EjbLocalRef(org.apache.openejb.jee.EjbLocalRef) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) JndiEncInfo(org.apache.openejb.assembler.classic.JndiEncInfo) StatefulBean(org.apache.openejb.jee.StatefulBean) EnvEntryInfo(org.apache.openejb.assembler.classic.EnvEntryInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ResourceRef(org.apache.openejb.jee.ResourceRef) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 32 with StatefulBean

use of org.apache.openejb.jee.StatefulBean in project tomee by apache.

the class CheckAnnotationTest method testWebServiceWithStateful.

@Keys({ @Key(value = "annotation.invalid.stateful.webservice", type = KeyType.WARNING) })
public AppModule testWebServiceWithStateful() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(Green.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Green.class)).link());
    final AppModule appModule = new AppModule(ejbModule);
    return appModule;
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Green(org.apache.openejb.test.annotated.Green) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Example 33 with StatefulBean

use of org.apache.openejb.jee.StatefulBean in project tomee by apache.

the class CheckInvalidCallbacksTest method test.

@Keys({ @Key(value = "ignoredMethodAnnotation", count = 10, type = KeyType.WARNING), @Key("callback.invalidArguments"), @Key("callback.badReturnType"), @Key("callback.badModifier"), @Key("callback.invalidArguments"), @Key("aroundInvoke.missing"), @Key("callback.missing"), @Key(value = "callback.sessionSynchronization.invalidUse", count = 2) })
public EjbJar test() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean testBean = ejbJar.addEnterpriseBean(new StatelessBean("TestStateless", TestBean.class));
    testBean.addAroundInvoke("wrongMethod");
    testBean.addPostConstruct("wrongMethod");
    ejbJar.addEnterpriseBean(new SingletonBean("TestSingleton", TestBean.class));
    ejbJar.addEnterpriseBean(new StatefulBean("FooStateful", FooBean.class));
    ejbJar.addEnterpriseBean(new StatefulBean("BarStateful", BarBean.class));
    final StatefulBean starBean = ejbJar.addEnterpriseBean(new StatefulBean("StarStateful", StarBean.class));
    starBean.setAfterBeginMethod(new NamedMethod("myAfterBegin"));
    starBean.setBeforeCompletionMethod(new NamedMethod("myBeforeCompletion"));
    starBean.setAfterCompletionMethod(new NamedMethod("myAfterCompletion"));
    return ejbJar;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) NamedMethod(org.apache.openejb.jee.NamedMethod) EjbJar(org.apache.openejb.jee.EjbJar)

Example 34 with StatefulBean

use of org.apache.openejb.jee.StatefulBean in project tomee by apache.

the class CheckMissingClassTest method wrongClassType.

@Keys(@Key(value = "missing.class", count = 16))
public EjbJar wrongClassType() throws OpenEJBException {
    System.setProperty("openejb.validation.output.level", "VERBOSE");
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean stateless = new StatelessBean(FooStateless.class);
    stateless.setHomeAndRemote("WrongHome", "WrongRemote");
    stateless.setLocal("WrongLocal");
    stateless.setLocalHome("WrongLocalHome");
    ejbJar.addEnterpriseBean(stateless);
    final StatefulBean stateful = new StatefulBean(FooStateful.class);
    stateful.setHomeAndRemote("WrongHome", "WrongRemote");
    stateful.setLocal("WrongLocal");
    stateful.setLocalHome("WrongLocalHome");
    ejbJar.addEnterpriseBean(stateful);
    final EntityBean bmpEntityBean = new EntityBean(FooEntityBMP.class, PersistenceType.BEAN);
    bmpEntityBean.setHome("WrongHome");
    bmpEntityBean.setLocalHome("WrongLocalHome");
    bmpEntityBean.setRemote("WrongRemote");
    bmpEntityBean.setLocal("WrongLocal");
    ejbJar.addEnterpriseBean(bmpEntityBean);
    final EntityBean cmpEntityBean = new EntityBean(FooEntityCMP.class, PersistenceType.CONTAINER);
    cmpEntityBean.setHome("WrongHome");
    cmpEntityBean.setLocalHome("WrongLocalHome");
    cmpEntityBean.setRemote("WrongRemote");
    cmpEntityBean.setLocal("WrongLocal");
    ejbJar.addEnterpriseBean(cmpEntityBean);
    return ejbJar;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EntityBean(org.apache.openejb.jee.EntityBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 35 with StatefulBean

use of org.apache.openejb.jee.StatefulBean in project tomee by apache.

the class CheckNoCreateMethodsTest method noCreateMethod.

@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");
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean stateless = new StatelessBean(FooStateless.class);
    stateless.setHomeAndRemote(FooStatelessHome.class, FooStatelessRemote.class);
    stateless.setHomeAndLocal(FooStatelessLocalHome.class, FooStatelessLocal.class);
    ejbJar.addEnterpriseBean(stateless);
    final StatefulBean stateful = new StatefulBean(FooStateful.class);
    stateful.setHomeAndRemote(FooStatefulHome.class, FooStatefulRemote.class);
    stateful.setHomeAndLocal(FooStatefulLocalHome.class, FooStatefulLocal.class);
    ejbJar.addEnterpriseBean(stateful);
    final 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);
    final 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);
    final StatelessBean bar = new StatelessBean(BarStateless.class);
    bar.setHomeAndRemote(BarStatelessHome.class, BarStatelessRemote.class);
    ejbJar.addEnterpriseBean(bar);
    final StatefulBean bazStateful = new StatefulBean(BazStateful.class);
    ejbJar.addEnterpriseBean(bazStateful);
    return ejbJar;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EntityBean(javax.ejb.EntityBean) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

StatefulBean (org.apache.openejb.jee.StatefulBean)36 EjbJar (org.apache.openejb.jee.EjbJar)33 Assembler (org.apache.openejb.assembler.classic.Assembler)18 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)18 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)18 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)16 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)12 StatelessBean (org.apache.openejb.jee.StatelessBean)12 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)10 StatefulSessionContainerInfo (org.apache.openejb.assembler.classic.StatefulSessionContainerInfo)7 EjbModule (org.apache.openejb.config.EjbModule)7 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)6 NamedMethod (org.apache.openejb.jee.NamedMethod)6 InitialContext (javax.naming.InitialContext)5 AppModule (org.apache.openejb.config.AppModule)3 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)3 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)3 SingletonBean (org.apache.openejb.jee.SingletonBean)3 Timeout (org.apache.openejb.jee.Timeout)3 Properties (java.util.Properties)2