Skip to content

Commit

Permalink
Update showcase to Spring Extension Beta 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Narloch authored and aslakknutsen committed Aug 30, 2012
1 parent feaef61 commit f8b0e75
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 161 deletions.
21 changes: 19 additions & 2 deletions spring/pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -73,6 +74,13 @@
<scope>test</scope>
</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>
Expand Down Expand Up @@ -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>
Expand Down
12 changes: 12 additions & 0 deletions spring/spring-hibernate/pom.xml
Expand Up @@ -76,6 +76,18 @@
<scope>test</scope>
</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>
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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;
Expand All @@ -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();
}

/**
Expand All @@ -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());

Expand All @@ -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());
Expand All @@ -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());
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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());
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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;
Expand All @@ -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();
}

/**
Expand All @@ -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);

Expand All @@ -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));
Expand All @@ -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());
Expand All @@ -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());
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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());
}
Expand Down
Expand Up @@ -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>
Expand Down
12 changes: 12 additions & 0 deletions spring/spring-jdbc/pom.xml
Expand Up @@ -61,6 +61,18 @@
<scope>test</scope>
</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>
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down
12 changes: 12 additions & 0 deletions spring/spring-jpa/pom.xml
Expand Up @@ -81,6 +81,18 @@
<scope>test</scope>
</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>
Expand Down

0 comments on commit f8b0e75

Please sign in to comment.