From d2bfec2a1be4a2a81d4dbd532e9a8f6ed716bfc5 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 2 Feb 2016 08:28:11 +0000 Subject: [PATCH] CCM NG: Setup for registry git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3835 8810af33-2d31-482b-a856-94f89814c4df --- ccm-bundle-devel-wildfly/pom.xml | 63 ++++++++ .../categorization/RegistrySetup.java | 54 +++++++ .../RegistrySetupDatasetsTest.java | 62 ++++++++ .../categorization/RegistrySetupTest.java | 143 ++++++++++++++++++ .../RegistrySetupTest/after-setup.xml | 12 ++ 5 files changed, 334 insertions(+) create mode 100644 ccm-bundle-devel-wildfly/pom.xml create mode 100644 ccm-core/src/main/java/org/libreccm/categorization/RegistrySetup.java create mode 100644 ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupDatasetsTest.java create mode 100644 ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupTest.java create mode 100644 ccm-core/src/test/resources/datasets/org/libreccm/categorization/RegistrySetupTest/after-setup.xml diff --git a/ccm-bundle-devel-wildfly/pom.xml b/ccm-bundle-devel-wildfly/pom.xml new file mode 100644 index 000000000..dc22952cf --- /dev/null +++ b/ccm-bundle-devel-wildfly/pom.xml @@ -0,0 +1,63 @@ + + + + + UTF-8 + + + 4.0.0 + + + org.libreccm + libreccm-parent + 7.0.0-SNAPSHOT + + + org.libreccm + ccm-bundle-devel-wildfly + + ear + + LibreCCM Devel Bundle for Wildfly + http://www.libreccm.org/bundles/devel/wildfly + + + + org.libreccm + ccm-bundle-devel-wildfly-web + ${project.parent.version} + war + + + + + libreccm-devel-7.0.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-ear-plugin + + + 7 + + lib + no-version + + + org.libreccm + ccm-bundle-devel-wildfly-web + /libreccm + + + + + + + + diff --git a/ccm-core/src/main/java/org/libreccm/categorization/RegistrySetup.java b/ccm-core/src/main/java/org/libreccm/categorization/RegistrySetup.java new file mode 100644 index 000000000..9014d7ef6 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/categorization/RegistrySetup.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.categorization; + +import org.libreccm.configuration.ConfigurationConstants; +import org.libreccm.modules.InstallEvent; + +import javax.persistence.EntityManager; + +/** + * + * @author Jens Pelzetter + */ +public class RegistrySetup { + + private final EntityManager entityManager; + + public RegistrySetup(final InstallEvent event) { + this.entityManager = event.getEntityManager(); + } + + public void setup() { + final Domain registry = new Domain(); + registry.setDomainKey(ConfigurationConstants.REGISTRY_DOMAIN); + registry.setVersion("1.0"); + registry.setDisplayName(ConfigurationConstants.REGISTRY_DOMAIN); + + final Category root = new Category(); + root.setName(ConfigurationConstants.REGISTRY_DOMAIN + "-root"); + root.setDisplayName(ConfigurationConstants.REGISTRY_DOMAIN + "-root"); + + registry.setRoot(root); + + entityManager.persist(root); + entityManager.persist(registry); + } + +} diff --git a/ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupDatasetsTest.java b/ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupDatasetsTest.java new file mode 100644 index 000000000..f579ed543 --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupDatasetsTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.categorization; + +import static org.libreccm.testutils.DatasetType.*; + +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.libreccm.tests.categories.UnitTest; +import org.libreccm.testutils.DatasetType; +import org.libreccm.testutils.DatasetsVerifier; + +import java.util.Arrays; +import java.util.Collection; + +/** + * + * @author Jens Pelzetter + */ +@RunWith(Parameterized.class) +@Category(UnitTest.class) +public class RegistrySetupDatasetsTest extends DatasetsVerifier { + + @Parameterized.Parameters(name = "Dataset {0}") + public static Collection data() { + return Arrays.asList(new String[]{ + "/datasets/org/libreccm/categorization/RegistrySetupTest/after-setup.xml" + }); + } + + public RegistrySetupDatasetsTest(final String datasetPath) { + super(datasetPath); + } + + @Override + public String[] getSchemas() { + return new String[]{"ccm_core"}; + } + + @Override + public DatasetType getDatasetType() { + return FLAT_XML; + } + +} diff --git a/ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupTest.java b/ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupTest.java new file mode 100644 index 000000000..29c8b8f00 --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/categorization/RegistrySetupTest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.categorization; + +import org.libreccm.categorization.RegistrySetup; +import com.example.TestConfiguration; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.arquillian.persistence.CreateSchema; +import org.jboss.arquillian.persistence.PersistenceTest; +import org.jboss.arquillian.persistence.ShouldMatchDataSet; +import org.jboss.arquillian.transaction.api.annotation.TransactionMode; +import org.jboss.arquillian.transaction.api.annotation.Transactional; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.libreccm.categorization.Categorization; +import org.libreccm.core.CcmObject; +import org.libreccm.jpa.EntityManagerProducer; +import org.libreccm.jpa.utils.MimeTypeConverter; +import org.libreccm.l10n.LocalizedString; +import org.libreccm.modules.InstallEvent; +import org.libreccm.security.Permission; +import org.libreccm.tests.categories.IntegrationTest; +import org.libreccm.testutils.EqualsVerifier; +import org.libreccm.web.CcmApplication; +import org.libreccm.workflow.Workflow; + +import java.io.File; + +import javax.inject.Inject; +import javax.persistence.EntityManager; + +import org.libreccm.configuration.Configuration; + + +/** + * + * @author Jens Pelzetter + */ +@org.junit.experimental.categories.Category(IntegrationTest.class) +@RunWith(Arquillian.class) +@PersistenceTest +@Transactional(TransactionMode.COMMIT) +@CreateSchema({"create_ccm_core_schema.sql"}) +public class RegistrySetupTest { + + @Inject + private EntityManager entityManager; + + public RegistrySetupTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Deployment + public static WebArchive createDeployment() { + final PomEquippedResolveStage pom = Maven + .resolver() + .loadPomFromFile("pom.xml"); + final PomEquippedResolveStage dependencies = pom + .importCompileAndRuntimeDependencies(); + final File[] libs = dependencies.resolve().withTransitivity().asFile(); + + for (File lib : libs) { + System.err.printf("Adding file '%s' to test archive...%n", + lib.getName()); + } + + return ShrinkWrap + .create(WebArchive.class, + "LibreCCM-org.libreccm.categorization.RegistrySetupTest.war") + .addPackage(org.libreccm.core.CcmObject.class.getPackage()) + .addPackage(org.libreccm.security.Permission.class.getPackage()) + .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) + .addPackage(org.libreccm.categorization.Categorization.class.getPackage()) + .addPackage(org.libreccm.configuration.Configuration.class.getPackage()) + .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()) + .addPackage(org.libreccm.workflow.Workflow.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()) + .addPackage(org.libreccm.modules.InstallEvent.class.getPackage()) + .addAsLibraries(libs) + .addAsResource("test-persistence.xml", + "META-INF/persistence.xml") + .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); + } + + @Test + @ShouldMatchDataSet(value = + "datasets/org/libreccm/categorization/RegistrySetupTest/after-setup.xml", + excludeColumns = {"object_id", "root_category_id"}) + @InSequence(100) + public void setupRegistry() { + final InstallEvent installEvent = new InstallEvent(); + installEvent.setEntityManager(entityManager); + final RegistrySetup registrySetup = new RegistrySetup(installEvent); + registrySetup.setup(); + } + +} diff --git a/ccm-core/src/test/resources/datasets/org/libreccm/categorization/RegistrySetupTest/after-setup.xml b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/RegistrySetupTest/after-setup.xml new file mode 100644 index 000000000..432332103 --- /dev/null +++ b/ccm-core/src/test/resources/datasets/org/libreccm/categorization/RegistrySetupTest/after-setup.xml @@ -0,0 +1,12 @@ + + + + + + +