PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/TransactionIIOPInvocationTestCase.java

#
Java | 140 lines | 96 code | 20 blank | 24 comment | 1 complexity | 573aa5d4ac3b931d9a6169b505ecc909 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.test.iiop.transaction;
  23. import java.io.IOException;
  24. import java.util.Properties;
  25. import javax.naming.InitialContext;
  26. import javax.naming.NamingException;
  27. import javax.transaction.HeuristicMixedException;
  28. import javax.transaction.HeuristicRollbackException;
  29. import javax.transaction.NotSupportedException;
  30. import javax.transaction.RollbackException;
  31. import javax.transaction.SystemException;
  32. import org.jboss.arquillian.container.test.api.Deployment;
  33. import org.jboss.arquillian.container.test.api.OperateOnDeployment;
  34. import org.jboss.arquillian.container.test.api.TargetsContainer;
  35. import org.jboss.arquillian.junit.Arquillian;
  36. import org.jboss.as.network.NetworkUtils;
  37. import org.jboss.as.test.iiop.basic.BasicIIOPInvocationTestCase;
  38. import org.jboss.as.test.shared.FileUtils;
  39. import org.jboss.as.test.shared.PropertiesValueResolver;
  40. import org.jboss.shrinkwrap.api.Archive;
  41. import org.jboss.shrinkwrap.api.ShrinkWrap;
  42. import org.jboss.shrinkwrap.api.asset.StringAsset;
  43. import org.jboss.shrinkwrap.api.spec.JavaArchive;
  44. import org.junit.Test;
  45. import org.junit.runner.RunWith;
  46. /**
  47. * A simple IIOP invocation for one AS7 server to another
  48. */
  49. @RunWith(Arquillian.class)
  50. public class TransactionIIOPInvocationTestCase {
  51. @Deployment(name = "server", testable = false)
  52. @TargetsContainer("iiop-server")
  53. public static Archive<?> deployment() {
  54. final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "server.jar");
  55. jar.addClasses(IIOPTransactionalStatelessBean.class, IIOPTransactionalHome.class,
  56. IIOPTransactionalRemote.class, IIOPTransactionalStatefulHome.class,
  57. IIOPTransactionalStatefulRemote.class, IIOPTransactionalStatefulBean.class)
  58. .addAsManifestResource(TransactionIIOPInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
  59. return jar;
  60. }
  61. @Deployment(name = "client", testable = true)
  62. @TargetsContainer("iiop-client")
  63. public static Archive<?> clientDeployment() {
  64. String ejbJar = FileUtils.readFile(TransactionIIOPInvocationTestCase.class, "ejb-jar.xml");
  65. final Properties properties = new Properties();
  66. properties.putAll(System.getProperties());
  67. if(properties.containsKey("node1")) {
  68. properties.put("node1", NetworkUtils.formatPossibleIpv6Address((String) properties.get("node1")));
  69. }
  70. final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "client.jar");
  71. jar.addClasses(ClientEjb.class, IIOPTransactionalHome.class,
  72. IIOPTransactionalRemote.class, TransactionIIOPInvocationTestCase.class
  73. , IIOPTransactionalStatefulHome.class, IIOPTransactionalStatefulRemote.class)
  74. .addAsManifestResource(TransactionIIOPInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
  75. .addAsManifestResource(new StringAsset(PropertiesValueResolver.replaceProperties(ejbJar, properties)), "ejb-jar.xml");
  76. return jar;
  77. }
  78. @Test
  79. @OperateOnDeployment("client")
  80. public void testRemoteIIOPInvocation() throws IOException, NamingException, NotSupportedException, SystemException {
  81. final InitialContext context = new InitialContext();
  82. final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
  83. ejb.basicTransactionPropagationTest();
  84. }
  85. @Test
  86. @OperateOnDeployment("client")
  87. public void testRollbackOnly() throws IOException, NamingException, NotSupportedException, SystemException {
  88. final InitialContext context = new InitialContext();
  89. final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
  90. ejb.testRollbackOnly();
  91. }
  92. @Test
  93. @OperateOnDeployment("client")
  94. public void testRollbackOnlyBeforeCompletion() throws IOException, NamingException, NotSupportedException, SystemException, HeuristicMixedException, HeuristicRollbackException {
  95. final InitialContext context = new InitialContext();
  96. final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
  97. ejb.testRollbackOnlyBeforeCompletion();
  98. }
  99. @Test
  100. @OperateOnDeployment("client")
  101. public void testSameTransactionEachCall() throws IOException, NamingException, NotSupportedException, SystemException {
  102. final InitialContext context = new InitialContext();
  103. final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
  104. ejb.testSameTransactionEachCall();
  105. }
  106. @Test
  107. @OperateOnDeployment("client")
  108. public void testSynchronizationSuceeded() throws IOException, NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
  109. final InitialContext context = new InitialContext();
  110. final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
  111. ejb.testSynchronization(true);
  112. }
  113. @Test
  114. @OperateOnDeployment("client")
  115. public void testSynchronizationFailed() throws IOException, NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
  116. final InitialContext context = new InitialContext();
  117. final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
  118. ejb.testSynchronization(false);
  119. }
  120. }