[jboss-svn-commits] JBL Code SVN: r37776 - in labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss: narayana and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Dec 5 10:19:31 EST 2011


Author: paul.robinson
Date: 2011-12-05 10:19:29 -0500 (Mon, 05 Dec 2011)
New Revision: 37776

Added:
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/ATTest.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BACoordinatorCompletionTest.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BAParticipantCompletionTest.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BaseFunctionalTest.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/ATClient.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BACoordinatorCompletionClient.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BAParticipantCompletionClient.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/EventLog.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/ServiceCommand.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/SomeApplicationException.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/AT.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BACoordinatorCompletion.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BAParticipantCompletion.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/ATService.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BACoordinatorCompletionService.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BAParticipantCompletionService.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATDurable2PCParticipantTest.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATVolatile2PCParticipantTest.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBACoordinatorCompletionParticipantTest.java
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBAParticipantCompletionParticipantTest.java
Removed:
   labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/jbossts/
Log:
Package rename

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/ATTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/ATTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/ATTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,128 @@
+package org.jboss.narayana.txframework.functional;
+
+import com.arjuna.mw.wst11.UserTransaction;
+import com.arjuna.mw.wst11.UserTransactionFactory;
+import com.arjuna.wst.TransactionRolledBackException;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Commit;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Prepare;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Rollback;
+import org.jboss.narayana.txframework.functional.clients.ATClient;
+import org.jboss.narayana.txframework.functional.interfaces.AT;
+import org.junit.After;
+import org.junit.Assert;
+import org.jboss.arquillian.junit.Arquillian;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import javax.xml.ws.soap.SOAPFaultException;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+
+ at RunWith(Arquillian.class)
+public class ATTest extends BaseFunctionalTest
+{
+    private UserTransaction ut;
+    private AT client;
+
+    @Before
+    public void setupTest() throws Exception
+    {
+        ut = UserTransactionFactory.userTransaction();
+        client = ATClient.newInstance();
+    }
+
+    @After
+    public void teardownTest() throws Exception
+    {
+        client.clearEventLog();
+    }
+
+    @Test
+    public void testSimple() throws Exception
+    {
+        ut.begin();
+        client.invoke();
+        ut.commit();
+
+        assertOrder(Prepare.class, Commit.class);
+    }
+
+    @Test
+    public void testClientDrivenRollback() throws Exception
+    {
+        ut.begin();
+        client.invoke();
+        ut.rollback();
+
+        //todo: should rollback be called twice? once for volatile and once for durable
+        assertOrder(Rollback.class, Rollback.class);
+
+    }
+
+    @Test(expected = TransactionRolledBackException.class)
+    public void testParticipantDrivenRollback() throws Exception
+    {
+        try
+        {
+            ut.begin();
+            client.invoke(VOTE_ROLLBACK);
+            ut.commit();
+        }
+        catch (TransactionRolledBackException e)
+        {
+            //todo: should rollback be called twice? once for volatile and once for durable
+            assertOrder(Prepare.class, Rollback.class);
+            throw e;
+        }
+    }
+
+    @Test
+    public void testApplicationException() throws Exception
+    {
+        try
+        {
+            ut.begin();
+            client.invoke(THROW_APPLICATION_EXCEPTION);
+            Assert.fail("Exception should have been thrown by now");
+        }
+        catch (SOAPFaultException e)
+        {
+            //todo: can we pass application exceptions over SOAP when using an EJB exposed as a JAX-WS ws?
+            System.out.println("Caught exception");
+        }
+        finally
+        {
+            ut.rollback();
+        }
+        //todo: should this cause Rollback?
+        assertOrder(Rollback.class, Rollback.class);
+    }
+
+    private void assertOrder(Class<? extends Annotation>... expectedOrder)
+    {
+        Assert.assertEquals(Arrays.asList(expectedOrder), client.getEventLog().getLog());
+    }
+}
+
+//todo: support multi invocation
+/*@Test
+public void testManualCompleteMultiInvoke() throws Exception
+{
+    UserBusinessActivity uba = UserBusinessActivityFactory.userBusinessActivity();
+    BAParticipantCompletion client = BAParticipantCompletionClient.newInstance();
+
+    Assert.assertTrue(!client.contains("a"));
+    Assert.assertTrue(!client.contains("b"));
+
+    uba.begin();
+    client.saveDataManualComplete("a");
+    client.saveDataManualComplete("b", ServiceCommand.COMPLETE);
+    uba.close();
+
+    Assert.assertTrue(client.contains("a"));
+    Assert.assertTrue(client.contains("b"));
+
+    client.clearData();
+    Assert.assertTrue(!client.contains("a"));
+    Assert.assertTrue(!client.contains("b"));
+}*/

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BACoordinatorCompletionTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BACoordinatorCompletionTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BACoordinatorCompletionTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,95 @@
+package org.jboss.narayana.txframework.functional;
+
+import com.arjuna.mw.wst11.UserBusinessActivity;
+import com.arjuna.mw.wst11.UserBusinessActivityFactory;
+import com.arjuna.wst.TransactionRolledBackException;
+import junit.framework.Assert;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Cancel;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Close;
+import org.jboss.narayana.txframework.functional.clients.BACoordinatorCompletionClient;
+import org.jboss.narayana.txframework.functional.interfaces.BACoordinatorCompletion;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Complete;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.ConfirmCompleted;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import javax.xml.ws.soap.SOAPFaultException;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+
+ at RunWith(Arquillian.class)
+public class BACoordinatorCompletionTest extends BaseFunctionalTest
+{
+    UserBusinessActivity uba;
+    BACoordinatorCompletion client;
+
+    @Before
+    public void setupTest() throws Exception
+    {
+        uba = UserBusinessActivityFactory.userBusinessActivity();
+        client = BACoordinatorCompletionClient.newInstance();
+    }
+
+    @After
+    public void teardownTest() throws Exception
+    {
+        client.clearEventLog();
+    }
+
+    @Test
+    public void testSimple() throws Exception
+    {
+        uba.begin();
+        client.saveData();
+        uba.close();
+
+        assertOrder(Complete.class, ConfirmCompleted.class, Close.class);
+    }
+
+    @Test
+    public void testClientDrivenCancel() throws Exception
+    {
+        uba.begin();
+        client.saveData();
+        uba.cancel();
+
+        assertOrder(Cancel.class);
+    }
+
+    @Test
+    public void testApplicationException() throws Exception
+    {
+        try
+        {
+            uba.begin();
+            client.saveData(THROW_APPLICATION_EXCEPTION);
+            Assert.fail("Exception should have been thrown by now");
+        }
+        catch (SOAPFaultException e)
+        {
+            //todo: can we pass application exceptions over SOAP when using an EJB exposed as a JAX-WS ws?
+        }
+        finally
+        {
+            uba.cancel();
+        }
+        assertOrder();
+    }
+
+    @Test(expected = TransactionRolledBackException.class)
+    public void testCannotComplete() throws Exception
+    {
+        uba.begin();
+        client.saveData(CANNOT_COMPLETE);
+        uba.close();
+
+        assertOrder();
+    }
+
+    private void assertOrder(Class<? extends Annotation>... expectedOrder)
+    {
+        org.junit.Assert.assertEquals(Arrays.asList(expectedOrder), client.getEventLog().getLog());
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BAParticipantCompletionTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BAParticipantCompletionTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BAParticipantCompletionTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,130 @@
+package org.jboss.narayana.txframework.functional;
+
+import com.arjuna.mw.wst11.UserBusinessActivity;
+import com.arjuna.mw.wst11.UserBusinessActivityFactory;
+import com.arjuna.wst.TransactionRolledBackException;
+import junit.framework.Assert;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Close;
+import org.jboss.narayana.txframework.functional.clients.BAParticipantCompletionClient;
+import org.jboss.narayana.txframework.functional.common.ServiceCommand;
+import org.jboss.narayana.txframework.functional.interfaces.BAParticipantCompletion;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Compensate;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.ConfirmCompleted;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import javax.xml.ws.soap.SOAPFaultException;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+
+ at RunWith(Arquillian.class)
+public class BAParticipantCompletionTest extends BaseFunctionalTest
+{
+    UserBusinessActivity uba;
+    BAParticipantCompletion client;
+
+    @Before
+    public void setupTest() throws Exception
+    {
+        uba = UserBusinessActivityFactory.userBusinessActivity();
+        client = BAParticipantCompletionClient.newInstance();
+    }
+
+    @After
+    public void teardownTest() throws Exception
+    {
+        client.clearEventLog();
+    }
+
+    @Test
+    public void testAutoComplete() throws Exception
+    {
+        uba.begin();
+        client.saveDataAutoComplete();
+        uba.close();
+
+        assertOrder(ConfirmCompleted.class, Close.class);
+
+    }
+
+    @Test
+    public void testManualComplete() throws Exception
+    {
+        uba.begin();
+        client.saveDataManualComplete(ServiceCommand.COMPLETE);
+        uba.close();
+
+        assertOrder(ConfirmCompleted.class, Close.class);
+    }
+
+    //todo: support multi invocation
+    /*@Test
+    public void testManualCompleteMultiInvoke() throws Exception
+    {
+        UserBusinessActivity uba = UserBusinessActivityFactory.userBusinessActivity();
+        BAParticipantCompletion client = BAParticipantCompletionClient.newInstance();
+
+        Assert.assertTrue(!client.contains());
+        Assert.assertTrue(!client.contains("b"));
+
+        uba.begin();
+        client.saveDataManualComplete();
+        client.saveDataManualComplete("b", ServiceCommand.COMPLETE);
+        uba.close();
+
+        Assert.assertTrue(client.contains());
+        Assert.assertTrue(client.contains("b"));
+
+        client.clearData();
+        Assert.assertTrue(!client.contains());
+        Assert.assertTrue(!client.contains("b"));
+    }*/
+
+    @Test
+    public void testClientDrivenCompensate() throws Exception
+    {
+        uba.begin();
+        client.saveDataAutoComplete();
+        uba.cancel();
+
+        assertOrder(ConfirmCompleted.class, Compensate.class);
+    }
+
+    @Test
+    public void testApplicationException() throws Exception
+    {
+        try
+        {
+            uba.begin();
+            client.saveDataAutoComplete(ServiceCommand.THROW_APPLICATION_EXCEPTION);
+            Assert.fail("Exception should have been thrown by now");
+        }
+        catch (SOAPFaultException e)
+        {
+            //todo: can we pass application exceptions over SOAP when using an EJB exposed as a JAX-WS ws?
+            System.out.println("Caught exception");
+        }
+        finally
+        {
+            uba.cancel();
+        }
+        assertOrder();
+    }
+
+    @Test(expected = TransactionRolledBackException.class)
+    public void testCannotComplete() throws Exception
+    {
+        uba.begin();
+        client.saveDataAutoComplete(ServiceCommand.CANNOT_COMPLETE);
+        uba.close();
+        assertOrder();
+    }
+
+
+    private void assertOrder(Class<? extends Annotation>... expectedOrder)
+    {
+        org.junit.Assert.assertEquals(Arrays.asList(expectedOrder), client.getEventLog().getLog());
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BaseFunctionalTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BaseFunctionalTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/BaseFunctionalTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,30 @@
+package org.jboss.narayana.txframework.functional;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+public class BaseFunctionalTest
+{
+    @Deployment
+    public static JavaArchive createTestArchive()
+    {
+        //todo: Does the application developer have to specify the interceptor?
+        JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
+                .addPackages(true, "org.jboss.narayana.txframework")
+                .addAsResource("context-handlers.xml")
+                .addAsManifestResource(new ByteArrayAsset("<beans xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd\"><interceptors><class>ServiceRequestInterceptor</class></interceptors></beans>".getBytes()),
+                        ArchivePaths.create("beans.xml"));
+
+        archive.delete(ArchivePaths.create("META-INF/MANIFEST.MF"));
+
+        String ManifestMF = "Manifest-Version: 1.0\n"
+                + "Dependencies: org.jboss.xts,org.jboss.modules,deployment.arquillian-service,org.jboss.msc,org.jboss.jts\n";
+        archive.setManifest(new StringAsset(ManifestMF));
+
+        return archive;
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/ATClient.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/ATClient.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/ATClient.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,54 @@
+package org.jboss.narayana.txframework.functional.clients;
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+import com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor;
+import org.jboss.narayana.txframework.functional.interfaces.AT;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ATClient
+{
+    public static AT newInstance() throws Exception
+    {
+        URL wsdlLocation = new URL("http://localhost:8080/test/ATService/AT?wsdl");
+        QName serviceName = new QName("http://www.jboss.com/functional/at/", "ATService");
+        QName portName = new QName("http://www.jboss.com/functional/at/", "AT");
+
+        Service service = Service.create(wsdlLocation, serviceName);
+        AT client = service.getPort(portName, AT.class);
+
+        /*
+           Add client handler chain
+        */
+        BindingProvider bindingProvider = (BindingProvider) client;
+        List<Handler> handlers = new ArrayList<Handler>(1);
+        handlers.add(new JaxWSHeaderContextProcessor());
+        bindingProvider.getBinding().setHandlerChain(handlers);
+
+        return client;
+    }
+}
+

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BACoordinatorCompletionClient.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BACoordinatorCompletionClient.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BACoordinatorCompletionClient.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,54 @@
+package org.jboss.narayana.txframework.functional.clients;
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+import com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor;
+import org.jboss.narayana.txframework.functional.interfaces.BACoordinatorCompletion;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BACoordinatorCompletionClient
+{
+    public static BACoordinatorCompletion newInstance() throws Exception
+    {
+        URL wsdlLocation = new URL("http://localhost:8080/test/BACoordinatorCompletionService/BACoordinatorCompletion?wsdl");
+        QName serviceName = new QName("http://www.jboss.com/functional/ba/participantcompletion/", "BACoordinatorCompletionService");
+        QName portName = new QName("http://www.jboss.com/functional/ba/participantcompletion/", "BACoordinatorCompletionService");
+
+        Service service = Service.create(wsdlLocation, serviceName);
+        BACoordinatorCompletion client = service.getPort(portName, BACoordinatorCompletion.class);
+
+        /*
+           Add client handler chain
+        */
+        BindingProvider bindingProvider = (BindingProvider) client;
+        List<Handler> handlers = new ArrayList<Handler>(1);
+        handlers.add(new JaxWSHeaderContextProcessor());
+        bindingProvider.getBinding().setHandlerChain(handlers);
+
+        return client;
+    }
+}
+

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BAParticipantCompletionClient.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BAParticipantCompletionClient.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/clients/BAParticipantCompletionClient.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,54 @@
+package org.jboss.narayana.txframework.functional.clients;
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+import com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor;
+import org.jboss.narayana.txframework.functional.interfaces.BAParticipantCompletion;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BAParticipantCompletionClient
+{
+    public static BAParticipantCompletion newInstance() throws Exception
+    {
+        URL wsdlLocation = new URL("http://localhost:8080/test/BAParticipantCompletionService/BAParticipantCompletion?wsdl");
+        QName serviceName = new QName("http://www.jboss.com/functional/ba/participantcompletion/", "BAParticipantCompletionService");
+        QName portName = new QName("http://www.jboss.com/functional/ba/participantcompletion/", "BAParticipantCompletionService");
+
+        Service service = Service.create(wsdlLocation, serviceName);
+        BAParticipantCompletion client = service.getPort(portName, BAParticipantCompletion.class);
+
+        /*
+           Add client handler chain
+        */
+        BindingProvider bindingProvider = (BindingProvider) client;
+        List<Handler> handlers = new ArrayList<Handler>(1);
+        handlers.add(new JaxWSHeaderContextProcessor());
+        bindingProvider.getBinding().setHandlerChain(handlers);
+
+        return client;
+    }
+}
+

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/EventLog.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/EventLog.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/EventLog.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,25 @@
+package org.jboss.narayana.txframework.functional.common;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+public class EventLog
+{
+    private static volatile List<Class<? extends Annotation>> log = new ArrayList<Class<? extends Annotation>>();
+
+    public void add(Class<? extends Annotation> event)
+    {
+        log.add(event);
+    }
+
+    public List<Class<? extends Annotation>> getLog()
+    {
+        return log;
+    }
+
+    public void clear()
+    {
+        log.clear();
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/ServiceCommand.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/ServiceCommand.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/ServiceCommand.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,6 @@
+package org.jboss.narayana.txframework.functional.common;
+
+public enum ServiceCommand
+{
+    THROW_APPLICATION_EXCEPTION, CANNOT_COMPLETE, COMPLETE, READ_ONLY, VOTE_ROLLBACK
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/SomeApplicationException.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/SomeApplicationException.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/common/SomeApplicationException.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,17 @@
+package org.jboss.narayana.txframework.functional.common;
+
+import java.io.Serializable;
+
+public class SomeApplicationException extends Exception implements Serializable
+{
+    public SomeApplicationException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+
+    public SomeApplicationException(String message)
+    {
+        super(message);
+    }
+
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/AT.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/AT.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/AT.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,21 @@
+package org.jboss.narayana.txframework.functional.interfaces;
+
+import org.jboss.narayana.txframework.functional.common.SomeApplicationException;
+import org.jboss.narayana.txframework.functional.common.EventLog;
+import org.jboss.narayana.txframework.functional.common.ServiceCommand;
+import javax.ejb.Remote;
+import javax.jws.WebMethod;
+
+ at Remote
+public interface AT
+{
+    @WebMethod
+    public void invoke(ServiceCommand... serviceCommands) throws SomeApplicationException;
+
+    @WebMethod
+    public EventLog getEventLog();
+
+    @WebMethod
+    public void clearEventLog();
+
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BACoordinatorCompletion.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BACoordinatorCompletion.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BACoordinatorCompletion.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,21 @@
+package org.jboss.narayana.txframework.functional.interfaces;
+
+import org.jboss.narayana.txframework.functional.common.EventLog;
+import org.jboss.narayana.txframework.functional.common.ServiceCommand;
+import org.jboss.narayana.txframework.functional.common.SomeApplicationException;
+import javax.ejb.Remote;
+import javax.jws.WebMethod;
+
+ at Remote
+public interface BACoordinatorCompletion
+{
+    @WebMethod
+    public void saveData(ServiceCommand... serviceCommands) throws SomeApplicationException;
+
+    @WebMethod
+    public EventLog getEventLog();
+
+    @WebMethod
+    public void clearEventLog();
+
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BAParticipantCompletion.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BAParticipantCompletion.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/interfaces/BAParticipantCompletion.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,24 @@
+package org.jboss.narayana.txframework.functional.interfaces;
+
+import org.jboss.narayana.txframework.functional.common.EventLog;
+import org.jboss.narayana.txframework.functional.common.ServiceCommand;
+import org.jboss.narayana.txframework.functional.common.SomeApplicationException;
+import javax.ejb.Remote;
+import javax.jws.WebMethod;
+
+ at Remote
+public interface BAParticipantCompletion
+{
+    @WebMethod
+    public void saveDataAutoComplete(ServiceCommand... serviceCommands) throws SomeApplicationException;
+
+    @WebMethod
+    public void saveDataManualComplete(ServiceCommand... serviceCommands) throws SomeApplicationException;
+
+    @WebMethod
+    public EventLog getEventLog();
+
+    @WebMethod
+    public void clearEventLog();
+
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/ATService.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/ATService.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/ATService.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.narayana.txframework.functional.services;
+
+import com.arjuna.wst.*;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Error;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.*;
+import org.jboss.narayana.txframework.api.annotation.management.TxManagement;
+import org.jboss.narayana.txframework.api.annotation.service.ServiceRequest;
+import org.jboss.narayana.txframework.api.annotation.transaction.WSAT;
+import org.jboss.narayana.txframework.api.management.ATTxControl;
+import org.jboss.narayana.txframework.functional.common.SomeApplicationException;
+import org.jboss.narayana.txframework.functional.common.EventLog;
+import org.jboss.narayana.txframework.functional.common.ServiceCommand;
+import org.jboss.narayana.txframework.functional.interfaces.AT;
+import org.jboss.narayana.txframework.impl.TXControlException;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.jws.HandlerChain;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+/**
+ * @author Paul Robinson (paul.robinson at redhat.com)
+ */
+ at Remote(AT.class)
+ at WSAT
+ at Stateless
+ at WebService(serviceName = "ATService", portName = "AT",
+        name = "AT", targetNamespace = "http://www.jboss.com/functional/at/")
+//todo: Can the framework specify the handlerchain if not isPresent? Would have to be added earlier in the chain than we currently intercept
+ at HandlerChain(file = "/context-handlers.xml", name = "Context Handlers")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+public class ATService implements AT
+{
+    @TxManagement
+    public ATTxControl txControl;
+    private boolean rollback = false;
+    private EventLog eventLog = new EventLog();
+
+    @WebMethod
+    @ServiceRequest
+    public void invoke(ServiceCommand[] serviceCommands) throws SomeApplicationException
+    {
+        try
+        {
+            if (isPresent(ServiceCommand.THROW_APPLICATION_EXCEPTION, serviceCommands))
+            {
+                throw new SomeApplicationException("Intentionally thrown Exception");
+            }
+
+            if (isPresent(ServiceCommand.READ_ONLY, serviceCommands))
+            {
+                //todo: is this right?
+                txControl.readOnly();
+            }
+
+            if (isPresent(ServiceCommand.VOTE_ROLLBACK, serviceCommands))
+            {
+                rollback = true;
+            }
+        }
+        catch (TXControlException e)
+        {
+            throw new RuntimeException("Error invoking lifecycle methods on the TXControl", e);
+        }
+    }
+
+    @WebMethod
+    public EventLog getEventLog()
+    {
+        return eventLog;
+    }
+
+    @WebMethod
+    public void clearEventLog()
+    {
+        eventLog.clear();
+    }
+
+    @Commit
+    @WebMethod(exclude = true)
+    public void commit()
+    {
+        eventLog.add(Commit.class);
+    }
+
+    @Rollback
+    @WebMethod(exclude = true)
+    public void rollback()
+    {
+        eventLog.add(Rollback.class);
+    }
+
+    @Prepare
+    @WebMethod(exclude = true)
+    public Vote prepare()
+    {
+        eventLog.add(Prepare.class);
+        if (rollback)
+        {
+            return new Aborted();
+        }
+        else
+        {
+            return new Prepared();
+        }
+    }
+
+    @Unknown
+    @WebMethod(exclude = true)
+    public void unknown() throws SystemException
+    {
+        eventLog.add(Unknown.class);
+    }
+
+    @Error
+    @WebMethod(exclude = true)
+    public void error() throws SystemException
+    {
+        eventLog.add(org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Error.class);
+    }
+
+    private boolean isPresent(ServiceCommand expectedServiceCommand, ServiceCommand... serviceCommands)
+    {
+        for (ServiceCommand foundServiceCommand : serviceCommands)
+        {
+            if (foundServiceCommand == expectedServiceCommand)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BACoordinatorCompletionService.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BACoordinatorCompletionService.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BACoordinatorCompletionService.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,176 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.narayana.txframework.functional.services;
+
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.*;
+import org.jboss.narayana.txframework.api.annotation.management.TxManagement;
+import org.jboss.narayana.txframework.api.annotation.service.ServiceRequest;
+import org.jboss.narayana.txframework.api.annotation.transaction.WSBA;
+import org.jboss.narayana.txframework.api.configuration.transaction.CompletionType;
+import org.jboss.narayana.txframework.api.management.WSBATxControl;
+import org.jboss.narayana.txframework.functional.common.SomeApplicationException;
+import org.jboss.narayana.txframework.functional.interfaces.BACoordinatorCompletion;
+import org.jboss.narayana.txframework.functional.common.EventLog;
+import org.jboss.narayana.txframework.functional.common.ServiceCommand;
+import org.jboss.narayana.txframework.impl.TXControlException;
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.jws.HandlerChain;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+/**
+ * @author Paul Robinson (paul.robinson at redhat.com)
+ */
+ at Stateless
+ at WebService(serviceName = "BACoordinatorCompletionService", portName = "BACoordinatorCompletionService",
+        name = "BACoordinatorCompletion", targetNamespace = "http://www.jboss.com/functional/ba/participantcompletion/")
+//todo: Can the framework specify the handlerchain if not isPresent? Would have to be added earlier in the chain than we currently intercept
+ at HandlerChain(file = "/context-handlers.xml", name = "Context Handlers")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+ at WSBA(completionType = CompletionType.COORDINATOR)
+public class BACoordinatorCompletionService implements BACoordinatorCompletion
+{
+    @TxManagement
+    public WSBATxControl txControl;
+    @Inject
+    private EventLog eventLog = new EventLog();
+
+    @WebMethod
+    @ServiceRequest
+    //todo: batch up data and only add during confirmCompleted
+    public void saveData(ServiceCommand[] serviceCommands) throws SomeApplicationException
+    {
+        try
+        {
+            if (isPresent(ServiceCommand.THROW_APPLICATION_EXCEPTION, serviceCommands))
+            {
+                throw new SomeApplicationException("Intentionally thrown Exception");
+            }
+
+            if (isPresent(ServiceCommand.CANNOT_COMPLETE, serviceCommands))
+            {
+                txControl.cannotComplete();
+                return;
+            }
+
+            if (isPresent(ServiceCommand.COMPLETE, serviceCommands))
+            {
+                txControl.completed();
+            }
+        }
+        catch (TXControlException e)
+        {
+            throw new RuntimeException("Error invoking lifecycle methods on the TXControl", e);
+        }
+    }
+
+    @WebMethod
+    public EventLog getEventLog()
+    {
+        return eventLog;
+    }
+
+    @WebMethod
+    public void clearEventLog()
+    {
+        eventLog.clear();
+    }
+
+    //todo: why is this never invoked? Always true for CoordinationCompletion?
+    @Compensate
+    @WebMethod(exclude = true)
+    public void compensate()
+    {
+        eventLog.add(Compensate.class);
+    }
+
+    @ConfirmCompleted
+    @WebMethod(exclude = true)
+    public void confirmCompleted(Boolean success)
+    {
+        eventLog.add(ConfirmCompleted.class);
+    }
+
+    @Cancel
+    @WebMethod(exclude = true)
+    public void cancel()
+    {
+        eventLog.add(Cancel.class);
+    }
+
+    @Close
+    @WebMethod(exclude = true)
+    public void close()
+    {
+        eventLog.add(Close.class);
+    }
+
+    @Complete
+    @WebMethod(exclude = true)
+    public void complete()
+    {
+        eventLog.add(Complete.class);
+    }
+
+    @ConfirmCompleted
+    @WebMethod(exclude = true)
+    public void confirmCompleted(boolean success)
+    {
+        eventLog.add(ConfirmCompleted.class);
+    }
+
+    @Error
+    @WebMethod(exclude = true)
+    public void error()
+    {
+        eventLog.add(org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error.class);
+    }
+
+    @Status
+    @WebMethod(exclude = true)
+    public String status()
+    {
+        eventLog.add(Status.class);
+        return null;
+    }
+
+    @Unknown
+    @WebMethod(exclude = true)
+    public void unknown()
+    {
+        eventLog.add(Unknown.class);
+    }
+
+    private boolean isPresent(ServiceCommand expectedServiceCommand, ServiceCommand... serviceCommands)
+    {
+        for (ServiceCommand foundServiceCommand : serviceCommands)
+        {
+            if (foundServiceCommand == expectedServiceCommand)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BAParticipantCompletionService.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BAParticipantCompletionService.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/functional/services/BAParticipantCompletionService.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. 
+ * See the copyright.txt in the distribution for a full listing 
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.narayana.txframework.functional.services;
+
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.*;
+import org.jboss.narayana.txframework.api.annotation.management.TxManagement;
+import org.jboss.narayana.txframework.api.annotation.service.ServiceRequest;
+import org.jboss.narayana.txframework.api.annotation.transaction.WSBA;
+import org.jboss.narayana.txframework.api.configuration.transaction.CompletionType;
+import org.jboss.narayana.txframework.api.management.WSBATxControl;
+import org.jboss.narayana.txframework.functional.common.SomeApplicationException;
+import org.jboss.narayana.txframework.functional.interfaces.BAParticipantCompletion;
+import org.jboss.narayana.txframework.functional.common.EventLog;
+import org.jboss.narayana.txframework.functional.common.ServiceCommand;
+import org.jboss.narayana.txframework.impl.TXControlException;
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.jws.HandlerChain;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+/**
+ * @author Paul Robinson (paul.robinson at redhat.com)
+ */
+ at Stateless
+ at WebService(serviceName = "BAParticipantCompletionService", portName = "BAParticipantCompletionService",
+        name = "BAParticipantCompletion", targetNamespace = "http://www.jboss.com/functional/ba/participantcompletion/")
+//todo: Can the framework specify the handlerchain if not present? Would have to be added earlier in the chain than we currently intercept
+ at HandlerChain(file = "/context-handlers.xml", name = "Context Handlers")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+ at WSBA(completionType = CompletionType.PARTICIPANT)
+public class BAParticipantCompletionService implements BAParticipantCompletion
+{
+    @TxManagement
+    public WSBATxControl txControl;
+    @Inject
+    private EventLog eventLog = new EventLog();
+
+    @WebMethod
+    @ServiceRequest
+    @Completes
+    public void saveDataAutoComplete(ServiceCommand... serviceCommands) throws SomeApplicationException
+    {
+        saveData(serviceCommands);
+    }
+
+    @WebMethod
+    @ServiceRequest
+    public void saveDataManualComplete(ServiceCommand... serviceCommands) throws SomeApplicationException
+    {
+        saveData(serviceCommands);
+    }
+
+    private void saveData(ServiceCommand[] serviceCommands) throws SomeApplicationException
+    {
+        try
+        {
+            if (present(THROW_APPLICATION_EXCEPTION, serviceCommands))
+            {
+                throw new SomeApplicationException("Intentionally thrown Exception");
+            }
+
+            if (present(CANNOT_COMPLETE, serviceCommands))
+            {
+                txControl.cannotComplete();
+                return;
+            }
+
+            if (present(COMPLETE, serviceCommands))
+            {
+                txControl.completed();
+            }
+        }
+        catch (TXControlException e)
+        {
+            throw new RuntimeException("Error invoking lifecycle methods on the TXControl", e);
+        }
+    }
+
+    @WebMethod
+    public EventLog getEventLog()
+    {
+        return eventLog;
+    }
+
+    @WebMethod
+    public void clearEventLog()
+    {
+        eventLog.clear();
+    }
+
+    @Compensate
+    @WebMethod(exclude = true)
+    public void compensate()
+    {
+        eventLog.add(Compensate.class);
+    }
+
+    @ConfirmCompleted
+    @WebMethod(exclude = true)
+    public void confirmCompleted(Boolean success)
+    {
+        eventLog.add(ConfirmCompleted.class);
+    }
+
+    @Cancel
+    @WebMethod(exclude = true)
+    public void cancel()
+    {
+        eventLog.add(Cancel.class);
+    }
+
+    @Close
+    @WebMethod(exclude = true)
+    public void close()
+    {
+        eventLog.add(Close.class);
+    }
+
+    @ConfirmCompleted
+    @WebMethod(exclude = true)
+    public void confirmCompleted(boolean success)
+    {
+        eventLog.add(ConfirmCompleted.class);
+    }
+
+    @Error
+    @WebMethod(exclude = true)
+    public void error()
+    {
+        eventLog.add(org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error.class);
+    }
+
+    @Status
+    @WebMethod(exclude = true)
+    public String status()
+    {
+        eventLog.add(Status.class);
+        return null;
+    }
+
+    @Unknown
+    @WebMethod(exclude = true)
+    public void unknown()
+    {
+        eventLog.add(Unknown.class);
+    }
+
+    private boolean present(ServiceCommand expectedServiceCommand, ServiceCommand... serviceCommands)
+    {
+        for (ServiceCommand foundServiceCommand : serviceCommands)
+        {
+            if (foundServiceCommand == expectedServiceCommand)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATDurable2PCParticipantTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATDurable2PCParticipantTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATDurable2PCParticipantTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,82 @@
+package org.jboss.narayana.txframework.impl.handlers.wsat;
+
+import com.arjuna.wst.Durable2PCParticipant;
+import com.arjuna.wst.SystemException;
+import com.arjuna.wst.Vote;
+import com.arjuna.wst.WrongStateException;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Commit;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Error;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Rollback;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Unknown;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Prepare;
+import org.jboss.narayana.txframework.impl.handlers.wsat.WSATDurable2PCParticipant;
+import org.junit.Test;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class WSATDurable2PCParticipantTest
+{
+    @Test
+    public void testCallbacks() throws Exception
+    {
+        LifecycleImpl lifecycle = new LifecycleImpl();
+        WSATDurable2PCParticipant participant = new WSATDurable2PCParticipant(lifecycle);
+
+        participant.prepare();
+        participant.commit();
+        participant.rollback();
+        participant.unknown();
+        participant.error();
+
+        List<Class<? extends Annotation>> actualOrder = lifecycle.getExecutionOrder();
+        assertOrder(actualOrder, Prepare.class, Commit.class, Rollback.class, Unknown.class, Error.class);
+    }
+
+    public class LifecycleImpl implements Durable2PCParticipant
+    {
+        private List<Class<? extends Annotation>> executionOrder = new ArrayList<Class<? extends Annotation>>();
+
+        @Prepare
+        public Vote prepare() throws WrongStateException, SystemException
+        {
+            executionOrder.add(Prepare.class);
+            //todo: return a vote
+            return null;
+        }
+
+        @Commit
+        public void commit() throws WrongStateException, SystemException
+        {
+            executionOrder.add(Commit.class);
+        }
+
+        @Rollback
+        public void rollback() throws WrongStateException, SystemException
+        {
+            executionOrder.add(Rollback.class);
+        }
+
+        @Unknown
+        public void unknown() throws SystemException
+        {
+            executionOrder.add(Unknown.class);
+        }
+
+        @Error
+        public void error() throws SystemException
+        {
+            executionOrder.add(Error.class);
+        }
+
+        public List<Class<? extends Annotation>> getExecutionOrder()
+        {
+            return executionOrder;
+        }
+    }
+    private void assertOrder( List<Class<? extends Annotation>> actualOrder, Class<? extends Annotation>... expectedOrder)
+    {
+        org.junit.Assert.assertEquals(Arrays.asList(expectedOrder), actualOrder);
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATVolatile2PCParticipantTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATVolatile2PCParticipantTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsat/WSATVolatile2PCParticipantTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,77 @@
+package org.jboss.narayana.txframework.impl.handlers.wsat;
+
+import com.arjuna.wst.*;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.Error;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsat.*;
+import org.jboss.narayana.txframework.impl.handlers.wsat.WSATDurable2PCParticipant;
+import org.junit.Test;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class WSATVolatile2PCParticipantTest
+{
+    @Test
+    public void testCallbacks() throws Exception
+    {
+        LifecycleImpl lifecycle = new LifecycleImpl();
+        WSATDurable2PCParticipant participant = new WSATDurable2PCParticipant(lifecycle);
+
+        participant.prepare();
+        participant.commit();
+        participant.rollback();
+        participant.unknown();
+        participant.error();
+
+        List<Class<? extends Annotation>> actualOrder = lifecycle.getExecutionOrder();
+        assertOrder(actualOrder, PrePrepare.class, PostCommit.class, Rollback.class, Unknown.class, Error.class);
+    }
+
+    private void assertOrder(List<Class<? extends Annotation>> actualOrder, Class<? extends Annotation>... expectedOrder)
+    {
+        org.junit.Assert.assertEquals(Arrays.asList(expectedOrder), actualOrder);
+    }
+
+    public class LifecycleImpl implements Volatile2PCParticipant
+    {
+        private List<Class<? extends Annotation>> executionOrder = new ArrayList<Class<? extends Annotation>>();
+
+        @Prepare
+        public Vote prepare() throws WrongStateException, SystemException
+        {
+            executionOrder.add(PrePrepare.class);
+            //todo: return a vote
+            return null;
+        }
+
+        @Commit
+        public void commit() throws WrongStateException, SystemException
+        {
+            executionOrder.add(PostCommit.class);
+        }
+
+        @Rollback
+        public void rollback() throws WrongStateException, SystemException
+        {
+            executionOrder.add(Rollback.class);
+        }
+
+        @Unknown
+        public void unknown() throws SystemException
+        {
+            executionOrder.add(Unknown.class);
+        }
+
+        @Error
+        public void error() throws SystemException
+        {
+            executionOrder.add(Error.class);
+        }
+
+        public List<Class<? extends Annotation>> getExecutionOrder()
+        {
+            return executionOrder;
+        }
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBACoordinatorCompletionParticipantTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBACoordinatorCompletionParticipantTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBACoordinatorCompletionParticipantTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,98 @@
+package org.jboss.narayana.txframework.impl.handlers.wsba;
+
+import com.arjuna.wst.BusinessAgreementWithCoordinatorCompletionParticipant;
+import com.arjuna.wst11.ConfirmCompletedParticipant;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.*;
+import org.jboss.narayana.txframework.impl.handlers.wsba.WSBACoordinatorCompletionParticipant;
+import org.junit.Test;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class WSBACoordinatorCompletionParticipantTest
+{
+    @Test
+    public void testCallbacks() throws Exception
+    {
+        LifecycleImpl lifecycle = new LifecycleImpl();
+        WSBACoordinatorCompletionParticipant participant = new WSBACoordinatorCompletionParticipant(lifecycle);
+
+        participant.cancel();
+        participant.close();
+        participant.compensate();
+        participant.complete();
+        participant.confirmCompleted(true);
+        participant.error();
+        participant.status();
+        participant.unknown();
+
+        List<Class<? extends Annotation>> actualOrder = lifecycle.getExecutionOrder();
+        assertOrder(actualOrder, Cancel.class, Close.class, Compensate.class, Complete.class, ConfirmCompleted.class, Error.class, Status.class, Unknown.class);
+    }
+
+    private void assertOrder(List<Class<? extends Annotation>> actualOrder, Class<? extends Annotation>... expectedOrder)
+    {
+        org.junit.Assert.assertEquals(Arrays.asList(expectedOrder), actualOrder);
+    }
+
+    public class LifecycleImpl implements BusinessAgreementWithCoordinatorCompletionParticipant, ConfirmCompletedParticipant
+    {
+        private List<Class<? extends Annotation>> executionOrder = new ArrayList<Class<? extends Annotation>>();
+
+        @Cancel
+        public void cancel()
+        {
+            executionOrder.add(Cancel.class);
+        }
+
+        @Close
+        public void close()
+        {
+            executionOrder.add(Close.class);
+        }
+
+        @Compensate
+        public void compensate()
+        {
+            executionOrder.add(Compensate.class);
+        }
+
+        @Complete
+        public void complete()
+        {
+            executionOrder.add(Complete.class);
+        }
+
+        @ConfirmCompleted
+        public void confirmCompleted(boolean success)
+        {
+            executionOrder.add(ConfirmCompleted.class);
+        }
+
+        @Error
+        public void error()
+        {
+            executionOrder.add(org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error.class);
+        }
+
+        @Status
+        public String status()
+        {
+            executionOrder.add(Status.class);
+            return null;
+        }
+
+        @Unknown
+        public void unknown()
+        {
+            executionOrder.add(Unknown.class);
+        }
+
+        public List<Class<? extends Annotation>> getExecutionOrder()
+        {
+            return executionOrder;
+        }
+    }
+}

Added: labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBAParticipantCompletionParticipantTest.java
===================================================================
--- labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBAParticipantCompletionParticipantTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/txframework/framework/src/test/java/org/jboss/narayana/txframework/impl/handlers/wsba/WSBAParticipantCompletionParticipantTest.java	2011-12-05 15:19:29 UTC (rev 37776)
@@ -0,0 +1,101 @@
+package org.jboss.narayana.txframework.impl.handlers.wsba;
+
+import com.arjuna.wst.BusinessAgreementWithParticipantCompletionParticipant;
+import com.arjuna.wst11.ConfirmCompletedParticipant;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error;
+import org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.*;
+import org.jboss.narayana.txframework.impl.handlers.wsba.WSBAParticipantCompletionParticipant;
+import org.junit.Test;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class WSBAParticipantCompletionParticipantTest
+{
+    @Test
+    public void testCallbacks() throws Exception
+    {
+        LifecycleImpl lifecycle = new LifecycleImpl();
+        WSBAParticipantCompletionParticipant participant = new WSBAParticipantCompletionParticipant(lifecycle);
+
+        participant.cancel();
+        participant.close();
+        participant.compensate();
+        participant.confirmCompleted(true);
+        participant.error();
+        participant.status();
+        participant.unknown();
+
+        List<Class<? extends Annotation>> expectedOrder = new ArrayList<Class<? extends Annotation>>();
+        expectedOrder.add(Cancel.class);
+        expectedOrder.add(Close.class);
+        expectedOrder.add(Compensate.class);
+        expectedOrder.add(ConfirmCompleted.class);
+        expectedOrder.add(Error.class);
+        expectedOrder.add(Status.class);
+        expectedOrder.add(Unknown.class);
+
+        List<Class<? extends Annotation>> actualOrder = lifecycle.getExecutionOrder();
+        assertOrder(actualOrder, Cancel.class, Close.class, Compensate.class, ConfirmCompleted.class, Error.class, Status.class, Unknown.class);
+    }
+
+    private void assertOrder(List<Class<? extends Annotation>> actualOrder, Class<? extends Annotation>... expectedOrder)
+    {
+        org.junit.Assert.assertEquals(Arrays.asList(expectedOrder), actualOrder);
+    }
+
+    public class LifecycleImpl implements BusinessAgreementWithParticipantCompletionParticipant, ConfirmCompletedParticipant
+    {
+        private List<Class<? extends Annotation>> executionOrder = new ArrayList<Class<? extends Annotation>>();
+
+        @Cancel
+        public void cancel()
+        {
+            executionOrder.add(Cancel.class);
+        }
+
+        @Close
+        public void close()
+        {
+            executionOrder.add(Close.class);
+        }
+
+        @Compensate
+        public void compensate()
+        {
+            executionOrder.add(Compensate.class);
+        }
+
+        @ConfirmCompleted
+        public void confirmCompleted(boolean success)
+        {
+            executionOrder.add(ConfirmCompleted.class);
+        }
+
+        @Error
+        public void error()
+        {
+            executionOrder.add(org.jboss.narayana.txframework.api.annotation.lifecycle.wsba.Error.class);
+        }
+
+
+        @Status
+        public String status()
+        {
+            executionOrder.add(Status.class);
+            return null;
+        }
+
+        @Unknown
+        public void unknown()
+        {
+            executionOrder.add(Unknown.class);
+        }
+
+        public List<Class<? extends Annotation>> getExecutionOrder()
+        {
+            return executionOrder;
+        }
+    }
+}



More information about the jboss-svn-commits mailing list