Permalink
Browse files

Update showcase to Spring Extension Beta 1.

  • Loading branch information...
1 parent feaef61 commit f8b0e75cd266b4b029e47aac781189c8ec93d64a Jakub Narloch committed with aslakknutsen Aug 30, 2012
View
@@ -36,8 +36,9 @@
<properties>
<!-- Arquillian version -->
- <version.arquillian>1.0.1.Final</version.arquillian>
- <version.arquillian.spring>1.0.0.Alpha2</version.arquillian.spring>
+ <version.arquillian>1.0.2.Final</version.arquillian>
+ <version.arquillian.spring>1.0.0.Beta1</version.arquillian.spring>
+ <version.arquillian.transaction>1.0.0.Alpha1</version.arquillian.transaction>
<!-- Test related -->
<version.junit_junit>4.8.1</version.junit_junit>
@@ -74,6 +75,13 @@
</dependency>
<dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-spring</artifactId>
+ <version>${version.arquillian.spring}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${version.spring_framework}</version>
@@ -109,6 +117,15 @@
<version>${version.spring_framework}</version>
</dependency>
+ <!-- Arquillian Transaction -->
+ <dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-bom</artifactId>
+ <version>${version.arquillian.transaction}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
@@ -77,6 +77,18 @@
</dependency>
<dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
@@ -24,6 +24,7 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.spring.integration.test.annotation.SpringConfiguration;
+import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.After;
import org.junit.Test;
@@ -46,6 +47,7 @@
* @author <a href="mailto:jmnarloch@gmail.com">Jakub Narloch</a>
*/
@RunWith(Arquillian.class)
+@Transactional(manager = "txManager")
@SpringConfiguration("applicationContext.xml")
public class HibernateStockRepositoryTestCase {
@@ -67,7 +69,7 @@ public static Archive createTestArchive() {
private StockRepository stockRepository;
/**
- * <p>{@link org.hibernate.SessionFactory} instance used by tests.</p>
+ * <p>{@link SessionFactory} instance used by tests.</p>
*/
@Autowired
private SessionFactory sessionFactory;
@@ -91,9 +93,7 @@ public Session getSession() {
public void tearDown() throws Exception {
// deletes all records from database
- getSession().getTransaction().begin();
getSession().createQuery("delete from Stock").executeUpdate();
- getSession().getTransaction().commit();
}
/**
@@ -105,16 +105,13 @@ public void testSave() {
Stock acme = createStock("Acme", "ACM", 123.21D, new Date());
Stock redhat = createStock("Red Hat", "RHC", 59.61D, new Date());
- getSession().getTransaction().begin();
-
stockRepository.save(acme);
stockRepository.save(redhat);
assertTrue("The stock id hasn't been assigned.", acme.getId() > 0);
assertTrue("The stock id hasn't been assigned.", redhat.getId() > 0);
List<Stock> stocks = retrieveAllStocks(getSession());
- getSession().getTransaction().commit();
assertEquals("Incorrect number of created stocks, 2 were expected.", 2, stocks.size());
@@ -128,8 +125,6 @@ public void testSave() {
@Test
public void testUpdate() throws Exception {
- getSession().getTransaction().begin();
-
runScript(getSession(), "insert.sql");
List<Stock> stocks = retrieveAllStocks(getSession());
@@ -141,8 +136,6 @@ public void testUpdate() throws Exception {
stocks = retrieveAllStocks(getSession());
- getSession().getTransaction().commit();
-
assertEquals("The stock symbol hasn't been updated.", acme.getSymbol(), stocks.get(0).getSymbol());
}
@@ -152,15 +145,11 @@ public void testUpdate() throws Exception {
@Test
public void testGet() throws Exception {
- getSession().getTransaction().begin();
-
runScript(getSession(), "insert.sql");
Stock acme = createStock("Acme", "ACM", 123.21D, new Date());
Stock result = stockRepository.get(1L);
- getSession().getTransaction().commit();
-
assertNotNull("Method returned null result.", result);
assertStock(acme, result);
}
@@ -171,16 +160,12 @@ public void testGet() throws Exception {
@Test
public void testGetBySymbol() throws Exception {
- getSession().getTransaction().begin();
-
runScript(getSession(), "insert.sql");
Stock acme = createStock("Acme", "ACM", 123.21D, new Date());
Stock result = stockRepository.getBySymbol(acme.getSymbol());
- getSession().getTransaction().commit();
-
assertNotNull("Method returned null result.", result);
assertStock(acme, result);
}
@@ -190,14 +175,11 @@ public void testGetBySymbol() throws Exception {
*/
@Test
public void testGetAll() throws Exception {
- getSession().getTransaction().begin();
runScript(getSession(), "insert.sql");
List<Stock> result = stockRepository.getAll();
- getSession().getTransaction().commit();
-
assertNotNull("Method returned null result.", result);
assertEquals("Incorrect number of elements.", 2, result.size());
}
@@ -24,6 +24,7 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.spring.integration.test.annotation.SpringConfiguration;
+import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.After;
import org.junit.Test;
@@ -46,6 +47,7 @@
* @author <a href="mailto:jmnarloch@gmail.com">Jakub Narloch</a>
*/
@RunWith(Arquillian.class)
+@Transactional(manager = "txManager")
@SpringConfiguration("applicationContext.xml")
public class DefaultStockServiceTestCase {
@@ -67,7 +69,7 @@ public static Archive createTestArchive() {
private StockService stockService;
/**
- * <p>{@link org.hibernate.SessionFactory} instance used by tests.</p>
+ * <p>{@link SessionFactory} instance used by tests.</p>
*/
@Autowired
private SessionFactory sessionFactory;
@@ -91,9 +93,7 @@ public Session getSession() {
public void tearDown() throws Exception {
// deletes all records from database
- getSession().getTransaction().begin();
getSession().createQuery("delete from Stock").executeUpdate();
- getSession().getTransaction().commit();
}
/**
@@ -105,8 +105,6 @@ public void testSave() {
Stock acme = createStock("Acme", "ACM", 123.21D, new Date());
Stock redhat = createStock("Red Hat", "RHC", 59.61D, new Date());
- getSession().getTransaction().begin();
-
stockService.save(acme);
stockService.save(redhat);
@@ -115,8 +113,6 @@ public void testSave() {
List<Stock> stocks = retrieveAllStocks(getSession());
- getSession().getTransaction().commit();
-
assertEquals("Incorrect number of created stocks, 2 were expected.", 2, stocks.size());
assertStock(acme, stocks.get(0));
@@ -129,8 +125,6 @@ public void testSave() {
@Test
public void testUpdate() throws Exception {
- getSession().getTransaction().begin();
-
runScript(getSession(), "insert.sql");
List<Stock> stocks = retrieveAllStocks(getSession());
@@ -142,8 +136,6 @@ public void testUpdate() throws Exception {
stocks = retrieveAllStocks(getSession());
- getSession().getTransaction().commit();
-
assertEquals("The stock symbol hasn't been updated.", acme.getSymbol(), stocks.get(0).getSymbol());
}
@@ -153,15 +145,12 @@ public void testUpdate() throws Exception {
@Test
public void testGet() throws Exception {
- getSession().getTransaction().begin();
runScript(getSession(), "insert.sql");
Stock acme = createStock("Acme", "ACM", 123.21D, new Date());
Stock result = stockService.get(1L);
- getSession().getTransaction().commit();
-
assertNotNull("Method returned null result.", result);
assertStock(acme, result);
}
@@ -172,15 +161,12 @@ public void testGet() throws Exception {
@Test
public void testGetBySymbol() throws Exception {
- getSession().getTransaction().begin();
runScript(getSession(), "insert.sql");
Stock acme = createStock("Acme", "ACM", 123.21D, new Date());
Stock result = stockService.getBySymbol(acme.getSymbol());
- getSession().getTransaction().commit();
-
assertNotNull("Method returned null result.", result);
assertStock(acme, result);
}
@@ -191,13 +177,10 @@ public void testGetBySymbol() throws Exception {
@Test
public void testGetAll() throws Exception {
- getSession().getTransaction().begin();
runScript(getSession(), "insert.sql");
List<Stock> result = stockService.getAll();
- getSession().getTransaction().commit();
-
assertNotNull("Method returned null result.", result);
assertEquals("Incorrect number of elements.", 2, result.size());
}
@@ -31,7 +31,6 @@
</property>
<property name="hibernateProperties">
<value>
- hibernate.current_session_context_class=thread
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=create-drop
</value>
@@ -62,6 +62,18 @@
</dependency>
<dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
@@ -22,6 +22,7 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.spring.integration.test.annotation.SpringConfiguration;
+import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.After;
import org.junit.Test;
@@ -46,6 +47,7 @@
* @author <a href="mailto:jmnarloch@gmail.com">Jakub Narloch</a>
*/
@RunWith(Arquillian.class)
+@Transactional(manager = "txManager")
@SpringConfiguration("applicationContext.xml")
public class JdbcStockRepositoryTestCase {
@@ -22,6 +22,7 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.spring.integration.test.annotation.SpringConfiguration;
+import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.After;
import org.junit.Test;
@@ -46,6 +47,7 @@
* @author <a href="mailto:jmnarloch@gmail.com">Jakub Narloch</a>
*/
@RunWith(Arquillian.class)
+@Transactional(manager = "txManager")
@SpringConfiguration("applicationContext.xml")
public class DefaultStockServiceTestCase {
@@ -82,6 +82,18 @@
</dependency>
<dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.extension</groupId>
+ <artifactId>arquillian-transaction-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Oops, something went wrong. Retry.

0 comments on commit f8b0e75

Please sign in to comment.