Could not invoke deploy() method
robyp7 Mar 7, 2018 4:42 PMHi
I have a test, i need to create war but i need some dependencies with it.
So i using:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
and this code:
File[] files = Maven.resolver().loadPomFromFile("C:/Progetti/altri/javaee-soteria-master/pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile();
// JavaArchive[] assertjArch = Maven.resolver().resolve("org.assertj:assertj-core").withTransitivity().as(JavaArchive.class);<--I dont' use that, because i need this for every dep! And not work..
return ShrinkWrap.create(WebArchive.class, "test.war")
.addAsLibraries(files)
.addClass(Account.class)
.addClass(Token.class)
.addClass(TokenType.class)
;
When i start wildfly and run mvn failsafe plugin
i get this exception:
16:55:34,876 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9050/management
16:55:34,876 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9050
16:55:34,876 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started (with errors) in 6705ms - Started 339 of 586 services (1 services failed or missing dependencies, 394 services are lazy, passive or on-demand)
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.561 s <<< FAILURE! - in id.swhp.javaee.soteria.business.security.boundary.ArquillianEmptyTestIT
[ERROR] id.swhp.javaee.soteria.business.security.boundary.ArquillianEmptyTestIT Time elapsed: 10.558 s <<< ERROR!
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.Archive id.swhp.javaee.soteria.business.security.boundary.ArquillianEmptyTestIT.deploy()
at id.swhp.javaee.soteria.business.security.boundary.ArquillianEmptyTestIT.deploy(ArquillianEmptyTestIT.java:39)
Mar 07, 2018 4:55:36 PM org.jboss.arquillian.core.impl.ObserverImpl resolveArguments
WARNING: Argument 2 for ArquillianServiceDeployer.undeploy is null. It won't be invoked.
I have tried to replace C:/Progetti/altri/javaee-soteria-master/pom.xml with test.properties with a path from properties placed in /test/resources:
pom.path=${project.basedir}/pom.xml
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
mvn clean install
- >in target/test-classes (substitution param for project.basedir produce the same absolute path as above):
pom.path=C:\\Progetti\\altri\\javaee-soteria-master/pom.xml
and
this line become:
public static Archive deploy(){
File[] files = Maven.resolver().loadPomFromFile(getPomPath()).importRuntimeDependencies().resolve().withTransitivity().asFile(); --> but it still get null
andnothing change
So the problems are:
1) why i get RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.Archive id.swhp.javaee.soteria.business.security.boundary.ArquillianEmptyTestIT.deploy()
2) why loadProperties(ArquillianEmptyTestIT.class.getResourceAsStream(DEFAULT_CONF)) return null
Can you help me?
Thank you very much
My class is:
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
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.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(Arquillian.class)
public class ArquillianEmptyTestIT {
public static final String DEFAULT_CONF = "test.properties";
Account account;
@Deployment
public static Archive deploy(){
File[] files = Maven.resolver().loadPomFromFile("C:/Progetti/altri/javaee-test/pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile();
// JavaArchive[] assertjArch = Maven.resolver().resolve("org.assertj:assertj-core").withTransitivity().as(JavaArchive.class);
return ShrinkWrap.create(WebArchive.class, "test.war")
.addAsLibraries(files)
.addClass(Account.class)
.addClass(Token.class)
.addClass(TokenType.class)
;
}
@Ignore
private static Properties getPomPath() {
//try to read pom path by configuration files
Properties defaults = loadProperties(ArquillianEmptyTestIT.class.getResourceAsStream(DEFAULT_CONF));
System.out.println("*** " + defaults.getProperty("pom.path")); //--> but this is null
return defaults;
}
@Ignore
private static Properties loadProperties(InputStream is) {
Properties props = new Properties();
try {
if (is != null) {
props.load(is);
} else {
props = null;
}
} catch (IOException ex) {
System.err.println("Errore nella lettura della configurazione (" + ex.getMessage() + ")");
props = null;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ioe) {
System.err.println("Errore nella lettura della configurazione (" + ioe.getMessage() + ")");
}
}
}
return props;
}
@Test
public void emptyInContainerTest(){
System.out.println("=========================================");
System.out.println("This test should run inside the container");
System.out.println("=========================================");
// assertThat(account).isNotNull();
}
}
Pom fragment with dependecies for test:
<!--test scope -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.15.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>2.1.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>