我正在尝试运行一个非常基本的Pax Exam 4单元测试,但需要访问多个Maven存储库(不是Maven Central).这是代码:
@RunWith(PaxExam.class)
public class ExamTest {
@Inject
private BundleContext bundleContext;
@Configuration
public Option[] config() {
return options(
repositories(
repository("http://maven.wso2.org/nexus/content/groups/wso2-public").id("wso2"),
repository("http://nexus.codehaus.org/snapshots").id("nexus.public.repo").allowSnapshots(),
),
mavenBundle("commons-httpclient.wso2", "commons-httpclient").version("3.1.0.wso2v2"),
mavenBundle("org.codehaus.woodstox", "stax2-api").version("3.0.1-SNAPSHOT"),
cleanCaches(),
junitBundles()
);
}
@Test
public void testInjection() {
Assert.assertNotNull(bundleContext);
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
System.out.println(bundle.getSymbolicName() + ", state = " + bundle.getState());
}
}
}
Run Code Online (Sandbox Code Playgroud)
实际测试是微不足道的,但仅用于测试目的,所以不要介意(repos和库也仅用于测试目的).问题是以上操作不起作用,Pax考试抱怨存储库URL无效.运行此测试时的输出如下:
[main] ERROR org.ops4j.pax.url.mvn.internal.AetherBasedResolver - invalid repository URLs
java.net.MalformedURLException: no protocol: +http://nexus.codehaus.org/snapshots/
at java.net.URL.<init>(URL.java:585)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.ops4j.pax.url.mvn.internal.config.MavenRepositoryURL.<init>(MavenRepositoryURL.java:191)
at …Run Code Online (Sandbox Code Playgroud)