CCM NG: Some progress on the test bundle
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3602 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
abfa4c6ff7
commit
551c8c398d
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
<properties>
|
||||
<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>
|
||||
|
||||
<parent>
|
||||
|
|
@ -164,6 +166,13 @@
|
|||
</resource>
|
||||
</resources>-->
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/test/resources</directory>
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ import javax.persistence.EntityManager;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Module(entities = {org.libreccm.auditing.CcmRevision.class,
|
||||
org.libreccm.categorization.Category.class,
|
||||
org.libreccm.categorization.Categorization.class,
|
||||
org.libreccm.categorization.Category.class,
|
||||
org.libreccm.categorization.Domain.class,
|
||||
org.libreccm.categorization.DomainOwnership.class,
|
||||
org.libreccm.core.CcmObject.class,
|
||||
|
|
@ -46,13 +46,47 @@ import javax.persistence.EntityManager;
|
|||
org.libreccm.core.Role.class,
|
||||
org.libreccm.core.Subject.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 {
|
||||
|
||||
@Override
|
||||
public void install(final InstallEvent event) {
|
||||
final EntityManager entityManager = event.getEntityManager();
|
||||
|
||||
|
||||
final User user = new User();
|
||||
user.setScreenName("public-user");
|
||||
final PersonName name = new PersonName();
|
||||
|
|
@ -62,7 +96,7 @@ public class CcmCore implements CcmModule {
|
|||
final EmailAddress email = new EmailAddress();
|
||||
email.setAddress("public-user@localhost");
|
||||
user.addEmailAddress(email);
|
||||
|
||||
|
||||
entityManager.persist(user);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,9 +150,9 @@ public class CcmIntegrator implements Integrator {
|
|||
if (newModule) {
|
||||
final Statement statement = connection.createStatement();
|
||||
statement.execute(String.format(
|
||||
"INSERT INTO flyhydra_core.installed_modules "
|
||||
"INSERT INTO ccm_core.installed_modules "
|
||||
+ "(module_id, module_class_name, status) "
|
||||
+ "VALUES (%d, %s', 'NEW')",
|
||||
+ "VALUES (%d, '%s', 'NEW')",
|
||||
module.getName().hashCode(),
|
||||
module.getName()));
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ public class CcmIntegrator implements Integrator {
|
|||
final Statement query = connection.createStatement();
|
||||
final ResultSet result = query.executeQuery(
|
||||
String.format("SELECT module_class_name, status "
|
||||
+ "FROM flyhydra_core.installed_modules "
|
||||
+ "FROM ccm_core.installed_modules "
|
||||
+ "WHERE module_class_name = '%s'",
|
||||
module.getClass().getName()));
|
||||
System.out.printf("Checking status of module %s...\n",
|
||||
|
|
@ -208,7 +208,7 @@ public class CcmIntegrator implements Integrator {
|
|||
|
||||
final Statement statement = connection.createStatement();
|
||||
statement.addBatch(String.format(
|
||||
"DELETE FROM flyhydra_core.installed_modules "
|
||||
"DELETE FROM ccm_core.installed_modules "
|
||||
+ "WHERE module_class_name = '%s'",
|
||||
module.getClass().getName()));
|
||||
statement.executeBatch();
|
||||
|
|
|
|||
|
|
@ -265,8 +265,7 @@ public class ModuleInfo {
|
|||
return String.format("%s/%s",
|
||||
moduleInfo.getProperty(GROUP_ID),
|
||||
moduleInfo.
|
||||
getProperty(ARTIFACT_ID).replace(
|
||||
"-", "_"));
|
||||
getProperty(ARTIFACT_ID));
|
||||
} else {
|
||||
LOGGER.warn("The module data package was specified by the module "
|
||||
+ "annotation nore was an group id found in the module info"
|
||||
|
|
|
|||
|
|
@ -39,10 +39,10 @@ import org.apache.logging.log4j.Logger;
|
|||
public class ModuleManager {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ModuleManager.class
|
||||
ModuleManager.class
|
||||
);
|
||||
|
||||
@PersistenceContext(name = "FlyHydra")
|
||||
@PersistenceContext(name = "LibreCCM")
|
||||
private EntityManager entityManager;
|
||||
|
||||
private List<TreeNode> moduleNodes;
|
||||
|
|
@ -51,7 +51,7 @@ public class ModuleManager {
|
|||
public void initDependencyTree() {
|
||||
LOGGER.info("Finding modules");
|
||||
final ServiceLoader<CcmModule> modules = ServiceLoader.load(
|
||||
CcmModule.class);
|
||||
CcmModule.class);
|
||||
|
||||
LOGGER.info("Creating dependency tree these modules:");
|
||||
for (final CcmModule module : modules) {
|
||||
|
|
@ -83,9 +83,10 @@ public class ModuleManager {
|
|||
installEvent.setEntityManager(entityManager);
|
||||
|
||||
final InstalledModule installedModule = entityManager.find(
|
||||
InstalledModule.class, node.getModule().getClass().getName());
|
||||
InstalledModule.class,
|
||||
node.getModule().getClass().getName().hashCode());
|
||||
if (installedModule != null
|
||||
&& installedModule.getStatus() == ModuleStatus.NEW) {
|
||||
&& installedModule.getStatus() == ModuleStatus.NEW) {
|
||||
node.getModule().install(installEvent);
|
||||
installedModule.setStatus(ModuleStatus.INSTALLED);
|
||||
entityManager.merge(installedModule);
|
||||
|
|
@ -99,8 +100,8 @@ public class ModuleManager {
|
|||
node.getModule().getClass().getName());
|
||||
final Properties moduleInfo = getModuleInfo(node.getModule());
|
||||
LOGGER
|
||||
.info("Module group id: {}", moduleInfo.getProperty(
|
||||
"groupId"));
|
||||
.info("Module group id: {}", moduleInfo.getProperty(
|
||||
"groupId"));
|
||||
LOGGER.info("Module artifact id: {}", moduleInfo.getProperty(
|
||||
"artifactId"));
|
||||
LOGGER.info("Module version: {}", moduleInfo.getProperty("version"));
|
||||
|
|
@ -117,11 +118,11 @@ public class ModuleManager {
|
|||
// final String moduleInfoPath = String.format("/%s/module-info.properties",
|
||||
// module.getClass().getName().replace(".", "/"));
|
||||
final String moduleInfoPath = String.format(
|
||||
"/module-info/%s.properties",
|
||||
module.getClass().getName());
|
||||
"/module-info/%s.properties",
|
||||
module.getClass().getName());
|
||||
LOGGER.info("Path for module info: {}", moduleInfoPath);
|
||||
final InputStream stream = module.getClass().getResourceAsStream(
|
||||
moduleInfoPath);
|
||||
moduleInfoPath);
|
||||
if (stream == null) {
|
||||
LOGGER.warn("No module info found.");
|
||||
} else {
|
||||
|
|
@ -154,8 +155,8 @@ public class ModuleManager {
|
|||
System.out.printf("Checking status of module %s\n",
|
||||
node.getModule().getClass().getName());
|
||||
final InstalledModule installedModule = entityManager.find(
|
||||
InstalledModule.class, node.
|
||||
getModule().getClass().getName());
|
||||
InstalledModule.class, node.
|
||||
getModule().getClass().getName());
|
||||
LOGGER.info("Status of module {} ({}): {}",
|
||||
node.getModuleInfo().getModuleName(),
|
||||
node.getModule().getClass().getName(),
|
||||
|
|
@ -172,16 +173,16 @@ public class ModuleManager {
|
|||
node.getModuleInfo().getModuleName());
|
||||
if (node.getDependentModules().isEmpty()) {
|
||||
System.out.
|
||||
printf("Calling uninstall method of module %s...\n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
printf("Calling uninstall method of module %s...\n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
final UnInstallEvent unInstallEvent = new UnInstallEvent();
|
||||
unInstallEvent.setEntityManager(entityManager);
|
||||
node.getModule().uninstall(null);
|
||||
|
||||
} else {
|
||||
System.out.printf("There are other modules depending on "
|
||||
+ "module %s. Module can't be "
|
||||
+ "uninstalled. Depending modules:\n",
|
||||
+ "module %s. Module can't be "
|
||||
+ "uninstalled. Depending modules:\n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
for (final TreeNode dependent : node.getDependentModules()) {
|
||||
System.out.printf("\t%s\n",
|
||||
|
|
@ -193,9 +194,10 @@ public class ModuleManager {
|
|||
}
|
||||
} else {
|
||||
System.out.printf(
|
||||
"Module %s is *not* scheduled for uninstall.\n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
"Module %s is *not* scheduled for uninstall.\n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
create schema ccm_core;
|
||||
|
||||
create table ccm_core.application_types (
|
||||
resource_type_id int8 not null,
|
||||
container_group_id int8,
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -25,6 +25,7 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
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.junit.Arquillian;
|
||||
import org.jboss.arquillian.persistence.CleanupUsingScript;
|
||||
import org.jboss.arquillian.persistence.CreateSchema;
|
||||
import org.jboss.arquillian.persistence.PersistenceTest;
|
||||
import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
|
||||
|
|
@ -64,7 +66,7 @@ import org.libreccm.tests.categories.IntegrationTest;
|
|||
@RunWith(Arquillian.class)
|
||||
@PersistenceTest
|
||||
@Transactional(TransactionMode.COMMIT)
|
||||
@CreateSchema({"clean_schema.sql"})
|
||||
//@CreateSchema({"clean_schema.sql"})
|
||||
public class CcmModulesTest {
|
||||
|
||||
@PersistenceContext(name = "LibreCCM")
|
||||
|
|
@ -93,10 +95,10 @@ public class CcmModulesTest {
|
|||
@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) {
|
||||
|
|
@ -105,15 +107,18 @@ public class CcmModulesTest {
|
|||
}
|
||||
|
||||
return ShrinkWrap
|
||||
.create(WebArchive.class,
|
||||
"LibreCCM-org.libreccm.CcmModulesTest.war")
|
||||
.addAsLibraries(libs)
|
||||
.setWebXML(new File("src/main/webapp/WEB-INF/web.xml"))
|
||||
.addAsWebInfResource("test-persistence.xml")
|
||||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
|
||||
.create(WebArchive.class,
|
||||
"LibreCCM-org.libreccm.CcmModulesTest.war")
|
||||
.addAsLibraries(libs)
|
||||
.addPackage(IntegrationTest.class.getPackage())
|
||||
.setWebXML(new File("src/main/webapp/WEB-INF/web.xml"))
|
||||
//.addAsWebInfResource("test-persistence.xml", "persistence.xml")
|
||||
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
|
||||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@CleanupUsingScript("clean_schema.sql")
|
||||
public void verifyModules() throws SQLException {
|
||||
final Object dataSourceObj = entityManager.getEntityManagerFactory()
|
||||
.getProperties().get("javax.persistence.jtaDataSource");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
-- 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;
|
||||
Loading…
Reference in New Issue