CCM NG/ccm-testutils:
- Code cleanup - Helper class for retrieving the dependencies of the current module and other module for use in the deployment method of Arquillan tests. git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4323 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
1c08efca11
commit
9948649d1d
|
|
@ -59,6 +59,11 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.shrinkwrap.resolver</groupId>
|
||||||
|
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
@ -155,11 +160,11 @@
|
||||||
</rulesets>
|
</rulesets>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<!--<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>javancss-maven-plugin</artifactId>
|
<artifactId>javancss-maven-plugin</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.1</version>
|
||||||
</plugin>
|
</plugin>-->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,8 @@ import static org.libreccm.testutils.DatasetType.*;
|
||||||
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
|
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
|
||||||
import org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet;
|
import org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -121,7 +120,7 @@ public class DatasetsVerifier {
|
||||||
try (final Connection connection = DriverManager.getConnection(
|
try (final Connection connection = DriverManager.getConnection(
|
||||||
connectionStr, "sa", "")) {
|
connectionStr, "sa", "")) {
|
||||||
//Create DB tables etc
|
//Create DB tables etc
|
||||||
for(final String ddlFile : getDdlFiles()) {
|
for (final String ddlFile : getDdlFiles()) {
|
||||||
processDdlFile(connection, ddlFile);
|
processDdlFile(connection, ddlFile);
|
||||||
}
|
}
|
||||||
// final Path schemaPath = Paths.get(getClass().getResource(
|
// final Path schemaPath = Paths.get(getClass().getResource(
|
||||||
|
|
@ -132,26 +131,26 @@ public class DatasetsVerifier {
|
||||||
|
|
||||||
//Get dataset to test
|
//Get dataset to test
|
||||||
final IDataSet dataSet;
|
final IDataSet dataSet;
|
||||||
|
try (final InputStream inputStream = getClass().getResourceAsStream(
|
||||||
|
datasetPath)) {
|
||||||
switch (getDatasetType()) {
|
switch (getDatasetType()) {
|
||||||
case FLAT_XML:
|
case FLAT_XML:
|
||||||
final FlatXmlDataSetBuilder builder
|
final FlatXmlDataSetBuilder builder
|
||||||
= new FlatXmlDataSetBuilder();
|
= new FlatXmlDataSetBuilder();
|
||||||
dataSet = builder.build(getClass().getResourceAsStream(
|
dataSet = builder.build(inputStream);
|
||||||
datasetPath));
|
|
||||||
break;
|
break;
|
||||||
case JSON:
|
case JSON:
|
||||||
dataSet = new JsonDataSet(getClass()
|
dataSet = new JsonDataSet(inputStream);
|
||||||
.getResourceAsStream(datasetPath));
|
|
||||||
break;
|
break;
|
||||||
case YAML:
|
case YAML:
|
||||||
dataSet = new YamlDataSet(getClass()
|
dataSet = new YamlDataSet(inputStream);
|
||||||
.getResourceAsStream(datasetPath));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
"Unsupported DatasetType \"%s\"",
|
"Unsupported DatasetType \"%s\"",
|
||||||
getDatasetType()));
|
getDatasetType()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Create DBUnit DB connection
|
//Create DBUnit DB connection
|
||||||
final IDatabaseConnection dbUnitConn
|
final IDatabaseConnection dbUnitConn
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* 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.testutils;
|
||||||
|
|
||||||
|
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
|
||||||
|
import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some static helper methods to deal with the dependencies in Arquillian tests.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public final class DependenciesHelpers {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor to avoid accidental instantiation of this class.
|
||||||
|
*/
|
||||||
|
private DependenciesHelpers() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method implements the common part of the public methods in this
|
||||||
|
* class.
|
||||||
|
*
|
||||||
|
* @param pomPath The path of the POM file to use.
|
||||||
|
*
|
||||||
|
* @return The dependencies defined in the POM file including their
|
||||||
|
* transitive dependencies. All dependencies whose name starts with
|
||||||
|
* {@code ccm-} (which should be modules of {@code LibreCCM} are
|
||||||
|
* excluded. Classes from CCM modules which are required for tests
|
||||||
|
* have to be included manually using the {@code addPackage} or
|
||||||
|
* {@code addClass} methods from ShrinkWrap.
|
||||||
|
*/
|
||||||
|
private static File[] getDependenciesFromPom(final String pomPath) {
|
||||||
|
final PomEquippedResolveStage pom = Maven
|
||||||
|
.resolver()
|
||||||
|
.loadPomFromFile(pomPath);
|
||||||
|
final PomEquippedResolveStage dependencies = pom
|
||||||
|
.importCompileAndRuntimeDependencies();
|
||||||
|
final File[] libFiles = dependencies.resolve().withTransitivity()
|
||||||
|
.asFile();
|
||||||
|
|
||||||
|
final File[] libs = Arrays.stream(libFiles)
|
||||||
|
.filter(lib -> !lib.getName().startsWith("ccm-"))
|
||||||
|
.collect(Collectors.toList()).toArray(new File[0]);
|
||||||
|
Arrays.stream(libs)
|
||||||
|
.forEach(lib -> System.err.printf(
|
||||||
|
"Found dependency '%s'...%n",
|
||||||
|
lib.getName()));
|
||||||
|
|
||||||
|
return libs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the dependencies of the current module.
|
||||||
|
*
|
||||||
|
* @return The dependencies of the current module.
|
||||||
|
*
|
||||||
|
* @see #getDependenciesFromPom(java.lang.String)
|
||||||
|
*/
|
||||||
|
public static File[] getModuleDependencies() {
|
||||||
|
return getDependenciesFromPom("pom.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the dependencies for another CCM module.
|
||||||
|
*
|
||||||
|
* @param module The module
|
||||||
|
*
|
||||||
|
* @return The dependencies of the module.
|
||||||
|
*
|
||||||
|
* @see #getDependenciesFromPom(java.lang.String)
|
||||||
|
*/
|
||||||
|
public static File[] getDependenciesFromModule(final String module) {
|
||||||
|
return getDependenciesFromPom(String.format("../%s/pom.xml",
|
||||||
|
module));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenient method for getting the the dependencies of the
|
||||||
|
* {@code ccm-core} module.
|
||||||
|
*
|
||||||
|
* @return The dependencies of the {@code ccm-core} module.
|
||||||
|
* @see #getDependenciesFromModule(java.lang.String)
|
||||||
|
* @see #getDependenciesFromPom(java.lang.String)
|
||||||
|
*/
|
||||||
|
public static File[] getCcmCoreDependencies() {
|
||||||
|
return getDependenciesFromModule("ccm-core");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ public class EqualsVerifier {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void verifyEqualsAndHashCode() {
|
public void verifyEqualsAndHashCode() {
|
||||||
nl.jqno.equalsverifier.EqualsVerifier<?> verifier
|
final nl.jqno.equalsverifier.EqualsVerifier<?> verifier
|
||||||
= nl.jqno.equalsverifier.EqualsVerifier
|
= nl.jqno.equalsverifier.EqualsVerifier
|
||||||
.forClass(entityClass)
|
.forClass(entityClass)
|
||||||
.withRedefinedSuperclass();
|
.withRedefinedSuperclass();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue