CCM NG: Some progress on the test bundle

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3602 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-09-04 17:18:51 +00:00
parent abfa4c6ff7
commit 551c8c398d
11 changed files with 173 additions and 42 deletions

View File

@ -8,6 +8,8 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'Z</maven.build.timestamp.format>
</properties> </properties>
<parent> <parent>
@ -164,6 +166,13 @@
</resource> </resource>
</resources>--> </resources>-->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources> <testResources>
<testResource> <testResource>
<directory>src/test/resources</directory> <directory>src/test/resources</directory>

View File

@ -32,8 +32,8 @@ import javax.persistence.EntityManager;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@Module(entities = {org.libreccm.auditing.CcmRevision.class, @Module(entities = {org.libreccm.auditing.CcmRevision.class,
org.libreccm.categorization.Category.class,
org.libreccm.categorization.Categorization.class, org.libreccm.categorization.Categorization.class,
org.libreccm.categorization.Category.class,
org.libreccm.categorization.Domain.class, org.libreccm.categorization.Domain.class,
org.libreccm.categorization.DomainOwnership.class, org.libreccm.categorization.DomainOwnership.class,
org.libreccm.core.CcmObject.class, org.libreccm.core.CcmObject.class,
@ -46,7 +46,41 @@ import javax.persistence.EntityManager;
org.libreccm.core.Role.class, org.libreccm.core.Role.class,
org.libreccm.core.Subject.class, org.libreccm.core.Subject.class,
org.libreccm.core.User.class, org.libreccm.core.User.class,
org.libreccm.core.modules.InstalledModule.class}) org.libreccm.core.modules.InstalledModule.class,
org.libreccm.formbuilder.Component.class,
org.libreccm.formbuilder.DataDrivenSelect.class,
org.libreccm.formbuilder.FormSection.class,
org.libreccm.formbuilder.Listener.class,
org.libreccm.formbuilder.MetaObject.class,
org.libreccm.formbuilder.ObjectType.class,
org.libreccm.formbuilder.Option.class,
org.libreccm.formbuilder.PersistentDataQuery.class,
org.libreccm.formbuilder.ProcessListener.class,
org.libreccm.formbuilder.Widget.class,
org.libreccm.formbuilder.WidgetLabel.class,
org.libreccm.formbuilder.actions.ConfirmEmailListener.class,
org.libreccm.formbuilder.actions.ConfirmRedirectListener.class,
org.libreccm.formbuilder.actions.RemoteServerPostListener.class,
org.libreccm.formbuilder.actions.SimpleEmailListener.class,
org.libreccm.formbuilder.actions.TemplateEmailListener.class,
org.libreccm.formbuilder.actions.XmlEmailListener.class,
org.libreccm.messaging.Attachment.class,
org.libreccm.messaging.Message.class,
org.libreccm.messaging.MessageThread.class,
org.libreccm.notification.Digest.class,
org.libreccm.notification.Notification.class,
org.libreccm.notification.QueueItem.class,
org.libreccm.portal.Portal.class,
org.libreccm.portal.Portlet.class,
org.libreccm.runtime.Initalizer.class,
org.libreccm.search.lucene.Document.class,
org.libreccm.search.lucene.Index.class,
org.libreccm.web.Application.class,
org.libreccm.web.ApplicationType.class,
org.libreccm.web.Host.class,
org.libreccm.workflow.Task.class,
org.libreccm.workflow.UserTask.class,
org.libreccm.workflow.Workflow.class})
public class CcmCore implements CcmModule { public class CcmCore implements CcmModule {
@Override @Override

View File

@ -150,9 +150,9 @@ public class CcmIntegrator implements Integrator {
if (newModule) { if (newModule) {
final Statement statement = connection.createStatement(); final Statement statement = connection.createStatement();
statement.execute(String.format( statement.execute(String.format(
"INSERT INTO flyhydra_core.installed_modules " "INSERT INTO ccm_core.installed_modules "
+ "(module_id, module_class_name, status) " + "(module_id, module_class_name, status) "
+ "VALUES (%d, %s', 'NEW')", + "VALUES (%d, '%s', 'NEW')",
module.getName().hashCode(), module.getName().hashCode(),
module.getName())); module.getName()));
} }
@ -187,7 +187,7 @@ public class CcmIntegrator implements Integrator {
final Statement query = connection.createStatement(); final Statement query = connection.createStatement();
final ResultSet result = query.executeQuery( final ResultSet result = query.executeQuery(
String.format("SELECT module_class_name, status " String.format("SELECT module_class_name, status "
+ "FROM flyhydra_core.installed_modules " + "FROM ccm_core.installed_modules "
+ "WHERE module_class_name = '%s'", + "WHERE module_class_name = '%s'",
module.getClass().getName())); module.getClass().getName()));
System.out.printf("Checking status of module %s...\n", System.out.printf("Checking status of module %s...\n",
@ -208,7 +208,7 @@ public class CcmIntegrator implements Integrator {
final Statement statement = connection.createStatement(); final Statement statement = connection.createStatement();
statement.addBatch(String.format( statement.addBatch(String.format(
"DELETE FROM flyhydra_core.installed_modules " "DELETE FROM ccm_core.installed_modules "
+ "WHERE module_class_name = '%s'", + "WHERE module_class_name = '%s'",
module.getClass().getName())); module.getClass().getName()));
statement.executeBatch(); statement.executeBatch();

View File

@ -265,8 +265,7 @@ public class ModuleInfo {
return String.format("%s/%s", return String.format("%s/%s",
moduleInfo.getProperty(GROUP_ID), moduleInfo.getProperty(GROUP_ID),
moduleInfo. moduleInfo.
getProperty(ARTIFACT_ID).replace( getProperty(ARTIFACT_ID));
"-", "_"));
} else { } else {
LOGGER.warn("The module data package was specified by the module " LOGGER.warn("The module data package was specified by the module "
+ "annotation nore was an group id found in the module info" + "annotation nore was an group id found in the module info"

View File

@ -39,10 +39,10 @@ import org.apache.logging.log4j.Logger;
public class ModuleManager { public class ModuleManager {
private static final Logger LOGGER = LogManager.getLogger( private static final Logger LOGGER = LogManager.getLogger(
ModuleManager.class ModuleManager.class
); );
@PersistenceContext(name = "FlyHydra") @PersistenceContext(name = "LibreCCM")
private EntityManager entityManager; private EntityManager entityManager;
private List<TreeNode> moduleNodes; private List<TreeNode> moduleNodes;
@ -51,7 +51,7 @@ public class ModuleManager {
public void initDependencyTree() { public void initDependencyTree() {
LOGGER.info("Finding modules"); LOGGER.info("Finding modules");
final ServiceLoader<CcmModule> modules = ServiceLoader.load( final ServiceLoader<CcmModule> modules = ServiceLoader.load(
CcmModule.class); CcmModule.class);
LOGGER.info("Creating dependency tree these modules:"); LOGGER.info("Creating dependency tree these modules:");
for (final CcmModule module : modules) { for (final CcmModule module : modules) {
@ -83,9 +83,10 @@ public class ModuleManager {
installEvent.setEntityManager(entityManager); installEvent.setEntityManager(entityManager);
final InstalledModule installedModule = entityManager.find( final InstalledModule installedModule = entityManager.find(
InstalledModule.class, node.getModule().getClass().getName()); InstalledModule.class,
node.getModule().getClass().getName().hashCode());
if (installedModule != null if (installedModule != null
&& installedModule.getStatus() == ModuleStatus.NEW) { && installedModule.getStatus() == ModuleStatus.NEW) {
node.getModule().install(installEvent); node.getModule().install(installEvent);
installedModule.setStatus(ModuleStatus.INSTALLED); installedModule.setStatus(ModuleStatus.INSTALLED);
entityManager.merge(installedModule); entityManager.merge(installedModule);
@ -99,8 +100,8 @@ public class ModuleManager {
node.getModule().getClass().getName()); node.getModule().getClass().getName());
final Properties moduleInfo = getModuleInfo(node.getModule()); final Properties moduleInfo = getModuleInfo(node.getModule());
LOGGER LOGGER
.info("Module group id: {}", moduleInfo.getProperty( .info("Module group id: {}", moduleInfo.getProperty(
"groupId")); "groupId"));
LOGGER.info("Module artifact id: {}", moduleInfo.getProperty( LOGGER.info("Module artifact id: {}", moduleInfo.getProperty(
"artifactId")); "artifactId"));
LOGGER.info("Module version: {}", moduleInfo.getProperty("version")); LOGGER.info("Module version: {}", moduleInfo.getProperty("version"));
@ -117,11 +118,11 @@ public class ModuleManager {
// final String moduleInfoPath = String.format("/%s/module-info.properties", // final String moduleInfoPath = String.format("/%s/module-info.properties",
// module.getClass().getName().replace(".", "/")); // module.getClass().getName().replace(".", "/"));
final String moduleInfoPath = String.format( final String moduleInfoPath = String.format(
"/module-info/%s.properties", "/module-info/%s.properties",
module.getClass().getName()); module.getClass().getName());
LOGGER.info("Path for module info: {}", moduleInfoPath); LOGGER.info("Path for module info: {}", moduleInfoPath);
final InputStream stream = module.getClass().getResourceAsStream( final InputStream stream = module.getClass().getResourceAsStream(
moduleInfoPath); moduleInfoPath);
if (stream == null) { if (stream == null) {
LOGGER.warn("No module info found."); LOGGER.warn("No module info found.");
} else { } else {
@ -154,8 +155,8 @@ public class ModuleManager {
System.out.printf("Checking status of module %s\n", System.out.printf("Checking status of module %s\n",
node.getModule().getClass().getName()); node.getModule().getClass().getName());
final InstalledModule installedModule = entityManager.find( final InstalledModule installedModule = entityManager.find(
InstalledModule.class, node. InstalledModule.class, node.
getModule().getClass().getName()); getModule().getClass().getName());
LOGGER.info("Status of module {} ({}): {}", LOGGER.info("Status of module {} ({}): {}",
node.getModuleInfo().getModuleName(), node.getModuleInfo().getModuleName(),
node.getModule().getClass().getName(), node.getModule().getClass().getName(),
@ -172,16 +173,16 @@ public class ModuleManager {
node.getModuleInfo().getModuleName()); node.getModuleInfo().getModuleName());
if (node.getDependentModules().isEmpty()) { if (node.getDependentModules().isEmpty()) {
System.out. System.out.
printf("Calling uninstall method of module %s...\n", printf("Calling uninstall method of module %s...\n",
node.getModuleInfo().getModuleName()); node.getModuleInfo().getModuleName());
final UnInstallEvent unInstallEvent = new UnInstallEvent(); final UnInstallEvent unInstallEvent = new UnInstallEvent();
unInstallEvent.setEntityManager(entityManager); unInstallEvent.setEntityManager(entityManager);
node.getModule().uninstall(null); node.getModule().uninstall(null);
} else { } else {
System.out.printf("There are other modules depending on " System.out.printf("There are other modules depending on "
+ "module %s. Module can't be " + "module %s. Module can't be "
+ "uninstalled. Depending modules:\n", + "uninstalled. Depending modules:\n",
node.getModuleInfo().getModuleName()); node.getModuleInfo().getModuleName());
for (final TreeNode dependent : node.getDependentModules()) { for (final TreeNode dependent : node.getDependentModules()) {
System.out.printf("\t%s\n", System.out.printf("\t%s\n",
@ -193,9 +194,10 @@ public class ModuleManager {
} }
} else { } else {
System.out.printf( System.out.printf(
"Module %s is *not* scheduled for uninstall.\n", "Module %s is *not* scheduled for uninstall.\n",
node.getModuleInfo().getModuleName()); node.getModuleInfo().getModuleName());
} }
} }
} }
} }

View File

@ -1,6 +1,4 @@
create schema ccm_core;
create table ccm_core.application_types ( create table ccm_core.application_types (
resource_type_id int8 not null, resource_type_id int8 not null,
container_group_id int8, container_group_id int8,

View File

@ -0,0 +1,42 @@
<?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/db</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="verify"/>
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<!--
Properties for Hibernate Envers
We are using the ValidityAuditStrategy here because it is faster
when querying data than the DefaultStrategy
-->
<property name="org.hibernate.envers.audit_strategy"
value="org.hibernate.envers.strategy.ValidityAuditStrategy"/>
</properties>
</persistence-unit>
</persistence>

View File

@ -0,0 +1,42 @@
<?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/db</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="verify"/>
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<!--
Properties for Hibernate Envers
We are using the ValidityAuditStrategy here because it is faster
when querying data than the DefaultStrategy
-->
<property name="org.hibernate.envers.audit_strategy"
value="org.hibernate.envers.strategy.ValidityAuditStrategy"/>
</properties>
</persistence-unit>
</persistence>

View File

@ -25,6 +25,7 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -33,6 +34,7 @@ import static org.hamcrest.CoreMatchers.*;
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.persistence.CleanupUsingScript;
import org.jboss.arquillian.persistence.CreateSchema; import org.jboss.arquillian.persistence.CreateSchema;
import org.jboss.arquillian.persistence.PersistenceTest; import org.jboss.arquillian.persistence.PersistenceTest;
import org.jboss.arquillian.transaction.api.annotation.TransactionMode; import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
@ -64,7 +66,7 @@ import org.libreccm.tests.categories.IntegrationTest;
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
@PersistenceTest @PersistenceTest
@Transactional(TransactionMode.COMMIT) @Transactional(TransactionMode.COMMIT)
@CreateSchema({"clean_schema.sql"}) //@CreateSchema({"clean_schema.sql"})
public class CcmModulesTest { public class CcmModulesTest {
@PersistenceContext(name = "LibreCCM") @PersistenceContext(name = "LibreCCM")
@ -93,10 +95,10 @@ public class CcmModulesTest {
@Deployment @Deployment
public static WebArchive createDeployment() { public static WebArchive createDeployment() {
final PomEquippedResolveStage pom = Maven final PomEquippedResolveStage pom = Maven
.resolver() .resolver()
.loadPomFromFile("pom.xml"); .loadPomFromFile("pom.xml");
final PomEquippedResolveStage dependencies = pom final PomEquippedResolveStage dependencies = pom
.importCompileAndRuntimeDependencies(); .importCompileAndRuntimeDependencies();
final File[] libs = dependencies.resolve().withTransitivity().asFile(); final File[] libs = dependencies.resolve().withTransitivity().asFile();
for (File lib : libs) { for (File lib : libs) {
@ -105,15 +107,18 @@ public class CcmModulesTest {
} }
return ShrinkWrap return ShrinkWrap
.create(WebArchive.class, .create(WebArchive.class,
"LibreCCM-org.libreccm.CcmModulesTest.war") "LibreCCM-org.libreccm.CcmModulesTest.war")
.addAsLibraries(libs) .addAsLibraries(libs)
.setWebXML(new File("src/main/webapp/WEB-INF/web.xml")) .addPackage(IntegrationTest.class.getPackage())
.addAsWebInfResource("test-persistence.xml") .setWebXML(new File("src/main/webapp/WEB-INF/web.xml"))
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); //.addAsWebInfResource("test-persistence.xml", "persistence.xml")
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
} }
@Test @Test
@CleanupUsingScript("clean_schema.sql")
public void verifyModules() throws SQLException { public void verifyModules() throws SQLException {
final Object dataSourceObj = entityManager.getEntityManagerFactory() final Object dataSourceObj = entityManager.getEntityManagerFactory()
.getProperties().get("javax.persistence.jtaDataSource"); .getProperties().get("javax.persistence.jtaDataSource");

View File

@ -1,6 +1,6 @@
-- Used by the org.libreccm.core.modules.CcmModulesTest to clean up the -- Used by the org.libreccm.core.modules.CcmModulesTest to clean up the
-- schema before the test -- schema after the test
DROP SCHEMA IF EXISTS ccm_core; DROP SCHEMA IF EXISTS ccm_core CASCADE;
DROP SEQUENCE IF EXISTS hibernate_sequence; DROP SEQUENCE IF EXISTS hibernate_sequence;