use of org.apache.openejb.jee.ContainerTransaction$JAXB.readContainerTransaction in project tomee by apache.
the class StatefulTransactionAttributesTest method test.
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();
ejbJar.addEnterpriseBean(new StatefulBean(Color.class));
ejbJar.addEnterpriseBean(new StatefulBean(Red.class));
ejbJar.addEnterpriseBean(new StatefulBean(Crimson.class));
ejbJar.addEnterpriseBean(new StatefulBean(Scarlet.class));
final List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "*", "Crimson", "*"));
declared.add(new ContainerTransaction(TransAttribute.REQUIRES_NEW, "*", "Crimson", "create"));
final ContainerTransaction o = new ContainerTransaction(TransAttribute.SUPPORTS, "*", "Crimson", "create");
o.getMethod().get(0).setMethodIntf(MethodIntf.HOME);
declared.add(o);
declared.add(new ContainerTransaction(TransAttribute.REQUIRES_NEW, "*", "Crimson", "remove"));
declared.add(new ContainerTransaction(TransAttribute.REQUIRES_NEW, Color.class.getName(), "Scarlet", "*"));
declared.add(new ContainerTransaction(TransAttribute.NEVER, Red.class.getName(), "Scarlet", "red"));
declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "Scarlet", Scarlet.class.getMethod("scarlet")));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assembler.createApplication(ejbJarInfo);
final InitialContext context = new InitialContext();
{
final ColorLocal color = (ColorLocal) context.lookup("ColorLocal");
assertEquals("Never", color.color());
assertEquals("RequiresNew", color.color((Object) null));
assertEquals("Supports", color.color((String) null));
assertEquals("Supports", color.color((Boolean) null));
assertEquals("Supports", color.color((Integer) null));
}
{
final ColorRemote color = (ColorRemote) context.lookup("ColorRemote");
assertEquals("Never", color.color());
assertEquals("RequiresNew", color.color((Object) null));
assertEquals("Supports", color.color((String) null));
assertEquals("Supports", color.color((Boolean) null));
assertEquals("Supports", color.color((Integer) null));
}
{
final ColorEjbLocalHome home = (ColorEjbLocalHome) context.lookup("ColorLocalHome");
final ColorEjbLocalObject color = home.create("Supports");
assertEquals("Never", color.color());
assertEquals("RequiresNew", color.color((Object) null));
assertEquals("Supports", color.color((String) null));
assertEquals("Supports", color.color((Boolean) null));
assertEquals("Supports", color.color((Integer) null));
expected.set("Supports");
color.remove();
}
{
final ColorEjbHome home = (ColorEjbHome) context.lookup("ColorRemoteHome");
final ColorEjbObject color = home.create("Supports");
assertEquals("Never", color.color());
assertEquals("RequiresNew", color.color((Object) null));
assertEquals("Supports", color.color((String) null));
assertEquals("Supports", color.color((Boolean) null));
assertEquals("Supports", color.color((Integer) null));
expected.set("Supports");
color.remove();
}
{
final RedLocal red = (RedLocal) context.lookup("RedLocal");
assertEquals("Never", red.color());
assertEquals("Required", red.color((Object) null));
assertEquals("Supports", red.color((String) null));
assertEquals("Supports", red.color((Boolean) null));
assertEquals("Supports", red.color((Integer) null));
assertEquals("RequiresNew", red.red());
assertEquals("Required", red.red((Object) null));
assertEquals("Required", red.red((String) null));
}
{
final RedRemote red = (RedRemote) context.lookup("RedRemote");
assertEquals("Never", red.color());
assertEquals("Required", red.color((Object) null));
assertEquals("Supports", red.color((String) null));
assertEquals("Supports", red.color((Boolean) null));
assertEquals("Supports", red.color((Integer) null));
assertEquals("RequiresNew", red.red());
assertEquals("Required", red.red((Object) null));
assertEquals("Required", red.red((String) null));
}
{
final RedEjbLocalHome home = (RedEjbLocalHome) context.lookup("RedLocalHome");
final RedEjbLocalObject red = home.create("Supports");
assertEquals("Never", red.color());
assertEquals("Required", red.color((Object) null));
assertEquals("Supports", red.color((String) null));
assertEquals("Supports", red.color((Boolean) null));
assertEquals("Supports", red.color((Integer) null));
assertEquals("RequiresNew", red.red());
assertEquals("Required", red.red((Object) null));
assertEquals("Required", red.red((String) null));
expected.set("Supports");
red.remove();
}
{
final RedEjbHome home = (RedEjbHome) context.lookup("RedRemoteHome");
final RedEjbObject red = home.create("Supports");
assertEquals("Never", red.color());
assertEquals("Required", red.color((Object) null));
assertEquals("Supports", red.color((String) null));
assertEquals("Supports", red.color((Boolean) null));
assertEquals("Supports", red.color((Integer) null));
assertEquals("RequiresNew", red.red());
assertEquals("Required", red.red((Object) null));
assertEquals("Required", red.red((String) null));
expected.set("Supports");
red.remove();
}
{
final CrimsonLocal crimson = (CrimsonLocal) context.lookup("CrimsonLocal");
assertEquals("Required", crimson.color());
assertEquals("Required", crimson.color((Object) null));
assertEquals("Required", crimson.color((String) null));
assertEquals("Required", crimson.color((Boolean) null));
assertEquals("Required", crimson.color((Integer) null));
assertEquals("RequiresNew", crimson.red());
assertEquals("Required", crimson.red((Object) null));
assertEquals("Required", crimson.red((String) null));
assertEquals("RequiresNew", crimson.crimson());
assertEquals("Required", crimson.crimson((String) null));
}
{
final CrimsonRemote crimson = (CrimsonRemote) context.lookup("CrimsonRemote");
assertEquals("Required", crimson.color());
assertEquals("Required", crimson.color((Object) null));
assertEquals("Required", crimson.color((String) null));
assertEquals("Required", crimson.color((Boolean) null));
assertEquals("Required", crimson.color((Integer) null));
assertEquals("RequiresNew", crimson.red());
assertEquals("Required", crimson.red((Object) null));
assertEquals("Required", crimson.red((String) null));
assertEquals("RequiresNew", crimson.crimson());
assertEquals("Required", crimson.crimson((String) null));
}
{
final CrimsonEjbLocalHome home = (CrimsonEjbLocalHome) context.lookup("CrimsonLocalHome");
final CrimsonEjbLocalObject crimson = home.create("RequiresNew");
assertEquals("Required", crimson.color());
assertEquals("Required", crimson.color((Object) null));
assertEquals("Required", crimson.color((String) null));
assertEquals("Required", crimson.color((Boolean) null));
assertEquals("Required", crimson.color((Integer) null));
assertEquals("RequiresNew", crimson.red());
assertEquals("Required", crimson.red((Object) null));
assertEquals("Required", crimson.red((String) null));
assertEquals("RequiresNew", crimson.crimson());
assertEquals("Required", crimson.crimson((String) null));
expected.set("RequiresNew");
crimson.remove();
}
{
final CrimsonEjbHome home = (CrimsonEjbHome) context.lookup("CrimsonRemoteHome");
final CrimsonEjbObject crimson = home.create("Supports");
assertEquals("Required", crimson.color());
assertEquals("Required", crimson.color((Object) null));
assertEquals("Required", crimson.color((String) null));
assertEquals("Required", crimson.color((Boolean) null));
assertEquals("Required", crimson.color((Integer) null));
assertEquals("RequiresNew", crimson.red());
assertEquals("Required", crimson.red((Object) null));
assertEquals("Required", crimson.red((String) null));
assertEquals("RequiresNew", crimson.crimson());
assertEquals("Required", crimson.crimson((String) null));
expected.set("RequiresNew");
crimson.remove();
}
{
final ScarletLocal scarlet = (ScarletLocal) context.lookup("ScarletLocal");
assertEquals("Never", scarlet.color());
assertEquals("Required", scarlet.color((Object) null));
assertEquals("RequiresNew", scarlet.color((String) null));
assertEquals("RequiresNew", scarlet.color((Boolean) null));
assertEquals("RequiresNew", scarlet.color((Integer) null));
assertEquals("RequiresNew", scarlet.red());
assertEquals("Never", scarlet.red((Object) null));
assertEquals("Never", scarlet.red((String) null));
assertEquals("Required", scarlet.scarlet());
assertEquals("NotSupported", scarlet.scarlet((String) null));
}
{
final ScarletRemote scarlet = (ScarletRemote) context.lookup("ScarletRemote");
assertEquals("Never", scarlet.color());
assertEquals("Required", scarlet.color((Object) null));
assertEquals("RequiresNew", scarlet.color((String) null));
assertEquals("RequiresNew", scarlet.color((Boolean) null));
assertEquals("RequiresNew", scarlet.color((Integer) null));
assertEquals("RequiresNew", scarlet.red());
assertEquals("Never", scarlet.red((Object) null));
assertEquals("Never", scarlet.red((String) null));
assertEquals("Required", scarlet.scarlet());
assertEquals("NotSupported", scarlet.scarlet((String) null));
}
{
final ScarletEjbLocalHome home = (ScarletEjbLocalHome) context.lookup("ScarletLocalHome");
final ScarletEjbLocalObject scarlet = home.create("RequiresNew");
assertEquals("Never", scarlet.color());
assertEquals("Required", scarlet.color((Object) null));
assertEquals("RequiresNew", scarlet.color((String) null));
assertEquals("RequiresNew", scarlet.color((Boolean) null));
assertEquals("RequiresNew", scarlet.color((Integer) null));
assertEquals("RequiresNew", scarlet.red());
assertEquals("Never", scarlet.red((Object) null));
assertEquals("Never", scarlet.red((String) null));
assertEquals("Required", scarlet.scarlet());
assertEquals("NotSupported", scarlet.scarlet((String) null));
}
{
final ScarletEjbHome home = (ScarletEjbHome) context.lookup("ScarletRemoteHome");
final ScarletEjbObject scarlet = home.create("RequiresNew");
assertEquals("Never", scarlet.color());
assertEquals("Required", scarlet.color((Object) null));
assertEquals("RequiresNew", scarlet.color((String) null));
assertEquals("RequiresNew", scarlet.color((Boolean) null));
assertEquals("RequiresNew", scarlet.color((Integer) null));
assertEquals("RequiresNew", scarlet.red());
assertEquals("Never", scarlet.red((Object) null));
assertEquals("Never", scarlet.red((String) null));
assertEquals("Required", scarlet.scarlet());
assertEquals("NotSupported", scarlet.scarlet((String) null));
}
}
use of org.apache.openejb.jee.ContainerTransaction$JAXB.readContainerTransaction in project tomee by apache.
the class CheckInvalidTransactionAttributeTest method xml.
@Keys(@Key(value = "xml.invalidTransactionAttribute", type = KeyType.WARNING))
public EjbJar xml() throws SecurityException, NoSuchMethodException {
final EjbJar ejbJar = new EjbJar();
final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(CheeseEjb.class));
bean.setTransactionType(TransactionType.BEAN);
final ContainerTransaction tx = new ContainerTransaction();
tx.getMethod().add(new Method(bean.getEjbName(), CheeseEjb.class.getMethod("sayCheesePlease", null)));
tx.setTransAttribute(TransAttribute.REQUIRED);
ejbJar.getAssemblyDescriptor().getContainerTransaction().add(tx);
return ejbJar;
}
use of org.apache.openejb.jee.ContainerTransaction$JAXB.readContainerTransaction in project tomee by apache.
the class LegacyInterfaceTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
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();
ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
// <entity>
// <ejb-name>License</ejb-name>
// <local-home>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocalHome</local-home>
// <local>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocal</local>
// <ejb-class>org.apache.openejb.test.entity.cmr.onetoone.LicenseBean</ejb-class>
// <persistence-type>Container</persistence-type>
// <prim-key-class>java.lang.Integer</prim-key-class>
// <reentrant>false</reentrant>
// <cmp-version>2.x</cmp-version>
// <abstract-schema-name>License</abstract-schema-name>
// <cmp-field>
// <field-name>id</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>number</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>points</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>notes</field-name>
// </cmp-field>
// <primkey-field>id</primkey-field>
// <query>
// <!-- CompondPK one-to-one shares the local home interface so we need to declare this useless finder -->
// <query-method>
// <method-name>findByPrimaryKey</method-name>
// <method-params>
// <method-param>org.apache.openejb.test.entity.cmr.onetoone.LicensePk</method-param>
// </method-params>
// </query-method>
// <ejb-ql>SELECT OBJECT(DL) FROM License DL</ejb-ql>
// </query>
// </entity>
final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
cmp.setPrimKeyClass(Integer.class.getName());
cmp.setPrimkeyField("id");
cmp.getCmpField().add(new CmpField("id"));
cmp.getCmpField().add(new CmpField("name"));
final Query query = new Query();
query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
cmp.getQuery().add(query);
final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
// <container-transaction>
// <method>
// <ejb-name>MyBean</ejb-name>
// <method-name>*</method-name>
// </method>
// <trans-attribute>Supports</trans-attribute>
// </container-transaction>
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
final File f = new File("test").getAbsoluteFile();
if (!f.exists() && !f.mkdirs()) {
throw new Exception("Failed to create test directory: " + f);
}
final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
module.getEjbModules().add(new EjbModule(ejbJar));
assembler.createApplication(config.configureApplication(module));
}
use of org.apache.openejb.jee.ContainerTransaction$JAXB.readContainerTransaction in project tomee by apache.
the class AssemblyDescriptor$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final AssemblyDescriptor assemblyDescriptor, RuntimeContext context) throws Exception {
if (assemblyDescriptor == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (AssemblyDescriptor.class != assemblyDescriptor.getClass()) {
context.unexpectedSubclass(writer, assemblyDescriptor, AssemblyDescriptor.class);
return;
}
context.beforeMarshal(assemblyDescriptor, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = assemblyDescriptor.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(assemblyDescriptor, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: securityRole
final List<SecurityRole> securityRole = assemblyDescriptor.securityRole;
if (securityRole != null) {
for (final SecurityRole securityRoleItem : securityRole) {
if (securityRoleItem != null) {
writer.writeStartElement(prefix, "security-role", "http://java.sun.com/xml/ns/javaee");
writeSecurityRole(writer, securityRoleItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(assemblyDescriptor, "securityRole");
}
}
}
// ELEMENT: methodPermission
final List<MethodPermission> methodPermission = assemblyDescriptor.methodPermission;
if (methodPermission != null) {
for (final MethodPermission methodPermissionItem : methodPermission) {
if (methodPermissionItem != null) {
writer.writeStartElement(prefix, "method-permission", "http://java.sun.com/xml/ns/javaee");
writeMethodPermission(writer, methodPermissionItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(assemblyDescriptor, "methodPermission");
}
}
}
// ELEMENT: containerTransaction
final List<ContainerTransaction> containerTransaction = assemblyDescriptor.containerTransaction;
if (containerTransaction != null) {
for (final ContainerTransaction containerTransactionItem : containerTransaction) {
if (containerTransactionItem != null) {
writer.writeStartElement(prefix, "container-transaction", "http://java.sun.com/xml/ns/javaee");
writeContainerTransaction(writer, containerTransactionItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(assemblyDescriptor, "containerTransaction");
}
}
}
// ELEMENT: containerConcurrency
final List<ContainerConcurrency> containerConcurrency = assemblyDescriptor.containerConcurrency;
if (containerConcurrency != null) {
for (final ContainerConcurrency containerConcurrencyItem : containerConcurrency) {
if (containerConcurrencyItem != null) {
writer.writeStartElement(prefix, "container-concurrency", "http://java.sun.com/xml/ns/javaee");
writeContainerConcurrency(writer, containerConcurrencyItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(assemblyDescriptor, "containerConcurrency");
}
}
}
// ELEMENT: interceptorBinding
final List<InterceptorBinding> interceptorBinding = assemblyDescriptor.interceptorBinding;
if (interceptorBinding != null) {
for (final InterceptorBinding interceptorBindingItem : interceptorBinding) {
if (interceptorBindingItem != null) {
writer.writeStartElement(prefix, "interceptor-binding", "http://java.sun.com/xml/ns/javaee");
writeInterceptorBinding(writer, interceptorBindingItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(assemblyDescriptor, "interceptorBinding");
}
}
}
// ELEMENT: messageDestination
final List<MessageDestination> messageDestination = assemblyDescriptor.messageDestination;
if (messageDestination != null) {
for (final MessageDestination messageDestinationItem : messageDestination) {
if (messageDestinationItem != null) {
writer.writeStartElement(prefix, "message-destination", "http://java.sun.com/xml/ns/javaee");
writeMessageDestination(writer, messageDestinationItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(assemblyDescriptor, "messageDestination");
}
}
}
// ELEMENT: excludeList
final ExcludeList excludeList = assemblyDescriptor.excludeList;
if (excludeList != null) {
writer.writeStartElement(prefix, "exclude-list", "http://java.sun.com/xml/ns/javaee");
writeExcludeList(writer, excludeList, context);
writer.writeEndElement();
}
// ELEMENT: applicationException
final KeyedCollection<String, ApplicationException> applicationException = assemblyDescriptor.applicationException;
if (applicationException != null) {
for (final ApplicationException applicationExceptionItem : applicationException) {
if (applicationExceptionItem != null) {
writer.writeStartElement(prefix, "application-exception", "http://java.sun.com/xml/ns/javaee");
writeApplicationException(writer, applicationExceptionItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(assemblyDescriptor, "applicationException");
}
}
}
context.afterMarshal(assemblyDescriptor, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.ContainerTransaction$JAXB.readContainerTransaction in project tomee by apache.
the class InterfaceTransactionTest method module.
@Module
public EjbJar module() throws Exception {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
final Method remoteMethod = new Method("OrangeBean", "isInTransaction").withInterface(MethodIntf.REMOTE);
final Method localMethod = new Method("OrangeBean", "isInTransaction").withInterface(MethodIntf.LOCAL);
final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
transactions.add(new ContainerTransaction(TransAttribute.REQUIRED, remoteMethod));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, localMethod));
return ejbJar;
}
Aggregations