Hi,
yes, the the items (1) of src/main/java are in the stream bundle
(src/main/resources is empty). The blueprint.xml is in
src/test/resources/OSGI-INF/blueprint because it is only used for test
purposes. What is also strange is, that test test seems to run the class
SipDetectionProcessor it complains to not found! The test class is:
package ch.eugster.ingest.test.sip.detection.processor;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.streamBundle;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
import java.io.File;
import javax.inject.Inject;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.DefaultMessage;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.karaf.features.FeaturesService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
import org.ops4j.pax.exam.util.Filter;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import ch.eugster.ingest.sip.detection.processor.SipDetectionProcessor;
import ch.eugster.ingest.sip.detector.api.SipDetector;
@RunWith(PaxExam.class)
public class KarafContainerTest extends CamelTestSupport
{
private String zipOk = new
File("../../../../src/test/resources/SIP_20150306_Matterhorn.zip").getAbsolutePath();
private String zipNotOk = new
File("../../../../src/test/resources/SIP_20140430_eCH-0160v1.zip").getAbsolutePath();
@Inject
protected BundleContext bundleContext;
@Inject
protected FeaturesService featuresService;
@Inject
protected SipDetector sipDetector;
@Inject
@Filter(value="(camel.context.name=blueprintContext)", timeout=10000)
protected CamelContext testContext;
@Configuration
public static Option[] configuration() throws Exception
{
System.out.println("Configuring container");
return new Option[] {
karafDistributionConfiguration().frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf")
.type("zip").versionAsInProject())
.unpackDirectory(new
File("target/paxexam/unpack/"))
.useDeployFolder(false),
configureConsole().ignoreLocalConsole(),
logLevel(LogLevel.INFO),
features(
maven().groupId("org.apache.camel.karaf").artifactId("apache-camel").type("xml")
.classifier("features").versionAsInProject(), "camel-blueprint", "camel-test"),
features(
maven().groupId("org.apache.karaf.features")
.artifactId("standard").type("xml")
.classifier("features").versionAsInProject(),
"eventadmin"),
wrappedBundle(mavenBundle()
.groupId("de.schlichtherle.truezip")
.artifactId("truezip-swing")
.version("7.7.8")),
wrappedBundle(mavenBundle()
.groupId("de.schlichtherle.truezip")
.artifactId("truezip-kernel")
.version("7.7.8")),
wrappedBundle(mavenBundle()
.groupId("de.schlichtherle.truezip")
.artifactId("truezip-file")
.version("7.7.8")),
wrappedBundle(mavenBundle()
.groupId("de.schlichtherle.truezip")
.artifactId("truezip-path")
.version("7.7.8")),
wrappedBundle(mavenBundle()
.groupId("de.schlichtherle.truezip")
.artifactId("truezip-driver-file")
.version("7.7.8")),
wrappedBundle(mavenBundle()
.groupId("de.schlichtherle.truezip")
.artifactId("truezip-driver-zip")
.version("7.7.8")),
mavenBundle().groupId("ch.eugster.ingest")
.artifactId("sip-api")
.version("0.0.1-SNAPSHOT"),
mavenBundle().groupId("ch.eugster.ingest")
.artifactId("sip-detector-api")
.version("0.0.1-SNAPSHOT"),
mavenBundle().groupId("ch.eugster.ingest")
.artifactId("sip-matterhorn-profile")
.version("0.0.1-SNAPSHOT"),
mavenBundle().groupId("ch.eugster.ingest")
.artifactId("sip-detector-matterhorn")
.version("0.0.1-SNAPSHOT"),
streamBundle(
bundle()
.add(SipDetectionProcessor.class)
.add("OSGI-INF/blueprint/camel-context.xml",
new File("src/test/resources/OSGI-INF/blueprint/blueprint.xml")
.toURL())
.set(Constants.BUNDLE_SYMBOLICNAME, "sip-detection-processor")
.set(Constants.DYNAMICIMPORT_PACKAGE, "*").build())
.start()
};
}
@Override
public boolean isCreateCamelContextPerClass()
{
// we override this method and return true, to tell Camel
test-kit that
// it should only create CamelContext once (per class), so we
will
// re-use the CamelContext between each test method in this
class
return true;
}
@Test
public void test() throws Exception
{
System.out.println("START TEST");
assertTrue(featuresService.isInstalled(featuresService.getFeature("eventadmin")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-blueprint")));
System.out.println("Checking sipDetector service: " +
(this.sipDetector == null ? "not available" : "available"));
assertTrue(this.sipDetector != null);
doPreSetup();
MockEndpoint mockEndpoint = (MockEndpoint)
testContext.getEndpoint("mock:result");
mockEndpoint.expectedMessageCount(1);
File file = new File(zipOk);
System.out.println("File '" + file.getName() + "' " +
(file.exists() ? "exists" : "does not exist"));
assertTrue(file.isFile());
ProducerTemplate template =
this.testContext.createProducerTemplate();
Message message = new DefaultMessage();
GenericFile<File> genericFile = new GenericFile<File>();
genericFile.setFile(file);
message.setBody(file);
Exchange exchange = new DefaultExchange(testContext);
exchange.setIn(message);
template.send("direct:start", exchange);
file = new File(zipNotOk);
System.out.println("File '" + file.getName() + "' " +
(file.exists() ? "exists" : "does not exist"));
assertTrue(file.isFile());
message = new DefaultMessage();
genericFile = new GenericFile<File>();
genericFile.setFile(file);
message.setBody(file);
exchange = new DefaultExchange(testContext);
exchange.setIn(message);
template.send("direct:start", exchange);
mockEndpoint.assertIsSatisfied(15000);
}
}
Christian Eugster
Docuteam GmbH
Langacker 16
Postfach
CH-5405 Baden-Dättwil
+41 (0)56 470 03 37
[email protected]