Skip to content

Commit

Permalink
Add MP Config TCK Arquillian extension
Browse files Browse the repository at this point in the history
Hamcrest isn't loaded with the applications by default, despite
the deployed applications requiring it. This change adds an
Arquillian extension to deploy a Hamcrest dependency with the
apps.

Signed-off-by: Matthew Gill <matthew.gill@live.co.uk>
  • Loading branch information
MattGill98 committed Jun 10, 2022
1 parent 2746774 commit d97cd76
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
3 changes: 1 addition & 2 deletions appserver/tests/tck/microprofile/config/pom.xml
Expand Up @@ -27,7 +27,7 @@
</parent>

<artifactId>glassfish-external-tck-microprofile-config</artifactId>
<packaging>pom</packaging>
<packaging>jar</packaging>

<name>TCK: MicroProfile Config</name>

Expand Down Expand Up @@ -76,7 +76,6 @@
</environmentVariables>

<systemProperties>
<!-- We have put these values into mp.tck.properties above -->
<mp.tck.prop.dummy>dummy</mp.tck.prop.dummy>
<customer.hobby>Tennis</customer.hobby>
<config_ordinal>120</config_ordinal>
Expand Down
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2022 Contributors to Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.microprofile.config.tck;

import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
import org.jboss.arquillian.core.spi.LoadableExtension;
import org.jboss.arquillian.test.spi.TestClass;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;

import java.io.File;
import java.util.logging.Logger;

import static java.util.logging.Level.SEVERE;

/**
* This extension performs the following duties for TCK runs:
* - Adding Hamcrest to each deployment, to prevent ClassNotFoundExceptions when running hamcrest tests
*/
public class ConfigArquillianExtension implements LoadableExtension, ApplicationArchiveProcessor {

private static final Logger LOGGER = Logger.getLogger(ConfigArquillianExtension.class.getName());

/**
* Register this object as an Arquillian extension
* @param extensionBuilder a context object for the extension
*/
@Override
public void register(ExtensionBuilder extensionBuilder) {
extensionBuilder.service(ApplicationArchiveProcessor.class, getClass());
}

@Override
public void process(Archive<?> archive, TestClass testClass) {
if (!(archive instanceof WebArchive)) {
return;
}
addDependencies((WebArchive) archive);
}

private void addDependencies(WebArchive archive) {
try {
archive.addAsLibraries(resolveDependency("org.hamcrest:hamcrest:2.2"));
} catch (Exception e) {
LOGGER.log(SEVERE, "Error adding dependencies", e);
}
}

private static File[] resolveDependency(String coordinates) {
return Maven.resolver()
.resolve(coordinates)
.withoutTransitivity().asFile();
}
}
@@ -0,0 +1 @@
org.glassfish.microprofile.config.tck.ConfigArquillianExtension
38 changes: 38 additions & 0 deletions appserver/tests/tck/microprofile/pom.xml
Expand Up @@ -42,6 +42,18 @@
<module>config</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.7.0.Alpha10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.glassfish.main.distributions</groupId>
Expand Down Expand Up @@ -71,6 +83,32 @@
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.core</groupId>
<artifactId>arquillian-core-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-impl-base</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down

0 comments on commit d97cd76

Please sign in to comment.