CCM NG: Fixed some problems with Arquillian, dumping test data did not work. Disabled tempoarily. Fixed some minor issues in the CcmObjectRepository classes

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3477 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-06-11 12:10:20 +00:00
parent cbe2b198fd
commit 09169249ea
8 changed files with 226 additions and 47 deletions

View File

@ -570,6 +570,87 @@
</plugins>
</build>
</profile>
<profile>
<id>wildfly8-remote-h2-mem</id>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>8.2.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>0.7.4.201502262128</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-jacoco</artifactId>
<version>1.0.0.Alpha7</version>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>/src/test/resources</directory>
</testResource>
<testResource>
<directory>/src/test/resources-wildfly8-remote-h2-mem</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>de.jpdigital</groupId>
<artifactId>hibernate4-ddl-maven-plugin</artifactId>
<configuration>
<dialects>
<param>h2</param>
<param>mysql5_innodb</param>
<param>postgresql9</param>
</dialects>
<packages>
<param>de.jpdigital.research.accessibilitystudy</param>
</packages>
<useEnvers>true</useEnvers>
</configuration>
<executions>
<execution>
<goals>
<goal>gen-ddl</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<forkMode>always</forkMode>
<forkCount>999</forkCount>
<reuseForks>true</reuseForks>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<jboss.home>${project.basedir}/target/wildfly-8.2.0.Final</jboss.home>
<module.path>${project.basedir}/target/wildfly-8.2.0.Final/modules</module.path>
</systemPropertyVariables>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<groups>
org.libreccm.tests.categories.UnitTest,
org.libreccm.tests.categories.IntegrationTest
</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -35,6 +35,9 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
@Override
public boolean isNew(final CcmObject entity) {
if (entity == null) {
throw new IllegalArgumentException("Entity can't be null");
}
return entity.getObjectId() == 0;
}

View File

