Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-1782

@UsingDataSet/@ShouldMatchDataSet always makes test succeed

XMLWordPrintable

      <?xml version="1.0" encoding="UTF-8"?>
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xsi:schemaLocation="
              http://maven.apache.org/POM/4.0.0
              http://maven.apache.org/xsd/maven-4.0.0.xsd">
      	<modelVersion>4.0.0</modelVersion>
      
      	<groupId>fi.affecto.marela</groupId>
      	<artifactId>arq-concept</artifactId>
      	<version>1.0.0-SNAPSHOT</version>
      	<packaging>jar</packaging>
      
      	<properties>
      		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      		<browser>chrome</browser>
      	</properties>
      
      	<dependencyManagement>
      		<dependencies>
      			<dependency>
      				<groupId>org.jboss.arquillian</groupId>
      				<artifactId>arquillian-bom</artifactId>
      				<version>1.1.4.Final</version>
      				<scope>import</scope>
      				<type>pom</type>
      			</dependency>
      			<dependency>
      				<groupId>org.jboss.arquillian.extension</groupId>
      				<artifactId>arquillian-drone-bom</artifactId>
      				<version>1.3.0.Final</version>
      				<type>pom</type>
      				<scope>import</scope>
      			</dependency>
      			<dependency>
      				<groupId>org.jboss.arquillian.selenium</groupId>
      				<artifactId>selenium-bom</artifactId>
      				<version>2.41.0</version>
      				<type>pom</type>
      				<scope>import</scope>
      			</dependency>
      		</dependencies>
      	</dependencyManagement>
      
      	<dependencies>
      		<dependency>
      			<groupId>junit</groupId>
      			<artifactId>junit</artifactId>
      			<version>4.11</version>
      			<scope>test</scope>
      		</dependency>
      		<dependency>
      			<groupId>org.jboss.arquillian.junit</groupId>
      			<artifactId>arquillian-junit-container</artifactId>
      			<scope>test</scope>
      		</dependency>
      		<dependency>
      			<groupId>org.hibernate</groupId>
      			<artifactId>hibernate-jpamodelgen</artifactId>
      			<version>4.3.5.Final</version>
      			<scope>provided</scope>
      		</dependency>
      		<dependency>
      			<groupId>org.jboss.arquillian.graphene</groupId>
      			<artifactId>graphene-webdriver</artifactId>
      			<version>2.0.2.Final</version>
      			<type>pom</type>
      			<scope>test</scope>
      		</dependency>
      		<dependency>
      			<groupId>org.jboss.arquillian.extension</groupId>
      			<artifactId>arquillian-persistence-core</artifactId>
      			<version>1.0.0.Alpha7</version>
      		</dependency>
      		<dependency>
      			<groupId>org.jboss.arquillian.extension</groupId>
      			<artifactId>arquillian-persistence-dbunit</artifactId>
      			<version>1.0.0.Alpha7</version>
      		</dependency>
      	</dependencies>
      
      	<profiles>
      		<profile>
      			<id>arq-wildfly</id>
      			<dependencies>
      				<dependency>
      					<groupId>org.jboss.spec</groupId>
      					<artifactId>jboss-javaee-7.0</artifactId>
      					<version>1.0.0.Final</version>
      					<type>pom</type>
      					<scope>provided</scope>
      				</dependency>
      				<dependency>
      					<groupId>org.wildfly</groupId>
      					<artifactId>wildfly-arquillian-container-remote</artifactId>
      					<version>8.1.0.CR2</version>
      					<scope>test</scope>
      				</dependency>
      				<dependency>
      					<groupId>org.jboss.arquillian.protocol</groupId>
      					<artifactId>arquillian-protocol-servlet</artifactId>
      					<scope>test</scope>
      				</dependency>
      			</dependencies>
      		</profile>
      	</profiles>
      
      
      	<build>
      		<plugins>
      			<plugin>
      				<artifactId>maven-compiler-plugin</artifactId>
      				<version>2.3.2</version>
      				<configuration>
      					<source>1.7</source>
      					<target>1.7</target>
      				</configuration>
      			</plugin>
      		</plugins>
      		<testResources>
      			<testResource>
      				<directory>src/test/resources</directory>
      				<filtering>true</filtering>
      			</testResource>
      		</testResources>
      	</build>
      </project>
      
      package fi.affecto.marela.test;
      
      import javax.inject.Inject;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import javax.transaction.UserTransaction;
      
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.arquillian.persistence.ShouldMatchDataSet;
      import org.jboss.arquillian.persistence.UsingDataSet;
      import org.jboss.arquillian.transaction.api.annotation.Transactional;
      import org.jboss.shrinkwrap.api.Archive;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.EmptyAsset;
      import org.jboss.shrinkwrap.api.spec.WebArchive;
      import org.junit.Assert;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      import fi.affecto.marela.jpa.Game;
      
      @RunWith(Arquillian.class)
      public class PersistenceExtensionTest
      {
      
         @Deployment
         public static Archive<?> createDeployment()
         {
            return ShrinkWrap.create(WebArchive.class, "test.war").addPackage(Game.class.getPackage())
               .addAsResource("persistence.xml", "META-INF/persistence.xml")
               .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");      
         }
      
         @PersistenceContext
         EntityManager em;
      
         @Inject
         UserTransaction utx;
      
         @Test
         public void testA() throws Exception
         {
            Assert.assertNotNull(em);
            utx.begin();
      //      em.joinTransaction();
            Game g = new Game();
            g.setId(666L);
            g.setTitle("x");
            Assert.assertFalse(em.contains(g));
            g = em.merge(g);
            Assert.assertTrue(em.contains(g));
            utx.rollback();
         }
         
         @Test
         @Transactional
         public void testB() throws Exception
         {
            Assert.assertNotNull(em);
            Game g = new Game();
            g.setId(666L);
            g.setTitle("x");
            Assert.assertFalse(em.contains(g));
            g = em.merge(g);
            Assert.assertTrue(em.contains(g));
         }
      
      
         @Test
      //   @UsingDataSet("games.yml")
      //   @ShouldMatchDataSet("games-check.yml")
         @Transactional
         public void testC() throws Exception
         {
            Assert.assertTrue(false);
         }
      
      }
      

      testC succeeds if the annotations are uncommented.
      Furthermore, there is something strange with the em/transactions, the persistence works even if the em doesn't join the transaction and the em complains of a detached instance if merge() is switched for persist()

              bartosz-1 Bartosz Majsak
              nickarls Nicklas Karlsson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: