我无法使用@Configuration方法向我的Pax考试集成测试中添加捆绑软件。我正在尝试在集成测试期间将捆绑包添加到我的Karaf容器中,以便最终可以注入HelloWorld实现。这是我清理过的Java代码。
package my.package.test.pax;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.ConfigurationManager;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
import javax.inject.Inject;
import java.io.File;
import static org.ops4j.pax.exam.CoreOptions.*;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
/**
* Integration test for HelloWorld in Karaf.
*/
@RunWith(PaxExam.class)
public class PaxTest {
@Configuration
public Option[] config() {
MavenArtifactUrlReference karafUrl = maven()
.groupId("org.apache.karaf")
.artifactId("apache-karaf")
.version(getKarafVersion())
.type("zip");
return new Option[]{
karafDistributionConfiguration()
.frameworkUrl(karafUrl)
.unpackDirectory(new File("target", "exam"))
.useDeployFolder(false),
bundle("reference:file:/home/user/projects/hello_world/hello-world-interface/build/libs/hello-world-interface-1.0.0-SNAPSHOT.jar"),
bundle("reference:file:/home/user/projects/hello_world/hello-world-impl/build/libs/hello-world-impl-1.0.0-SNAPSHOT.jar")
};
}
private String getKarafVersion() throws NullPointerException {
String karafVersion = new ConfigurationManager().getProperty("pax.exam.karaf.version");
if (karafVersion == null) {
throw new NullPointerException("Could not find Karaf version in Pax Exam properties");
}
return karafVersion;
}
@Test
public void testSayHello() throws Exception {
// tests some code
}
}
这是我的相对Gradle代码
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations {
test.dependsOn jar
test.classpath += files(jar.archivePath)
testImplementation.extendsFrom compileOnly
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
compileOnly 'org.osgi:org.osgi.service.component:1.3.0'
compileOnly 'org.osgi:org.osgi.service.component.annotations:1.3.0'
compileOnly 'org.osgi:org.osgi.service.metatype.annotations:1.3.0'
compileOnly 'org.osgi:osgi.core:6.0.0'
compileOnly 'org.ops4j.pax.logging:pax-logging-api:1.10.1'
testImplementation 'junit:junit:4.13-beta-2'
testImplementation 'pl.pragmatists:JUnitParams:1.1.1'
testImplementation 'org.mockito:mockito-core:2.25.0'
testImplementation 'org.powermock:powermock-module-junit4:2.0.0'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.0'
testImplementation 'org.apache.sling:org.apache.sling.testing.osgi-mock.junit4:2.4.8'
testImplementation 'org.osgi:org.osgi.compendium:5.0.0'
integrationTestImplementation 'org.ops4j.pax.exam:pax-exam-container-karaf:4.13.1'
integrationTestImplementation 'org.ops4j.pax.exam:pax-exam-junit4:4.13.1'
integrationTestImplementation 'org.ops4j.pax.exam:pax-exam:4.13.1'
integrationTestImplementation 'org.ops4j.pax.url:pax-url-aether:2.6.1'
integrationTestImplementation 'org.ops4j.pax.url:pax-url-classpath:2.6.1'
integrationTestImplementation 'org.ops4j.pax.url:pax-url-reference:2.6.1'
integrationTestImplementation 'javax.inject:javax.inject:1'
}
task integrationTest(type: Test) {
group 'Verification'
description 'Run the integration tests.'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
testLogging.showStandardStreams = true
}
check.dependsOn integrationTest
integrationTest.shouldRunAfter test
我跑步时
./gradlew my-module:integrationTest
我收到以下错误
my.package.test.pax.PaxTest > testSayHello STANDARD_ERROR
org.apache.karaf.features.internal.util.MultiException: Error:
Error downloading reference:file:/home/user/projects/hello_world/hello-world-interface/build/libs/hello-world-interface-1.0.0-SNAPSHOT.jar
Error downloading reference:file:/home/user/projects/hello_world/hello-world-impl/build/libs/hello-world-impl-1.0.0-SNAPSHOT.jar
at org.apache.karaf.features.internal.download.impl.MavenDownloadManager$MavenDownloader.<init>(MavenDownloadManager.java:91)
at org.apache.karaf.features.internal.download.impl.MavenDownloadManager.createDownloader(MavenDownloadManager.java:72)
at org.apache.karaf.features.internal.region.Subsystem.downloadBundles(Subsystem.java:457)
at org.apache.karaf.features.internal.region.Subsystem.downloadBundles(Subsystem.java:452)
at org.apache.karaf.features.internal.region.SubsystemResolver.resolve(SubsystemResolver.java:224)
at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:388)
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1058)
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread$13(FeaturesServiceImpl.java:994)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Suppressed: java.io.IOException: Error downloading reference:file:/home/user/projects/hello_world/hello-world-interface/build/libs/hello-world-interface-1.0.0-SNAPSHOT.jar
at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:77)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
... 3 more
Caused by: java.io.IOException: Could not download [reference:file:/home/user/projects/hello_world/hello-world-interface/build/libs/hello-world-interface-1.0.0-SNAPSHOT.jar]
at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:91)
at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
... 7 more
Caused by: java.net.MalformedURLException: Unknown protocol: reference
at java.net.URL.<init>(URL.java:627)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(URL.java:439)
at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:62)
... 8 more
Caused by: java.lang.IllegalStateException: Unknown protocol: reference
at org.apache.felix.framework.URLHandlersStreamHandlerProxy.parseURL(URLHandlersStreamHandlerProxy.java:373)
at java.net.URL.<init>(URL.java:622)
... 11 more
Suppressed: java.io.IOException: Error downloading reference:file:/home/user/projects/hello_world/hello-world-impl/build/libs/hello-world-impl-1.0.0-SNAPSHOT.jar
at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:77)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
... 3 more
Caused by: java.io.IOException: Could not download [reference:file:/home/user/projects/hello_world/hello-world-impl/build/libs/hello-world-impl-1.0.0-SNAPSHOT.jar]
at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:91)
at org.apache.karaf.features.internal.download.impl.AbstractRetryableDownloadTask.run(AbstractRetryableDownloadTask.java:60)
... 7 more
Caused by: java.net.MalformedURLException: Unknown protocol: reference
at java.net.URL.<init>(URL.java:627)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(URL.java:439)
at org.apache.karaf.features.internal.download.impl.SimpleDownloadTask.download(SimpleDownloadTask.java:62)
... 8 more
Caused by: java.lang.IllegalStateException: Unknown protocol: reference
at org.apache.felix.framework.URLHandlersStreamHandlerProxy.parseURL(URLHandlersStreamHandlerProxy.java:373)
at java.net.URL.<init>(URL.java:622)
... 11 more
my.package.test.pax.PaxTest > testAdd FAILED
java.rmi.NotBoundException