@ -91,10 +91,10 @@ public class CcmObjectRepositoryTest {
@Deployment
public static WebArchive createDeployment() {
final PomEquippedResolveStage pom = Maven
.resolver()
.loadPomFromFile("pom.xml");
.resolver()
.loadPomFromFile("pom.xml");
final PomEquippedResolveStage dependencies = pom
.importCompileAndRuntimeDependencies();
.importCompileAndRuntimeDependencies();
final File[] libs = dependencies.resolve().withTransitivity().asFile();
for (File lib : libs) {
@ -103,21 +103,24 @@ public class CcmObjectRepositoryTest {
}
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war")
.addPackage(CcmObject.class.getPackage())
.addPackage(org.libreccm.categorization.Category.class.getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
.addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class.getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addAsLibraries(libs)
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
.create(WebArchive.class,
"LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war").
addPackage(CcmObject.class.getPackage())
.addPackage(org.libreccm.categorization.Category.class.
getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class.
getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addAsLibraries(libs)
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Test
@ -132,7 +135,23 @@ public class CcmObjectRepositoryTest {
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@InSequence(4)
public void datasetOnly() {
System.out.println("Dataset loaded successfully.");
}
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-changed.json")
@InSequence(4)
public void datasetOnly2() {
System.out.println("Dataset loaded successfully.");
}
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@InSequence(5)
public void entityManagerFindCcmObjectByLongPrimitive() {
final CcmObject obj1 = entityManager.find(CcmObject.class, -10L);
@ -154,16 +173,20 @@ public class CcmObjectRepositoryTest {
assertThat(none, is(nullValue()));
}
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@InSequence(6)
public void entityManagerFindCcmObjectByLongClass() {
final CcmObject obj1 = entityManager.find(CcmObject.class, new Long(-10L));
final CcmObject obj2 = entityManager.find(CcmObject.class, new Long(-20L));
final CcmObject obj3 = entityManager.find(CcmObject.class, new Long(-30L));
final CcmObject none = entityManager.find(CcmObject.class, new Long(-999L));
final CcmObject obj1 = entityManager.find(CcmObject.class,
new Long(-10L));
final CcmObject obj2 = entityManager.find(CcmObject.class,
new Long(-20L));
final CcmObject obj3 = entityManager.find(CcmObject.class,
new Long(-30L));
final CcmObject none = entityManager.find(CcmObject.class, new Long(
-999L));
assertThat(obj1, is(not(nullValue())));
assertThat(obj1.getObjectId(), is(-10L));
@ -182,7 +205,7 @@ public class CcmObjectRepositoryTest {
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@InSequence(10)
public void findCcmObjectById() {
final CcmObject obj1 = ccmObjectRepository.findById(-10L);
@ -207,7 +230,7 @@ public class CcmObjectRepositoryTest {
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@InSequence(10)
public void findAllCcmObjects() {
final List<CcmObject> objects = ccmObjectRepository.findAll();
@ -217,9 +240,9 @@ public class CcmObjectRepositoryTest {
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@ShouldMatchDataSet(value
= "datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-new.json",
= "datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-new.json",
excludeColumns = {"object_id"})
@InSequence(300)
public void saveNewCcmObject() {
@ -231,9 +254,9 @@ public class CcmObjectRepositoryTest {
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@ShouldMatchDataSet(value
= "datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-changed.json",
= "datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-changed.json",
excludeColumns = {"object_id"})
@InSequence(400)
public void saveChangedCcmObject() {
@ -243,7 +266,7 @@ public class CcmObjectRepositoryTest {
ccmObjectRepository.save(obj);
}
@Test(expected = EJBTransactionRolledbackException.class)
@Test(expected = IllegalArgumentException.class)
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(500)
public void saveNullValue() {
@ -252,9 +275,9 @@ public class CcmObjectRepositoryTest {
@Test
@UsingDataSet(
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
"datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json")
@ShouldMatchDataSet(value
= "datasets/org/libreccm/core/CcmObjectRepositoryTest/after-delete.json",
= "datasets/org/libreccm/core/CcmObjectRepositoryTest/after-delete.json",
excludeColumns = {"object_id"})
@InSequence(600)
public void deleteCcmObject() {
@ -263,7 +286,7 @@ public class CcmObjectRepositoryTest {
ccmObjectRepository.delete(obj);
}
@Test(expected = EJBTransactionRolledbackException.class)
@Test(expected = IllegalArgumentException.class)
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(700)
public void deleteNullValue() {

View File

@ -19,13 +19,6 @@
package org.libreccm.core;
import org.dbunit.DatabaseUnitException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.operation.DatabaseOperation;
import org.h2.tools.RunScript;
import org.jboss.arquillian.persistence.core.data.descriptor.Format;
import org.jboss.arquillian.persistence.dbunit.dataset.DataSetBuilder;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@ -34,18 +27,22 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.libreccm.tests.categories.UnitTest;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.operation.DatabaseOperation;
import org.h2.tools.RunScript;
import org.jboss.arquillian.persistence.core.data.descriptor.Format;
import org.jboss.arquillian.persistence.dbunit.dataset.DataSetBuilder;
import static org.junit.Assert.*;
/**
*

View File

@ -23,7 +23,7 @@ import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.operation.DatabaseOperation;
import org.h2.tools.RunScript;
//import org.h2.tools.RunScript;
import org.jboss.arquillian.persistence.core.data.descriptor.Format;
import org.jboss.arquillian.persistence.dbunit.dataset.DataSetBuilder;
import org.junit.Test;
@ -36,6 +36,7 @@ import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.h2.tools.RunScript;
/**
*

View File

@ -10,6 +10,9 @@
<extension qualifier="persistence">
<property name="defaultDataSource">java:/jboss/datasources/ExampleDS</property>
<!--<property name="javaVmArguments">
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
</property>-->
<!--
Disable automatic cleanup, does not work because of referential
@ -17,7 +20,7 @@
-->
<property name="defaultCleanupPhase">NONE</property>
<property name="dumpData">true</property>
<property name="dumpData">false</property>
<property name="dumpDirectory">target</property>
</extension>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd" >
<engine>
<property name="deploymentExportPath">target/deployments</property>
</engine>
<defaultProtocol type="Servlet 3.0"/>
<!--<property name="javaVmArguments">
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
</property>-->
<extension qualifier="persistence">
<property name="defaultDataSource">java:/comp/env/jdbc/ccm-core-test/h2/mem</property>
<!--
Disable automatic cleanup, does not work because of referential
integrity constrains.
-->
<property name="defaultCleanupPhase">NONE</property>
<property name="dumpData">true</property>
<property name="dumpDirectory">target</property>
</extension>
<extension qualifier="persistence-dbunit">
<property name="defaultDataSetFormat">json</property>
<property name="datatypeFactory">org.dbunit.ext.h2.H2DataTypeFactory</property>
<property name="excludePoi">true</property>
</extension>
<extension qualifier="persistence-script">
<property name="scriptsToExecuteAfterTest">scripts/h2-cleanup.sql</property>
</extension>
</arquillian>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
author: Jens Pelzetter
-->
<persistence
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="LibreCCM" transaction-type="JTA">
<!--
Enforce JPA provider
Not really necessary here because we don't use any Hibernate
specific features, but makes it easier to manage to database
creation scripts.
-->
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/comp/env/jdbc/ccm-core-test/h2/mem</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="hibernate.connection.autocommit" value="false" />
</properties>
</persistence-unit>
</persistence>