Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MP Config TCK Arquillian extension
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
1 parent
2746774
commit d97cd76
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...config/src/main/java/org/glassfish/microprofile/config/tck/ConfigArquillianExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...nfig/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.glassfish.microprofile.config.tck.ConfigArquillianExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters