我配置了我的项目并为多模块项目编写了测试类。使用Arquillan编写对AS400服务器的业务服务调用的测试,当我运行测试时,它会给我InvalidEnvironnmentException
。
package com.my.company.theproject.business.service.protect;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.my.company.theproject.common.dataaccess.PojoService;
import com.my.company.theproject.ServiceContext;
@RunWith(Arquillian.class)
public class SampleServiceTest
{
@Inject
@PojoService
SampleService service;
private ServiceContext context;
@Before
public void setUp()
throws Exception
{
context = new ServiceContext();
}
@Deployment
public static WebArchive createDeployment()
{
return ShrinkWrap
.create(WebArchive.class)
.addClasses(SampleService.class)
.addAsWebInfResource("META-INF/beans.xml", ArchivePaths.create("beans.xml"))
.addAsLibraries(
Maven.configureResolverViaPlugin().importRuntimeDependencies().resolve().withTransitivity().asFile());
}
@Test
public void test()
{
List<String> list = new ArrayList<String>();
list.add("AAA");
service.getStoredProcedureParameters(context, list);
fail("To be implemented");
}
}
我在这里记下了导入,以防有些错误(例如javax.inject.Inject?)。
这里的问题是Arquillian在测试运行时给出了这个错误(堆栈跟踪的第一个例外):
java.lang.RuntimeException:无法调用部署方法:public static org.jboss.shrinkwrap.api.spec.WebArchive com.sopra.banking.packbanque.business.service.protect.SampleServiceTest.createDeployment()
在堆栈跟踪结束时,我看到了:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:177)
... 50 more
Caused by: org.jboss.shrinkwrap.resolver.api.maven.InvalidEnvironmentException: Configuration from environment requires that user has following properties set, however they were not detected in runtime environment:
maven.execution.pom-file
maven.execution.offline
maven.execution.user-settings
maven.execution.global-settings
maven.execution.active-profiles
You should enable ShrinkWrap Maven Resolver Plugin to get them set for you automatically if executing from Maven via adding following to your <build> section:
<plugin>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>propagate-execution-context</goal>
</goals>
</execution>
</executions>
</plugin>
at org.jboss.shrinkwrap.resolver.impl.maven.task.ConfigureSettingsFromPluginTask.execute(ConfigureSettingsFromPluginTask.java:71)
at org.jboss.shrinkwrap.resolver.impl.maven.ConfigurableMavenResolverSystemBaseImpl.configureViaPlugin(ConfigurableMavenResolverSystemBaseImpl.java:119)
at org.jboss.shrinkwrap.resolver.api.maven.Maven.configureResolverViaPlugin(Maven.java:77)
at org.jboss.shrinkwrap.resolver.api.maven.Maven.configureResolverViaPlugin(Maven.java:59)
at com.sopra.banking.packbanque.business.service.protect.SampleServiceTest.createDeployment(SampleServiceTest.java:74)
... 55 more
问题是这个插件声明已经在我的Maven pom.xml中了!
<build>
<plugins>
<plugin>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-maven-plugin</artifactId>
<version>2.2.0-beta-2</version>
<executions>
<execution>
<goals>
<goal>propagate-execution-context</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
这里有什么问题?
答案 0 :(得分:0)
我认为问题可能是你需要首先加载pom文件然后解决,因为它现在知道要解决依赖关系...
我不确定,但你可以尝试这个......:)
您可以在此处找到有关shrikwrap解析器的所有信息: