You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2015/07/08 12:49:22 UTC
svn commit: r1689837 [1/2] - in /aries/trunk/transaction:
transaction-blueprint/
transaction-blueprint/src/test/java/org/apache/aries/transaction/
transaction-itests/
transaction-itests/src/test/java/org/apache/aries/transaction/itests/
transaction-tes...
Author: cschneider
Date: Wed Jul 8 10:49:21 2015
New Revision: 1689837
URL: http://svn.apache.org/r1689837
Log:
[ARIES-628] Avoid using testsupport in tests. Improve test speed
Added:
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerRegistry.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerSet.java
Removed:
aries/trunk/transaction/transaction-itests/derby.log
Modified:
aries/trunk/transaction/transaction-blueprint/pom.xml
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationParserTest.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BaseNameSpaceHandlerSetup.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java
aries/trunk/transaction/transaction-itests/pom.xml
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
aries/trunk/transaction/transaction-testbundle/pom.xml
aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/AnnotatedTestBeanImpl.java
aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/JtaAnnotatedTestBeanImpl.java
Modified: aries/trunk/transaction/transaction-blueprint/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/pom.xml?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/pom.xml (original)
+++ aries/trunk/transaction/transaction-blueprint/pom.xml Wed Jul 8 10:49:21 2015
@@ -71,17 +71,18 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.aries.testsupport</groupId>
- <artifactId>org.apache.aries.testsupport.unit</artifactId>
- <scope>test</scope>
- <version>1.0.0</version>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>javax.transaction-api</artifactId>
+ <version>1.2</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<scope>test</scope>
@@ -97,10 +98,10 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>javax.transaction</groupId>
- <artifactId>javax.transaction-api</artifactId>
- <version>1.2</version>
- <scope>provided</scope>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>3.3.1</version>
+ <scope>test</scope>
</dependency>
</dependencies>
<build>
Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java Wed Jul 8 10:49:21 2015
@@ -24,15 +24,9 @@ import static org.junit.Assert.assertNul
import org.apache.aries.blueprint.ComponentDefinitionRegistry;
import org.apache.aries.blueprint.PassThroughMetadata;
-import org.apache.aries.blueprint.container.BeanRecipe;
-import org.apache.aries.blueprint.container.BlueprintContainerImpl;
-import org.apache.aries.transaction.annotations.TransactionPropagationType;
-import org.apache.aries.transaction.parsing.AnnotationParser;
import org.apache.aries.transaction.parsing.TxNamespaceHandler;
-import org.apache.aries.transaction.pojo.AnnotatedPojo;
import org.junit.Test;
import org.osgi.service.blueprint.reflect.BeanMetadata;
-import org.osgi.service.blueprint.reflect.Metadata;
public class AnnotationEnablingNameSpaceHandlerTest extends BaseNameSpaceHandlerSetup {
@@ -40,16 +34,9 @@ public class AnnotationEnablingNameSpace
public void testAnnotationEnabled() throws Exception
{
ComponentDefinitionRegistry cdr = parseCDR("enable-annotations.xml");
-
- BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top");
-
- assertNotNull(compTop);
- assertEquals(0, cdr.getInterceptors(compTop).size());
- assertNull(txenhancer.getComponentMethodTxAttribute(compTop, "increment"));
-
+ checkCompTop(cdr);
BeanMetadata pmd = (BeanMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
assertNotNull(pmd);
-
assertEquals(3, pmd.getArguments().size());
assertEquals(cdr, ((PassThroughMetadata)pmd.getArguments().get(0).getValue()).getObject());
assertEquals(txenhancer, ((PassThroughMetadata) pmd.getArguments().get(2).getValue()).getObject());
@@ -59,15 +46,15 @@ public class AnnotationEnablingNameSpace
public void testAnnotationDisabled() throws Exception
{
ComponentDefinitionRegistry cdr = parseCDR("enable-annotations2.xml");
-
+ checkCompTop(cdr);
+ BeanMetadata pmd = (BeanMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
+ assertNull(pmd);
+ }
+
+ private void checkCompTop(ComponentDefinitionRegistry cdr) {
BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top");
-
assertNotNull(compTop);
assertEquals(0, cdr.getInterceptors(compTop).size());
assertNull(txenhancer.getComponentMethodTxAttribute(compTop, "increment"));
-
-
- BeanMetadata pmd = (BeanMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
- assertNull(pmd);
}
}
Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationParserTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationParserTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationParserTest.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationParserTest.java Wed Jul 8 10:49:21 2015
@@ -21,116 +21,111 @@ package org.apache.aries.transaction;
import static org.apache.aries.transaction.annotations.TransactionPropagationType.Mandatory;
import static org.apache.aries.transaction.annotations.TransactionPropagationType.Required;
import static org.apache.aries.transaction.annotations.TransactionPropagationType.Supports;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import java.util.ArrayList;
import java.util.Arrays;
import org.apache.aries.blueprint.ComponentDefinitionRegistry;
import org.apache.aries.blueprint.Interceptor;
import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
import org.apache.aries.blueprint.reflect.BeanMetadataImpl;
-import org.apache.aries.transaction.TxComponentMetaDataHelper;
import org.apache.aries.transaction.annotations.TransactionPropagationType;
import org.apache.aries.transaction.parsing.AnnotationParser;
import org.apache.aries.transaction.pojo.AnnotatedPojo;
import org.apache.aries.transaction.pojo.BadlyAnnotatedPojo1;
import org.apache.aries.transaction.pojo.BadlyAnnotatedPojo2;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.MethodCallHandler;
-import org.apache.aries.unittest.mocks.Skeleton;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;
import org.osgi.service.blueprint.reflect.ComponentMetadata;
public class AnnotationParserTest {
- private TxComponentMetaDataHelper helper;
- private ComponentDefinitionRegistry cdr;
- private Interceptor i;
- private AnnotationParser parser;
-
- @Before
- public void setup() {
- helper = Skeleton.newMock(TxComponentMetaDataHelper.class);
- Skeleton.getSkeleton(helper).setReturnValue(new MethodCall(TxComponentMetaDataHelper.class,
- "getComponentMethodTxAttribute", ComponentMetadata.class, String.class), null);
- cdr = Skeleton.newMock(ComponentDefinitionRegistry.class);
- i = Skeleton.newMock(Interceptor.class);
- parser = new AnnotationParser(cdr, i, helper);
- }
-
- @Test
- public void testFindAnnotation() {
- MutableBeanMetadata mbm = new BeanMetadataImpl();
- mbm.setId("testPojo");
- mbm.setClassName(AnnotatedPojo.class.getName());
- parser.beforeInit(new AnnotatedPojo(), "testPojo", null, mbm);
-
- Skeleton.getSkeleton(helper).assertCalledExactNumberOfTimes(new MethodCall(TxComponentMetaDataHelper.class,
- "getComponentMethodTxAttribute", mbm, String.class), 3);
-
- Skeleton.getSkeleton(helper).assertCalledExactNumberOfTimes(new MethodCall(TxComponentMetaDataHelper.class,
- "setComponentTransactionData", cdr, mbm, Required, "increment"), 1);
- Skeleton.getSkeleton(helper).assertCalledExactNumberOfTimes(new MethodCall(TxComponentMetaDataHelper.class,
- "setComponentTransactionData", cdr, mbm, Supports, "checkValue"), 1);
- Skeleton.getSkeleton(helper).assertCalledExactNumberOfTimes(new MethodCall(TxComponentMetaDataHelper.class,
- "setComponentTransactionData", cdr, mbm, Mandatory, "getRealObject"), 1);
-
- Skeleton.getSkeleton(cdr).assertCalledExactNumberOfTimes(new MethodCall(ComponentDefinitionRegistry.class,
- "registerInterceptorWithComponent", mbm, i), 1);
- }
-
- @Test
- public void testAnnotationsOverridenByXML() {
-
- MutableBeanMetadata mbm = new BeanMetadataImpl();
- mbm.setId("testPojo");
- mbm.setClassName(AnnotatedPojo.class.getName());
-
- Skeleton.getSkeleton(helper).registerMethodCallHandler(new MethodCall(TxComponentMetaDataHelper.class,
- "getComponentMethodTxAttribute", ComponentMetadata.class, String.class), new MethodCallHandler() {
-
- public Object handle(MethodCall arg0, Skeleton arg1) throws Exception {
- if(arg0.getArguments()[1].equals("increment"))
- return TransactionPropagationType.Never;
-
- return null;
- }
- });
-
- Skeleton.getSkeleton(cdr).setReturnValue(new MethodCall(ComponentDefinitionRegistry.class,
- "getInterceptors", mbm), Arrays.asList(i));
-
- parser.beforeInit(new AnnotatedPojo(), "testPojo", null, mbm);
-
- Skeleton.getSkeleton(helper).assertCalledExactNumberOfTimes(new MethodCall(TxComponentMetaDataHelper.class,
- "getComponentMethodTxAttribute", mbm, String.class), 3);
-
- Skeleton.getSkeleton(helper).assertNotCalled(new MethodCall(TxComponentMetaDataHelper.class,
- "setComponentTransactionData", cdr, mbm, Required, "increment"));
- Skeleton.getSkeleton(helper).assertCalledExactNumberOfTimes(new MethodCall(TxComponentMetaDataHelper.class,
- "setComponentTransactionData", cdr, mbm, Supports, "checkValue"), 1);
- Skeleton.getSkeleton(helper).assertCalledExactNumberOfTimes(new MethodCall(TxComponentMetaDataHelper.class,
- "setComponentTransactionData", cdr, mbm, TransactionPropagationType.Mandatory, "getRealObject"), 1);
-
- Skeleton.getSkeleton(cdr).assertNotCalled(new MethodCall(ComponentDefinitionRegistry.class,
- "registerInterceptorWithComponent", mbm, i));
- }
-
-
- @Test(expected=IllegalArgumentException.class)
- public void testNoPrivateAnnotation() {
- MutableBeanMetadata mbm = new BeanMetadataImpl();
- mbm.setId("testPojo");
- mbm.setClassName(BadlyAnnotatedPojo1.class.getName());
- parser.beforeInit(new BadlyAnnotatedPojo1(), "testPojo", null, mbm);
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void testNoStaticAnnotation() {
- MutableBeanMetadata mbm = new BeanMetadataImpl();
- mbm.setId("testPojo");
- mbm.setClassName(BadlyAnnotatedPojo2.class.getName());
- parser.beforeInit(new BadlyAnnotatedPojo2(), "testPojo", null, mbm);
- }
-
+ private TxComponentMetaDataHelper helper;
+ private ComponentDefinitionRegistry cdr;
+ private Interceptor interceptor;
+ private AnnotationParser parser;
+ private IMocksControl c;
+
+ @Before
+ public void setup() {
+ c = EasyMock.createNiceControl();
+ helper = c.createMock(TxComponentMetaDataHelper.class);
+ cdr = c.createMock(ComponentDefinitionRegistry.class);
+ interceptor = c.createMock(Interceptor.class);
+ parser = new AnnotationParser(cdr, interceptor, helper);
+ }
+
+ @Test
+ public void testFindAnnotation() {
+ MutableBeanMetadata mbm = createMetaData(AnnotatedPojo.class);
+ expect(helper.getComponentMethodTxAttribute(anyObject(ComponentMetadata.class), anyString())).andReturn(null).atLeastOnce();
+ expect(cdr.getInterceptors(mbm)).andReturn(new ArrayList<Interceptor>());
+ helper.setComponentTransactionData(cdr, mbm, Required, "increment");
+ expectLastCall().times(1);
+ helper.setComponentTransactionData(cdr, mbm, Supports, "checkValue");
+ expectLastCall().times(1);
+ helper.setComponentTransactionData(cdr, mbm, Mandatory, "getRealObject");
+ expectLastCall().times(1);
+ cdr.registerInterceptorWithComponent(mbm , interceptor);
+ expectLastCall().times(1);
+ c.replay();
+ parser.beforeInit(new AnnotatedPojo(), "testPojo", null, mbm);
+ c.verify();
+ }
+
+ @Test
+ public void testAnnotationsOverridenByXML() {
+ AnnotatedPojo bean = new AnnotatedPojo();
+ MutableBeanMetadata mbm = createMetaData(bean.getClass());
+
+ expect(helper.getComponentMethodTxAttribute(mbm, "increment")).andReturn(TransactionPropagationType.Never);
+ expect(helper.getComponentMethodTxAttribute(mbm, "checkValue")).andReturn(null);
+ expect(helper.getComponentMethodTxAttribute(mbm, "getRealObject")).andReturn(null);
+ expect(cdr.getInterceptors(mbm)).andReturn(Arrays.asList(interceptor));
+ helper.setComponentTransactionData(cdr, mbm, Supports, "checkValue");
+ expectLastCall().times(1);
+ helper.setComponentTransactionData(cdr, mbm, Mandatory, "getRealObject");
+ expectLastCall().times(1);
+
+ c.replay();
+ parser.beforeInit(bean, "testPojo", null, mbm);
+ c.verify();
+ }
+
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNoPrivateAnnotation() {
+ BadlyAnnotatedPojo1 bean = new BadlyAnnotatedPojo1();
+ MutableBeanMetadata mbm = createMetaData(bean.getClass());
+ expect(cdr.getInterceptors(mbm)).andReturn(new ArrayList<Interceptor>());
+ expect(helper.getComponentMethodTxAttribute(anyObject(ComponentMetadata.class), anyString())).andReturn(null).atLeastOnce();
+ c.replay();
+ parser.beforeInit(bean, "testPojo", null, mbm);
+ c.verify();
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNoStaticAnnotation() {
+ BadlyAnnotatedPojo2 bean = new BadlyAnnotatedPojo2();
+ MutableBeanMetadata mbm = createMetaData(bean.getClass());
+ expect(cdr.getInterceptors(mbm)).andReturn(new ArrayList<Interceptor>());
+ expect(helper.getComponentMethodTxAttribute(anyObject(ComponentMetadata.class), anyString())).andReturn(null).atLeastOnce();
+ c.replay();
+ parser.beforeInit(bean, "testPojo", null, mbm);
+ c.verify();
+ }
+
+ private MutableBeanMetadata createMetaData(Class<?> clazz) {
+ MutableBeanMetadata mbm = new BeanMetadataImpl();
+ mbm.setId("testPojo");
+ mbm.setClassName(clazz.getName());
+ return mbm;
+ }
}
Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BaseNameSpaceHandlerSetup.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BaseNameSpaceHandlerSetup.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BaseNameSpaceHandlerSetup.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BaseNameSpaceHandlerSetup.java Wed Jul 8 10:49:21 2015
@@ -18,91 +18,83 @@
*/
package org.apache.aries.transaction;
+import static org.easymock.EasyMock.expect;
+
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Properties;
import java.util.Set;
import javax.transaction.TransactionManager;
import org.apache.aries.blueprint.ComponentDefinitionRegistry;
-import org.apache.aries.blueprint.NamespaceHandler;
-import org.apache.aries.blueprint.container.NamespaceHandlerRegistry;
-import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
import org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl;
import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
import org.apache.aries.blueprint.parser.Parser;
import org.apache.aries.blueprint.reflect.PassThroughMetadataImpl;
-import org.apache.aries.mocks.BundleContextMock;
-import org.apache.aries.mocks.BundleMock;
import org.apache.aries.transaction.parsing.TxNamespaceHandler;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.Skeleton;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.blueprint.container.BlueprintContainer;
public class BaseNameSpaceHandlerSetup {
protected Bundle b;
- protected NamespaceHandlerRegistry nhri;
+ protected DummyNamespaceHandlerRegistry nhri;
protected TxComponentMetaDataHelperImpl txenhancer;
protected TxNamespaceHandler namespaceHandler;
-
+ protected IMocksControl control;
+
@Before
- public void setUp() {
- b = Skeleton.newMock(new BundleMock("org.apache.aries.tx", new Properties()), Bundle.class);
- BundleContext ctx = b.getBundleContext();
- nhri = new NamespaceHandlerRegistryImpl(ctx);
-
- TransactionManager tm = Skeleton.newMock(TransactionManager.class);
-
+ public void setUp() throws InvalidSyntaxException {
+ control = EasyMock.createControl();
+ b = control.createMock(Bundle.class);
+ TransactionManager tm = control.createMock(TransactionManager.class);
txenhancer = new TxComponentMetaDataHelperImpl();
-
TxInterceptorImpl txinterceptor = new TxInterceptorImpl();
txinterceptor.setTransactionManager(tm);
txinterceptor.setTxMetaDataHelper(txenhancer);
-
namespaceHandler = new TxNamespaceHandler();
-
- BlueprintContainer container = Skeleton.newMock(BlueprintContainer.class);
- Skeleton.getSkeleton(container).setReturnValue(
- new MethodCall(BlueprintContainer.class, "getComponentInstance", TxNamespaceHandler.DEFAULT_INTERCEPTOR_ID),
- txinterceptor);
+
+ BlueprintContainer container = control.createMock(BlueprintContainer.class);
+ expect(container.getComponentInstance(EasyMock.eq(TxNamespaceHandler.DEFAULT_INTERCEPTOR_ID))).andReturn(txinterceptor);
+ control.replay();
namespaceHandler.setBlueprintContainer(container);
namespaceHandler.setTxMetaDataHelper(txenhancer);
-
- Properties props = new Properties();
- props.put("osgi.service.blueprint.namespace", new String[]{"http://aries.apache.org/xmlns/transactions/v1.0.0", "http://aries.apache.org/xmlns/transactions/v1.1.0", "http://aries.apache.org/xmlns/transactions/v1.2.0"});
- ctx.registerService(NamespaceHandler.class.getName(), namespaceHandler, (Dictionary) props);
+
+ String[] namespaces = new String[]
+ {"http://aries.apache.org/xmlns/transactions/v1.0.0",
+ "http://aries.apache.org/xmlns/transactions/v1.1.0",
+ "http://aries.apache.org/xmlns/transactions/v1.2.0"
+ };
+ nhri = new DummyNamespaceHandlerRegistry();
+ nhri.addNamespaceHandlers(namespaces, namespaceHandler);
}
-
+
@After
public void tearDown() throws Exception{
- b = null;
- nhri = null;
- txenhancer = null;
-
- BundleContextMock.clear();
+ control.verify();
+ b = null;
+ nhri = null;
+ txenhancer = null;
}
-
+
protected ComponentDefinitionRegistry parseCDR(String name) throws Exception {
Parser p = new Parser();
-
+
URL bpxml = this.getClass().getResource(name);
p.parse(Arrays.asList(bpxml));
-
+
Set<URI> nsuris = p.getNamespaces();
NamespaceHandlerSet nshandlers = nhri.getNamespaceHandlers(nsuris, b);
- p.validate(nshandlers.getSchema());
-
+
ComponentDefinitionRegistry cdr = new ComponentDefinitionRegistryImpl();
cdr.registerComponentDefinition(new PassThroughMetadataImpl("blueprintBundle", b));
p.populate(nshandlers, cdr);
-
+
return cdr;
}
}
Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java Wed Jul 8 10:49:21 2015
@@ -30,107 +30,107 @@ import org.junit.Test;
import org.osgi.service.blueprint.reflect.BeanMetadata;
public class BundleWideNameSpaceHandlerTest extends BaseNameSpaceHandlerSetup {
-
-
+
+
private void testMultipleElements(String xml) throws Exception
{
- ComponentDefinitionRegistry cdr = parseCDR(xml);
-
- BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top1");
- BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down1");
-
- assertNotNull(compTop);
- assertNotNull(compDown);
-
- assertEquals(1, cdr.getInterceptors(compTop).size());
- assertEquals(1, cdr.getInterceptors(compDown).size());
-
- assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
- assertEquals(TransactionPropagationType.Never, txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
-
+ ComponentDefinitionRegistry cdr = parseCDR(xml);
+
+ BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top1");
+ BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down1");
+
+ assertNotNull(compTop);
+ assertNotNull(compDown);
+
+ assertEquals(1, cdr.getInterceptors(compTop).size());
+ assertEquals(1, cdr.getInterceptors(compDown).size());
+
+ assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
+ assertEquals(TransactionPropagationType.Never, txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
+
}
-
+
@Test
public void testMultipleElements_110() throws Exception {
- testMultipleElements("bundlewide-aries.xml");
+ testMultipleElements("bundlewide-aries.xml");
}
-
+
@Test
public void testMultipleElements_120() throws Exception {
- testMultipleElements("bundlewide-aries4.xml");
+ testMultipleElements("bundlewide-aries4.xml");
}
-
+
private void testMultipleElements2(String xml) throws Exception
{
- ComponentDefinitionRegistry cdr = parseCDR(xml);
-
- BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top2");
- BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down2");
- BeanMetadata compMiddle = (BeanMetadata) cdr.getComponentDefinition("middle2");
-
- assertNotNull(compTop);
- assertNotNull(compDown);
- assertNotNull(compMiddle);
-
- assertEquals(1, cdr.getInterceptors(compTop).size());
- assertEquals(1, cdr.getInterceptors(compDown).size());
- assertEquals(0, cdr.getInterceptors(compMiddle).size());
-
- assertEquals(RequiresNew, txenhancer.getComponentMethodTxAttribute(compTop, "update1234"));
- assertEquals(Required, txenhancer.getComponentMethodTxAttribute(compTop, "update"));
- assertEquals(NotSupported, txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
-
- assertEquals(Required, txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
- assertEquals(NotSupported, txenhancer.getComponentMethodTxAttribute(compDown, "update1234"));
-
- assertEquals(null, txenhancer.getComponentMethodTxAttribute(compMiddle, "doSomething"));
-
+ ComponentDefinitionRegistry cdr = parseCDR(xml);
+
+ BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top2");
+ BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down2");
+ BeanMetadata compMiddle = (BeanMetadata) cdr.getComponentDefinition("middle2");
+
+ assertNotNull(compTop);
+ assertNotNull(compDown);
+ assertNotNull(compMiddle);
+
+ assertEquals(1, cdr.getInterceptors(compTop).size());
+ assertEquals(1, cdr.getInterceptors(compDown).size());
+ assertEquals(0, cdr.getInterceptors(compMiddle).size());
+
+ assertEquals(RequiresNew, txenhancer.getComponentMethodTxAttribute(compTop, "update1234"));
+ assertEquals(Required, txenhancer.getComponentMethodTxAttribute(compTop, "update"));
+ assertEquals(NotSupported, txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
+
+ assertEquals(Required, txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
+ assertEquals(NotSupported, txenhancer.getComponentMethodTxAttribute(compDown, "update1234"));
+
+ assertEquals(null, txenhancer.getComponentMethodTxAttribute(compMiddle, "doSomething"));
+
}
-
+
@Test
public void testMultipleElements2_110() throws Exception {
- testMultipleElements2("bundlewide-aries2.xml");
+ testMultipleElements2("bundlewide-aries2.xml");
}
-
+
@Test
public void testMultipleElements2_120() throws Exception {
- testMultipleElements2("bundlewide-aries5.xml");
+ testMultipleElements2("bundlewide-aries5.xml");
}
-
+
private void testMultipleElements3(String xml) throws Exception
{
- ComponentDefinitionRegistry cdr = parseCDR(xml);
-
- BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top3");
- BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down3");
- BeanMetadata compMiddle = (BeanMetadata) cdr.getComponentDefinition("middle3");
-
- assertNotNull(compTop);
- assertNotNull(compDown);
- assertNotNull(compMiddle);
-
- assertEquals(1, cdr.getInterceptors(compTop).size());
- assertEquals(1, cdr.getInterceptors(compDown).size());
- assertEquals(1, cdr.getInterceptors(compMiddle).size());
-
- assertEquals(TransactionPropagationType.RequiresNew, txenhancer.getComponentMethodTxAttribute(compTop, "update1234"));
- assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compTop, "update"));
- assertEquals(TransactionPropagationType.NotSupported, txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
-
- assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
- assertEquals(TransactionPropagationType.NotSupported, txenhancer.getComponentMethodTxAttribute(compDown, "update1234"));
-
- assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compMiddle, "doSomething"));
-
+ ComponentDefinitionRegistry cdr = parseCDR(xml);
+
+ BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top3");
+ BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down3");
+ BeanMetadata compMiddle = (BeanMetadata) cdr.getComponentDefinition("middle3");
+
+ assertNotNull(compTop);
+ assertNotNull(compDown);
+ assertNotNull(compMiddle);
+
+ assertEquals(1, cdr.getInterceptors(compTop).size());
+ assertEquals(1, cdr.getInterceptors(compDown).size());
+ assertEquals(1, cdr.getInterceptors(compMiddle).size());
+
+ assertEquals(TransactionPropagationType.RequiresNew, txenhancer.getComponentMethodTxAttribute(compTop, "update1234"));
+ assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compTop, "update"));
+ assertEquals(TransactionPropagationType.NotSupported, txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
+
+ assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
+ assertEquals(TransactionPropagationType.NotSupported, txenhancer.getComponentMethodTxAttribute(compDown, "update1234"));
+
+ assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compMiddle, "doSomething"));
+
}
-
+
@Test
public void testMultipleElements3_110() throws Exception {
- testMultipleElements3("bundlewide-aries3.xml");
+ testMultipleElements3("bundlewide-aries3.xml");
}
-
+
@Test
public void testMultipleElements3_120() throws Exception {
- testMultipleElements3("bundlewide-aries6.xml");
+ testMultipleElements3("bundlewide-aries6.xml");
}
}
Added: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerRegistry.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerRegistry.java?rev=1689837&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerRegistry.java (added)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerRegistry.java Wed Jul 8 10:49:21 2015
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.transaction;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.container.NamespaceHandlerRegistry;
+import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
+import org.osgi.framework.Bundle;
+
+public class DummyNamespaceHandlerRegistry implements NamespaceHandlerRegistry {
+ Map<URI, NamespaceHandler> handlers = new HashMap<URI, NamespaceHandler>();
+
+ @Override
+ public NamespaceHandlerSet getNamespaceHandlers(Set<URI> uriSet, Bundle bundle) {
+ Map<URI, NamespaceHandler> matching = new HashMap<URI, NamespaceHandler>();
+ for (URI uri : uriSet) {
+ if (handlers.containsKey(uri)) {
+ matching.put(uri, handlers.get(uri));
+ }
+ }
+ return new DummyNamespaceHandlerSet(matching);
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ public void addNamespaceHandlers(String[] namespaces, NamespaceHandler namespaceHandler) {
+ for (String namespace : namespaces) {
+ try {
+ handlers.put(new URI(namespace), namespaceHandler);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
+ }
+ }
+
+}
Added: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerSet.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerSet.java?rev=1689837&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerSet.java (added)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/DummyNamespaceHandlerSet.java Wed Jul 8 10:49:21 2015
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.transaction;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.validation.Schema;
+
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
+import org.xml.sax.SAXException;
+
+public class DummyNamespaceHandlerSet implements NamespaceHandlerSet {
+ private Map<URI, NamespaceHandler> nsHandlers;
+
+ public DummyNamespaceHandlerSet(Map<URI, NamespaceHandler> nsHandlers) {
+ this.nsHandlers = nsHandlers;
+ }
+
+ @Override
+ public void addListener(Listener listener) {
+ throw new IllegalStateException("Not implemented");
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ @Override
+ public NamespaceHandler getNamespaceHandler(URI nsuri) {
+ return nsHandlers.get(nsuri);
+ }
+
+ @Override
+ public Set<URI> getNamespaces() {
+ return nsHandlers.keySet();
+ }
+
+ @Override
+ public Schema getSchema() throws SAXException, IOException {
+ throw new IllegalStateException("Not implemented");
+ }
+
+ @Override
+ public boolean isComplete() {
+ return true;
+ }
+
+ @Override
+ public void removeListener(Listener listener) {
+ throw new IllegalStateException("Not implemented");
+ }
+
+}
Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java Wed Jul 8 10:49:21 2015
@@ -23,39 +23,35 @@ import java.io.IOException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.Skeleton;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
import org.junit.Test;
public class InterceptorTest {
- private Transaction t;
-
- @Test
- public void testRollbackOnException() {
- TxInterceptorImpl sut = new TxInterceptorImpl();
- sut.setTransactionManager(Skeleton.newMock(TransactionManager.class));
-
- sut.postCallWithException(null, null, new IllegalStateException(), newTranToken());
- assertRolledBack();
- sut.postCallWithException(null, null, new Error(), newTranToken());
- assertRolledBack();
- sut.postCallWithException(null, null, new Exception(), newTranToken());
- assertNotRolledBack();
- sut.postCallWithException(null, null, new IOException(), newTranToken());
- assertNotRolledBack();
- }
-
- private void assertNotRolledBack() {
- Skeleton.getSkeleton(t).assertNotCalled(new MethodCall(Transaction.class, "setRollbackOnly"));
+ @Test
+ public void testRollbackOnException() throws Throwable {
+ postCallWithTransaction(new IllegalStateException(), true);
+ postCallWithTransaction(new Error(), true);
+ postCallWithTransaction(new Exception(), false);
+ postCallWithTransaction(new IOException(), false);
}
- private void assertRolledBack() {
- Skeleton.getSkeleton(t).assertCalled(new MethodCall(Transaction.class, "setRollbackOnly"));
+ private void postCallWithTransaction(Throwable th, boolean expectRollback) throws Throwable {
+ IMocksControl c = EasyMock.createControl();
+ TxInterceptorImpl sut = new TxInterceptorImpl();
+ sut.setTransactionManager(c.createMock(TransactionManager.class));
+ Transaction tran = c.createMock(Transaction.class);
+
+ if (expectRollback) {
+ tran.setRollbackOnly();
+ EasyMock.expectLastCall();
+ }
+
+ c.replay();
+ TransactionToken tt = new TransactionToken(tran, null, TransactionAttribute.REQUIRED);
+ sut.postCallWithException(null, null, th, tt);
+ c.verify();
}
- private TransactionToken newTranToken() {
- t = Skeleton.newMock(Transaction.class);
- return new TransactionToken(t, null, TransactionAttribute.REQUIRED);
- }
}
Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java Wed Jul 8 10:49:21 2015
@@ -23,7 +23,7 @@ import static org.junit.Assert.*;
import org.apache.aries.blueprint.ComponentDefinitionRegistry;
import org.apache.aries.transaction.annotations.TransactionPropagationType;
import org.apache.aries.transaction.parsing.TxBlueprintListener;
-import org.apache.aries.unittest.mocks.Skeleton;
+import org.easymock.EasyMock;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.service.blueprint.container.BlueprintEvent;
@@ -167,9 +167,9 @@ public class NameSpaceHandlerTest extend
assertEquals(TransactionPropagationType.Never, txenhancer.getComponentMethodTxAttribute(anonToo, "doSomething"));
assertTrue(namespaceHandler.isRegistered(cdr));
-
+ Bundle extenderBundle = EasyMock.createMock(Bundle.class);
new TxBlueprintListener(namespaceHandler).blueprintEvent(
- new BlueprintEvent(BlueprintEvent.DESTROYED, b, Skeleton.newMock(Bundle.class)));
+ new BlueprintEvent(BlueprintEvent.DESTROYED, b, extenderBundle));
assertNull(txenhancer.getComponentMethodTxAttribute(anon, "doSomething"));
assertNull(txenhancer.getComponentMethodTxAttribute(anonToo, "doSomething"));
@@ -212,9 +212,10 @@ public class NameSpaceHandlerTest extend
// cleanup
assertTrue(namespaceHandler.isRegistered(cdr));
-
+
+ Bundle extenderBundle = EasyMock.createMock(Bundle.class);
new TxBlueprintListener(namespaceHandler).blueprintEvent(
- new BlueprintEvent(BlueprintEvent.DESTROYED, b, Skeleton.newMock(Bundle.class)));
+ new BlueprintEvent(BlueprintEvent.DESTROYED, b, extenderBundle));
assertFalse(namespaceHandler.isRegistered(cdr));
assertNull(txenhancer.getComponentMethodTxAttribute(compRequiresNew, "doSomething"));
Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java Wed Jul 8 10:49:21 2015
@@ -18,6 +18,9 @@
*/
package org.apache.aries.transaction;
+import static org.easymock.EasyMock.createControl;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@@ -32,22 +35,23 @@ import javax.transaction.SystemException
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;
-import org.apache.aries.transaction.TransactionAttribute;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.Skeleton;
public class TranStrategyTest {
- TransactionManager tm = Skeleton.newMock(TransactionManager.class);
- Transaction t = Skeleton.newMock(Transaction.class);
- Skeleton skel = Skeleton.getSkeleton(tm);
+ TransactionManager tm;
+ Transaction t;
+ private IMocksControl c;
@Before
public void clean()
{
- skel.clearMethodCalls();
+ c = createControl();
+ tm = c.createMock(TransactionManager.class);
+ t = c.createMock(Transaction.class);
}
@Test
@@ -55,7 +59,7 @@ public class TranStrategyTest {
{
// MANDATORY strategy should throw IllegalStateException when tran manager
// status is Status.STATUS_NO_TRANSACTION it should not return null.
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_NO_TRANSACTION);
+ expect(tm.getStatus()).andReturn(Status.STATUS_NO_TRANSACTION);
try {
assertNotNull("TransactionStrategy.MANDATORY.begin(tm) returned null when manager " +
@@ -73,14 +77,17 @@ public class TranStrategyTest {
Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
for (int i = 0; i < invalids.length ; i++) {
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
+ c.reset();
+ expect(tm.getStatus()).andReturn(invalids[i]);
+ expect(tm.getTransaction()).andReturn(null);
+ c.replay();
try {
Transaction tran = TransactionAttribute.MANDATORY.begin(tm).getActiveTransaction();
assertNull("TransactionStrategy.MANDATORY.begin() did not return null when manager status value is " + invalids[i], tran);
} catch (Exception ise) {
fail("TransactionStrategy.MANDATORY.begin() threw Exception when manager status value is " + invalids[i]);
- }
+ }
+ c.verify();
}
}
@@ -99,33 +106,36 @@ public class TranStrategyTest {
@Test
public void testNeverBegin() throws Exception
{
- // NEVER strategy should throw IllegalStateException when tran manager
- // status is Status.STATUS_ACTIVE it should not return null.
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_ACTIVE);
-
- try {
- assertNotNull("TransactionStrategy.NEVER.begin() returned null when manager status is STATUS_ACTIVE", TransactionAttribute.NEVER.begin(tm));
- } catch (IllegalStateException ise) {
- // Expect to be in here
- } catch (Exception e) {
- fail("TransactionStrategy.NEVER.begin() threw an unexpected exception when tran manager status is STATUS_ACTIVE");
- }
-
- // NEVER strategy should return null for all tran manager states other
- // than Status.STATUS_ACTIVE.
- int[] invalids = new int[]{ Status.STATUS_COMMITTED, Status.STATUS_COMMITTING, Status.STATUS_MARKED_ROLLBACK,
- Status.STATUS_NO_TRANSACTION, Status.STATUS_PREPARED, Status.STATUS_PREPARING, Status.STATUS_ROLLEDBACK,
- Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
-
- for (int i = 0; i < invalids.length ; i++) {
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
+ // NEVER strategy should throw IllegalStateException when tran manager
+ // status is Status.STATUS_ACTIVE it should not return null.
+ expect(tm.getStatus()).andReturn(Status.STATUS_ACTIVE);
+
try {
- assertNull("TransactionStrategy.NEVER.begin() did not return null when manager status value is " + invalids[i], TransactionAttribute.NEVER.begin(tm).getActiveTransaction());
- } catch (Exception ise) {
- fail("TransactionStrategy.NEVER.begin() threw unexpected exception when manager status value is " + invalids[i]);
- }
- }
+ assertNotNull("TransactionStrategy.NEVER.begin() returned null when manager status is STATUS_ACTIVE", TransactionAttribute.NEVER.begin(tm));
+ } catch (IllegalStateException ise) {
+ // Expect to be in here
+ } catch (Exception e) {
+ fail("TransactionStrategy.NEVER.begin() threw an unexpected exception when tran manager status is STATUS_ACTIVE");
+ }
+
+ // NEVER strategy should return null for all tran manager states other
+ // than Status.STATUS_ACTIVE.
+ int[] invalids = new int[]{ Status.STATUS_COMMITTED, Status.STATUS_COMMITTING, Status.STATUS_MARKED_ROLLBACK,
+ Status.STATUS_NO_TRANSACTION, Status.STATUS_PREPARED, Status.STATUS_PREPARING, Status.STATUS_ROLLEDBACK,
+ Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
+
+ for (int i = 0; i < invalids.length ; i++) {
+ c.reset();
+ expect(tm.getStatus()).andReturn(invalids[i]);
+ expect(tm.getTransaction()).andReturn(null).anyTimes();
+ c.replay();
+ try {
+ assertNull("TransactionStrategy.NEVER.begin() did not return null when manager status value is " + invalids[i], TransactionAttribute.NEVER.begin(tm).getActiveTransaction());
+ } catch (Exception ise) {
+ fail("TransactionStrategy.NEVER.begin() threw unexpected exception when manager status value is " + invalids[i]);
+ }
+ c.verify();
+ }
}
@@ -145,11 +155,11 @@ public class TranStrategyTest {
{
// NOT_SUPPORTED strategy should suspend an active transaction
// and _NOT_ begin a new one
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_ACTIVE);
-
+ expect(tm.getStatus()).andReturn(Status.STATUS_ACTIVE);
+ expect(tm.suspend()).andReturn(null);
+ c.replay();
TransactionAttribute.NOTSUPPORTED.begin(tm);
- skel.assertCalled(new MethodCall(TransactionManager.class, "suspend"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "begin"));
+ c.verify();
// For all situations where there is no active transaction the
// NOT_SUPPORTED strategy should return null
@@ -158,13 +168,16 @@ public class TranStrategyTest {
Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
for (int i = 0; i < invalids.length ; i++) {
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
+ c.reset();
+ expect(tm.getStatus()).andReturn(invalids[i]);
+ expect(tm.getTransaction()).andReturn(null).anyTimes();
+ c.replay();
try {
assertNull("TransactionStrategy.NOT_SUPPORTED.begin() did not return null when manager status value is " + invalids[i], TransactionAttribute.NOTSUPPORTED.begin(tm).getActiveTransaction());
} catch (Exception ise) {
fail("TransactionStrategy.NOT_SUPPORTED.begin() threw unexpected exception when manager status value is " + invalids[i]);
}
+ c.verify();
}
}
@@ -175,13 +188,16 @@ public class TranStrategyTest {
// If finish is called with a previously active transaction, then
// we expect this transaction to be resumed for a NOT_SUPPORTED strategy
try {
+ tm.resume(t);
+ EasyMock.expectLastCall();
+ c.replay();
TransactionToken tranToken = new TransactionToken(null, t, TransactionAttribute.NOTSUPPORTED);
TransactionAttribute.NOTSUPPORTED.finish(tm, tranToken);
- skel.assertCalled(new MethodCall(TransactionManager.class, "resume", t));
- skel.clearMethodCalls();
+ c.verify();
+
+ c.reset();
tranToken = new TransactionToken(null, null, TransactionAttribute.NOTSUPPORTED);
TransactionAttribute.NOTSUPPORTED.finish(tm, tranToken);
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "resume", Transaction.class));
} catch (Exception e) {
fail("TransactionStrategy.NOT_SUPPORTED.finish() threw unexpected exception, " + e);
}
@@ -192,11 +208,14 @@ public class TranStrategyTest {
{
// If there is no previously active transaction when the REQUIRED strategy
// is invoked then we expect a call to begin one
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_NO_TRANSACTION);
-
+ expect(tm.getStatus()).andReturn(Status.STATUS_NO_TRANSACTION);
+ expect(tm.getTransaction()).andReturn(null);
+ tm.begin();
+ expectLastCall();
+ c.replay();
TransactionAttribute.REQUIRED.begin(tm);
- skel.assertCalled(new MethodCall(TransactionManager.class, "begin"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "suspend"));
+ c.verify();
+ c.reset();
// For all cases where there is a transaction we expect REQUIRED to return null
int[] invalids = new int[]{ Status.STATUS_COMMITTED, Status.STATUS_COMMITTING, Status.STATUS_MARKED_ROLLBACK,
@@ -204,28 +223,32 @@ public class TranStrategyTest {
Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
for (int i = 0; i < invalids.length ; i++) {
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
+ c.reset();
+ expect(tm.getStatus()).andReturn(invalids[i]);
+ expect(tm.getTransaction()).andReturn(null);
+ c.replay();
try {
assertNull("TransactionStrategy.REQUIRED.begin() did not return null when manager status value is " + invalids[i], TransactionAttribute.REQUIRED.begin(tm).getActiveTransaction());
} catch (Exception ise) {
fail("TransactionStrategy.REQUIRED.begin() threw unexpected exception when manager status value is " + invalids[i]);
}
+ c.verify();
}
}
@Test
- public void testRequiredFinish()
+ public void testRequiredFinish() throws Exception
{
// In the REQUIRED strategy we expect a call to rollback when a call to finish()
// is made with a tran where the tran manager status shows Status.STATUS_MARKED_ROLLBACK
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_MARKED_ROLLBACK);
+ expect(tm.getStatus()).andReturn(Status.STATUS_MARKED_ROLLBACK);
- try {
TransactionToken tranToken = new TransactionToken(t, null, TransactionAttribute.REQUIRED, true);
+ tm.rollback();
+ expectLastCall();
+ c.replay();
TransactionAttribute.REQUIRED.finish(tm, tranToken);
- skel.assertCalled(new MethodCall(TransactionManager.class, "rollback"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "commit"));
+ c.verify();
int[] invalids = new int[]{ Status.STATUS_COMMITTED, Status.STATUS_COMMITTING, Status.STATUS_NO_TRANSACTION,
Status.STATUS_ACTIVE, Status.STATUS_PREPARED, Status.STATUS_PREPARING, Status.STATUS_ROLLEDBACK,
@@ -233,37 +256,40 @@ public class TranStrategyTest {
// For all other tran manager states we expect a call to commit
for (int i = 0; i < invalids.length ; i++) {
- skel.clearMethodCalls();
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
+ c.reset();
+ expect(tm.getStatus()).andReturn(invalids[i]);
+ tm.commit();
+ expectLastCall();
+ c.replay();
TransactionAttribute.REQUIRED.finish(tm, tranToken);
- skel.assertCalled(new MethodCall(TransactionManager.class, "commit"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "rollback"));
+ c.verify();
}
// If null is passed instead of a tran we expect nothing to happen
- skel.clearMethodCalls();
+ c.reset();
+ c.replay();
tranToken = new TransactionToken(null, null, TransactionAttribute.REQUIRED);
+ c.verify();
TransactionAttribute.REQUIRED.finish(tm, tranToken);
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "commit"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "rollback"));
- }catch (Exception e) {
- fail("TransactionStrategy.REQUIRED.begin() threw unexpected exception");
- }
}
@Test
public void testRequiresNew_BeginActiveTran() throws Exception
{
// Suspend case (no exception from tm.begin())
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_ACTIVE);
+ expect(tm.getStatus()).andReturn(Status.STATUS_ACTIVE);
// In the case of the REQUIRES_NEW strategy we expect an active tran to be suspended
- // a new new transaction to begin
+ // a new new transaction to begin
+ expect(tm.suspend()).andReturn(null);
+ expectLastCall();
+ tm.begin();
+ expectLastCall();
+ expect(tm.getTransaction()).andReturn(null);
+ c.replay();
TransactionAttribute.REQUIRESNEW.begin(tm);
- skel.assertCalled(new MethodCall(TransactionManager.class, "suspend"));
- skel.assertCalled(new MethodCall(TransactionManager.class, "begin"));
-
+ c.verify();
}
@Test
@@ -279,22 +305,24 @@ public class TranStrategyTest {
// we expect a call to begin a new tran, no call to suspend and null to be
// returned from TransactionStrategy.REQUIRES_NEW.begin(tm)
for (int i = 0; i < manStatus.length ; i++) {
- skel.clearMethodCalls();
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), manStatus[i]);
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
+ c.reset();
+ expect(tm.getStatus()).andReturn(manStatus[i]);
+ expect(tm.getTransaction()).andReturn(null);
+ tm.begin();
+ expectLastCall();
+ c.replay();
try {
assertNull("TransactionStrategy.REQUIRES_NEW.begin() did not return null when manager status value is " + manStatus[i], TransactionAttribute.REQUIRESNEW.begin(tm).getActiveTransaction());
- skel.assertCalled(new MethodCall(TransactionManager.class, "begin"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "suspend"));
} catch (Exception ise) {
fail("TransactionStrategy.REQUIRES_NEW.begin() threw unexpected exception when manager status value is " + manStatus[i]);
}
+ c.verify();
}
}
@Test
- public void testRequiresNew_TmExceptions()
+ public void testRequiresNew_TmExceptions() throws Exception
{
int[] allStates = new int[]{ Status.STATUS_COMMITTED, Status.STATUS_COMMITTING, Status.STATUS_NO_TRANSACTION,
Status.STATUS_ACTIVE, Status.STATUS_PREPARED, Status.STATUS_PREPARING, Status.STATUS_ROLLEDBACK,
@@ -311,28 +339,27 @@ public class TranStrategyTest {
Iterator<Exception> iterator = ees.iterator();
while (iterator.hasNext()) {
Exception e = iterator.next();
- skel.clearMethodCalls();
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), allStates[i]);
- skel.setThrows(new MethodCall(TransactionManager.class, "begin"), e);
- requiresNewExceptionCheck(tm, skel);
+ c.reset();
+ expect(tm.getStatus()).andReturn(allStates[i]);
+ expect(tm.getTransaction()).andReturn(null).anyTimes();
+ tm.begin();
+ expectLastCall().andThrow(e);
+ requiresNewExceptionCheck(tm, allStates[i]);
}
}
}
- private void requiresNewExceptionCheck(TransactionManager tm, Skeleton skel)
+ private void requiresNewExceptionCheck(TransactionManager tm, int managerStatus) throws Exception
{
- int managerStatus = -1 ;
-
- try {
- managerStatus = tm.getStatus();
- } catch (SystemException se){
- fail("Unable to obtain tran manager status");
- }
-
// If an ACTIVE tran is already present we expect a call to suspend this tran.
// All states should call begin(), whereupon we receive our exception resulting
// in calls to resume(t)
-
+ if (managerStatus == Status.STATUS_ACTIVE) {
+ expect(tm.suspend()).andReturn(null);
+ }
+ tm.resume(EasyMock.anyObject(Transaction.class));
+ expectLastCall();
+ c.replay();
try {
TransactionAttribute.REQUIRESNEW.begin(tm);
} catch (SystemException se) {
@@ -343,76 +370,71 @@ public class TranStrategyTest {
fail("TransactionStrategy.REQUIRES_NEW.begin() threw unexpected exception when manager status is " + managerStatus);
} finally {
// If Status.STATUS_ACTIVE
- if (managerStatus == 0) {
- skel.assertCalled(new MethodCall(TransactionManager.class, "suspend"));
- } else {
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "suspend"));
- }
- skel.assertCalled(new MethodCall(TransactionManager.class, "begin"));
- skel.assertCalled(new MethodCall(TransactionManager.class, "resume", Transaction.class));
}
+ c.verify();
+ c.reset();
}
@Test
- public void testRequiresNew_Finish()
+ public void testRequiresNew_Finish() throws Exception
{
- int[] allStates = new int[]{ Status.STATUS_COMMITTED, Status.STATUS_COMMITTING, Status.STATUS_NO_TRANSACTION,
- Status.STATUS_ACTIVE, Status.STATUS_PREPARED, Status.STATUS_PREPARING, Status.STATUS_ROLLEDBACK,
- Status.STATUS_MARKED_ROLLBACK, Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
-
- // Loop through all states calling TransactionStrategy.REQUIRES_NEW.finish
- // passing tran manager and a tran, then passing tran manager and null
- for (int i = 0 ; i < allStates.length ; i++ ) {
- skel.clearMethodCalls();
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), allStates[i]);
-
- try {
- TransactionToken tranToken = new TransactionToken(t, t, TransactionAttribute.REQUIRESNEW, true);
- TransactionAttribute.REQUIRESNEW.finish(tm, tranToken);
- } catch (Exception e) {
- fail("TransactionStrategy.REQUIRES_NEW.finish() threw unexpected exception when manager status is " + allStates[i]);
- } finally {
- requiresNew_assertion(skel, allStates, i);
- skel.assertCalled(new MethodCall(TransactionManager.class, "resume", t));
- }
-
- try {
- skel.clearMethodCalls();
- TransactionToken tranToken = new TransactionToken(t, null, TransactionAttribute.REQUIRESNEW, true);
- TransactionAttribute.REQUIRESNEW.finish(tm, tranToken);
- } catch (Exception e) {
- fail("TransactionStrategy.REQUIRES_NEW.finish() threw unexpected exception when manager status is " + allStates[i]);
- } finally {
- requiresNew_assertion(skel, allStates, i);
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "resume", Transaction.class));
+ int[] allStates = new int[]{ Status.STATUS_COMMITTED, Status.STATUS_COMMITTING, Status.STATUS_NO_TRANSACTION,
+ Status.STATUS_ACTIVE, Status.STATUS_PREPARED, Status.STATUS_PREPARING, Status.STATUS_ROLLEDBACK,
+ Status.STATUS_MARKED_ROLLBACK, Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
+
+ // Loop through all states calling TransactionStrategy.REQUIRES_NEW.finish
+ // passing tran manager and a tran, then passing tran manager and null
+ for (int i = 0 ; i < allStates.length ; i++ ) {
+ c.reset();
+ expect(tm.getStatus()).andReturn(allStates[i]);
+ requiresNew_assertion(tm, allStates[i]);
+ tm.resume(EasyMock.anyObject(Transaction.class));
+ expectLastCall();
+ c.replay();
+ try {
+ TransactionToken tranToken = new TransactionToken(t, t, TransactionAttribute.REQUIRESNEW, true);
+ TransactionAttribute.REQUIRESNEW.finish(tm, tranToken);
+ } catch (Exception e) {
+ fail("TransactionStrategy.REQUIRES_NEW.finish() threw unexpected exception when manager status is " + allStates[i]);
+ }
+ c.verify();
+ c.reset();
+ try {
+ expect(tm.getStatus()).andReturn(allStates[i]);
+ requiresNew_assertion(tm, allStates[i]);
+ c.replay();
+ TransactionToken tranToken = new TransactionToken(t, null, TransactionAttribute.REQUIRESNEW, true);
+ TransactionAttribute.REQUIRESNEW.finish(tm, tranToken);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail("TransactionStrategy.REQUIRES_NEW.finish() threw unexpected exception when manager status is " + allStates[i]);
+ } finally {
+ }
+ c.verify();
}
- }
-
+
}
- private void requiresNew_assertion(Skeleton skel, int[] allStates, int i)
+ // If tran manager status reports Status.STATUS_MARKED_ROLLBACK we expect
+ // a call to rollback ... otherwise we expect a call to commit
+ private void requiresNew_assertion(TransactionManager tm, int status) throws Exception
{
- // If tran manager status reports Status.STATUS_MARKED_ROLLBACK we expect
- // a call to rollback ... otherwise we expect a call to commit
- if (allStates[i] == Status.STATUS_MARKED_ROLLBACK) {
- skel.assertCalled(new MethodCall(TransactionManager.class, "rollback"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "commit"));
+ if (status == Status.STATUS_MARKED_ROLLBACK) {
+ tm.rollback();
}
else {
- skel.assertCalled(new MethodCall(TransactionManager.class, "commit"));
- skel.assertNotCalled(new MethodCall(TransactionManager.class, "rollback"));
+ tm.commit();
}
+ expectLastCall();
}
@Test
- public void testSupports()
+ public void testSupports() throws Exception
{
- try {
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
- assertNull("TransTransactionStrategy.SUPPORTS.begin(tm) did not return null", TransactionAttribute.SUPPORTS.begin(tm).getActiveTransaction());
- } catch (Exception e) {
- fail("TransTransactionStrategy.SUPPORTS.begin(tm) threw an unexpected exception");
- }
-
+ expect(tm.getTransaction()).andReturn(null);
+ expect(tm.getStatus()).andReturn(Status.STATUS_ACTIVE);
+ c.replay();
+ assertNull("TransTransactionStrategy.SUPPORTS.begin(tm) did not return null", TransactionAttribute.SUPPORTS.begin(tm).getActiveTransaction());
+ c.verify();
}
}
Modified: aries/trunk/transaction/transaction-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/pom.xml?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/pom.xml (original)
+++ aries/trunk/transaction/transaction-itests/pom.xml Wed Jul 8 10:49:21 2015
@@ -93,12 +93,6 @@
<version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.apache.aries.testsupport</groupId>
- <artifactId>org.apache.aries.testsupport.unit</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.8.0.v20120529-1548</version>
@@ -134,7 +128,7 @@
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-native</artifactId>
+ <artifactId>pax-exam-container-forked</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>
@@ -201,13 +195,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkMode>pertest</forkMode>
- </configuration>
- </plugin>
</plugins>
</build>
@@ -225,7 +212,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <forkMode>pertest</forkMode>
<!--
when the local repo location has been specified, we need to pass
on this information to PAX mvn url
Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java Wed Jul 8 10:49:21 2015
@@ -26,6 +26,9 @@ import static org.ops4j.pax.exam.CoreOpt
import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.ops4j.pax.exam.CoreOptions.when;
+import javax.inject.Inject;
+import javax.transaction.UserTransaction;
+
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.CoreOptions;
@@ -33,12 +36,18 @@ import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerSuite;
+import org.osgi.framework.BundleContext;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerSuite.class)
-public abstract class AbstractIntegrationTest extends org.apache.aries.itest.AbstractIntegrationTest {
-
- public Option baseOptions() {
+public abstract class AbstractIntegrationTest {
+ @Inject
+ BundleContext bundleContext;
+
+ @Inject
+ UserTransaction tran;
+
+ public Option baseOptions() {
String localRepo = System.getProperty("maven.repo.local");
if (localRepo == null) {
localRepo = System.getProperty("org.ops4j.pax.url.mvn.localRepository");
@@ -55,10 +64,9 @@ public abstract class AbstractIntegratio
@Configuration
public Option[] configuration() {
return new Option[] {
- baseOptions(),
+ baseOptions(),
frameworkProperty("org.osgi.framework.system.packages")
- .value("javax.accessibility,javax.activation,javax.activity,javax.annotation,javax.annotation.processing,javax.crypto,javax.crypto.interfaces,javax.crypto.spec,javax.imageio,javax.imageio.event,javax.imageio.metadata,javax.imageio.plugins.bmp,javax.imageio.plugins.jpeg,javax.imageio.spi,javax.imageio.stream,javax.jws,javax.jws.soap,javax.lang.model,javax.lang.model.element,javax.lang.model.type,javax.lang.model.util,javax.management,javax.management.loading,javax.management.modelmbean,javax.management.monitor,javax.management.openmbean,javax.management.relation,javax.management.remote,javax.management.remote.rmi,javax.management.timer,javax.naming,javax.naming.directory,javax.naming.event,javax.naming.ldap,javax.naming.spi,javax.net,javax.net.ssl,javax.print,javax.print.attribute,javax.print.attribute.standard,javax.print.event,javax.rmi,javax.rmi.CORBA,javax.rmi.ssl,javax.script,javax.security.auth,javax.security.auth.callback,javax.security.auth.kerberos,javax.sec
urity.auth.login,javax.security.auth.spi,javax.security.auth.x500,javax.security.cert,javax.security.sasl,javax.sound.midi,javax.sound.midi.spi,javax.sound.sampled,javax.sound.sampled.spi,javax.sql,javax.sql.rowset,javax.sql.rowset.serial,javax.sql.rowset.spi,javax.swing,javax.swing.border,javax.swing.colorchooser,javax.swing.event,javax.swing.filechooser,javax.swing.plaf,javax.swing.plaf.basic,javax.swing.plaf.metal,javax.swing.plaf.multi,javax.swing.plaf.synth,javax.swing.table,javax.swing.text,javax.swing.text.html,javax.swing.text.html.parser,javax.swing.text.rtf,javax.swing.tree,javax.swing.undo,javax.tools,javax.xml,javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.adapters,javax.xml.bind.attachment,javax.xml.bind.helpers,javax.xml.bind.util,javax.xml.crypto,javax.xml.crypto.dom,javax.xml.crypto.dsig,javax.xml.crypto.dsig.dom,javax.xml.crypto.dsig.keyinfo,javax.xml.crypto.dsig.spec,javax.xml.datatype,javax.xml.namespace,javax.xml.parsers,javax.xml.soap,javax.x
ml.stream,javax.xml.stream.events,javax.xml.stream.util,javax.xml.transform,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.transform.stax,javax.xml.transform.stream,javax.xml.validation,javax.xml.ws,javax.xml.ws.handler,javax.xml.ws.handler.soap,javax.xml.ws.http,javax.xml.ws.soap,javax.xml.ws.spi,javax.xml.xpath,org.ietf.jgss,org.omg.CORBA,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg.CORBA.TypeCodePackage,org.omg.CORBA.portable,org.omg.CORBA_2_3,org.omg.CORBA_2_3.portable,org.omg.CosNaming,org.omg.CosNaming.NamingContextExtPackage,org.omg.CosNaming.NamingContextPackage,org.omg.Dynamic,org.omg.DynamicAny,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage,org.omg.IOP,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage,org.omg.Messaging,org.omg.PortableInterceptor,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.PortableServer,org.omg.PortableServer.CurrentPackage,org.omg.PortableServer.POAManagerPackage,org.omg.PortableServe
r.POAPackage,org.omg.PortableServer.ServantLocatorPackage,org.omg.PortableServer.portable,org.omg.SendingContext,org.omg.stub.java.rmi,org.w3c.dom,org.w3c.dom.bootstrap,org.w3c.dom.css,org.w3c.dom.events,org.w3c.dom.html,org.w3c.dom.ls,org.w3c.dom.ranges,org.w3c.dom.stylesheets,org.w3c.dom.traversal,org.w3c.dom.views,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers"),
- mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit").versionAsInProject(),
+ .value("javax.accessibility,javax.activation,javax.activity,javax.annotation,javax.annotation.processing,javax.crypto,javax.crypto.interfaces,javax.crypto.spec,javax.imageio,javax.imageio.event,javax.imageio.metadata,javax.imageio.plugins.bmp,javax.imageio.plugins.jpeg,javax.imageio.spi,javax.imageio.stream,javax.jws,javax.jws.soap,javax.lang.model,javax.lang.model.element,javax.lang.model.type,javax.lang.model.util,javax.management,javax.management.loading,javax.management.modelmbean,javax.management.monitor,javax.management.openmbean,javax.management.relation,javax.management.remote,javax.management.remote.rmi,javax.management.timer,javax.naming,javax.naming.directory,javax.naming.event,javax.naming.ldap,javax.naming.spi,javax.net,javax.net.ssl,javax.print,javax.print.attribute,javax.print.attribute.standard,javax.print.event,javax.rmi,javax.rmi.CORBA,javax.rmi.ssl,javax.script,javax.security.auth,javax.security.auth.callback,javax.security.auth.kerberos,javax.
security.auth.login,javax.security.auth.spi,javax.security.auth.x500,javax.security.cert,javax.security.sasl,javax.sound.midi,javax.sound.midi.spi,javax.sound.sampled,javax.sound.sampled.spi,javax.sql,javax.sql.rowset,javax.sql.rowset.serial,javax.sql.rowset.spi,javax.swing,javax.swing.border,javax.swing.colorchooser,javax.swing.event,javax.swing.filechooser,javax.swing.plaf,javax.swing.plaf.basic,javax.swing.plaf.metal,javax.swing.plaf.multi,javax.swing.plaf.synth,javax.swing.table,javax.swing.text,javax.swing.text.html,javax.swing.text.html.parser,javax.swing.text.rtf,javax.swing.tree,javax.swing.undo,javax.tools,javax.xml,javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.adapters,javax.xml.bind.attachment,javax.xml.bind.helpers,javax.xml.bind.util,javax.xml.crypto,javax.xml.crypto.dom,javax.xml.crypto.dsig,javax.xml.crypto.dsig.dom,javax.xml.crypto.dsig.keyinfo,javax.xml.crypto.dsig.spec,javax.xml.datatype,javax.xml.namespace,javax.xml.parsers,javax.xml.soap,java
x.xml.stream,javax.xml.stream.events,javax.xml.stream.util,javax.xml.transform,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.transform.stax,javax.xml.transform.stream,javax.xml.validation,javax.xml.ws,javax.xml.ws.handler,javax.xml.ws.handler.soap,javax.xml.ws.http,javax.xml.ws.soap,javax.xml.ws.spi,javax.xml.xpath,org.ietf.jgss,org.omg.CORBA,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg.CORBA.TypeCodePackage,org.omg.CORBA.portable,org.omg.CORBA_2_3,org.omg.CORBA_2_3.portable,org.omg.CosNaming,org.omg.CosNaming.NamingContextExtPackage,org.omg.CosNaming.NamingContextPackage,org.omg.Dynamic,org.omg.DynamicAny,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage,org.omg.IOP,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage,org.omg.Messaging,org.omg.PortableInterceptor,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.PortableServer,org.omg.PortableServer.CurrentPackage,org.omg.PortableServer.POAManagerPackage,org.omg.PortableSe
rver.POAPackage,org.omg.PortableServer.ServantLocatorPackage,org.omg.PortableServer.portable,org.omg.SendingContext,org.omg.stub.java.rmi,org.w3c.dom,org.w3c.dom.bootstrap,org.w3c.dom.css,org.w3c.dom.events,org.w3c.dom.html,org.w3c.dom.ls,org.w3c.dom.ranges,org.w3c.dom.stylesheets,org.w3c.dom.traversal,org.w3c.dom.views,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers"),
systemProperty("org.apache.aries.proxy.weaving.enabled").value("none"),
// Bundles
@@ -86,13 +94,14 @@ public abstract class AbstractIntegratio
};
}
- private Option jta12Bundles() {
- return CoreOptions.composite(
+ private Option jta12Bundles() {
+ return CoreOptions.composite(
mavenBundle("javax.interceptor", "javax.interceptor-api", "1.2"),
mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.javax-inject", "1_2"),
mavenBundle("javax.el", "javax.el-api", "3.0.0"),
mavenBundle("javax.enterprise", "cdi-api", "1.2"),
mavenBundle("javax.transaction", "javax.transaction-api", "1.2")
- );
- }
+ );
+ }
+
}
\ No newline at end of file
Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java Wed Jul 8 10:49:21 2015
@@ -15,25 +15,18 @@
*/
package org.apache.aries.transaction.itests;
-import static org.junit.Assert.fail;
+import javax.inject.Inject;
import org.apache.aries.transaction.test.TestBean;
import org.junit.Test;
+import org.ops4j.pax.exam.util.Filter;
public class InvalidTranAttributeTest extends AbstractIntegrationTest {
-
- @Test
+ @Inject @Filter("(tranAttribute=MandatoryJtaAnnotated)")
+ TestBean bean;
+
+ @Test(expected=IllegalStateException.class)
public void testInvalid() throws Exception {
- TestBean bean = context().getService(TestBean.class, "(tranAttribute=Invalid)");
-
- //Test without client transaction - an exception is thrown because the bean is not
- //configured correctly, i.e. multiple transaction elements match to the same method
- //name.
- try {
- bean.insertRow("testWithoutClientTran", 1);
- fail("IllegalStateException not thrown");
- } catch (IllegalStateException e) {
- e.printStackTrace();
- }
+ bean.insertRow("testWithoutClientTran", 1);
}
}
Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java Wed Jul 8 10:49:21 2015
@@ -15,25 +15,25 @@
*/
package org.apache.aries.transaction.itests;
-import org.apache.aries.transaction.test.TestBean;
-import org.junit.Ignore;
-import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import javax.transaction.RollbackException;
-import javax.transaction.UserTransaction;
import java.sql.SQLException;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import javax.inject.Inject;
+import javax.transaction.RollbackException;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+import org.ops4j.pax.exam.util.Filter;
public class MandatoryAnnotatedTranAttributeTest extends AbstractIntegrationTest {
+ @Inject @Filter("(tranAttribute=MandatoryAnnotated)")
+ TestBean bean;
@Test
public void testMandatory() throws Exception {
- String prefix = "MTAT";
- TestBean bean = context().getService(TestBean.class, "(tranAttribute=MandatoryAnnotated)");
- UserTransaction tran = context().getService(UserTransaction.class);
-
+ String prefix = "MTAT";
//Test with client transaction - the user transaction is used to insert a row
int initialRows = bean.countRows();
Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java?rev=1689837&r1=1689836&r2=1689837&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java Wed Jul 8 10:49:21 2015
@@ -15,23 +15,25 @@
*/
package org.apache.aries.transaction.itests;
-import org.apache.aries.transaction.test.TestBean;
-import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import javax.transaction.RollbackException;
-import javax.transaction.UserTransaction;
import java.sql.SQLException;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import javax.inject.Inject;
+import javax.transaction.RollbackException;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+import org.ops4j.pax.exam.util.Filter;
public class MandatoryJtaAnnotatedTranAttributeTest extends AbstractIntegrationTest {
+ @Inject @Filter("(tranAttribute=MandatoryJtaAnnotated)")
+ TestBean bean;
@Test
public void testMandatory() throws Exception {
- String prefix = "MTAT";
- TestBean bean = context().getService(TestBean.class, "(tranAttribute=MandatoryJtaAnnotated)");
- UserTransaction tran = context().getService(UserTransaction.class);
+ String prefix = "MTAT";
//Test with client transaction - the user transaction is used to insert a row
int initialRows = bean.countRows();