001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.camel.integration;
017
018import static org.osgi.framework.Bundle.ACTIVE;
019import static org.slf4j.LoggerFactory.getLogger;
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertNotNull;
022import static org.junit.Assert.assertTrue;
023import static org.ops4j.pax.exam.CoreOptions.bundle;
024import static org.ops4j.pax.exam.CoreOptions.maven;
025import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
026import static org.ops4j.pax.exam.CoreOptions.systemProperty;
027import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
028import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
029import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
030import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
031import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
032import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
033import static org.ops4j.pax.exam.util.PathUtils.getBaseDir;
034
035import java.io.File;
036
037import javax.inject.Inject;
038
039import org.apache.karaf.features.FeaturesService;
040import org.junit.Test;
041import org.junit.runner.RunWith;
042import org.ops4j.pax.exam.Configuration;
043import org.ops4j.pax.exam.ConfigurationManager;
044import org.ops4j.pax.exam.Option;
045import org.ops4j.pax.exam.junit.PaxExam;
046import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
047import org.osgi.framework.BundleContext;
048import org.slf4j.Logger;
049
050/**
051 * @author Aaron Coburn
052 * @since February 8, 2016
053 */
054@RunWith(PaxExam.class)
055public class KarafIT {
056
057    private static Logger LOG = getLogger(KarafIT.class);
058
059    @Inject
060    protected FeaturesService featuresService;
061
062    @Inject
063    protected BundleContext bundleContext;
064
065    @Configuration
066    public Option[] config() {
067        final ConfigurationManager cm = new ConfigurationManager();
068        final String artifactName = cm.getProperty("project.artifactId") + "-" + cm.getProperty("project.version");
069        final String fcrepoCamelBundle = "file:" + getBaseDir() + "/target/" + artifactName + ".jar";
070        final String commonsCodecVersion = cm.getProperty("commons.codec.version");
071        final String commonsCsvVersion = cm.getProperty("commons.csv.version");
072        final String httpclientVersion = cm.getProperty("httpclient.version");
073        final String httpcoreVersion = cm.getProperty("httpcore.version");
074        final String thriftVersion = cm.getProperty("thrift.version");
075        final String jenaVersion = cm.getProperty("jena.version");
076        final String rmiRegistryPort = cm.getProperty("karaf.rmiRegistry.port");
077        final String rmiServerPort = cm.getProperty("karaf.rmiServer.port");
078        final String sshPort = cm.getProperty("karaf.ssh.port");
079        return new Option[] {
080            karafDistributionConfiguration()
081                .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf")
082                        .versionAsInProject().type("zip"))
083                .unpackDirectory(new File("target", "exam"))
084                .useDeployFolder(false),
085            logLevel(LogLevel.WARN),
086            keepRuntimeFolder(),
087            configureConsole().ignoreLocalConsole(),
088            systemProperty("fcrepo-camel-bundle").value(fcrepoCamelBundle),
089            editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort),
090            editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
091            editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
092            features(maven().groupId("org.apache.karaf.features").artifactId("standard")
093                        .versionAsInProject().classifier("features").type("xml"), "scr"),
094            features(maven().groupId("org.apache.camel.karaf").artifactId("apache-camel")
095                        .type("xml").classifier("features").versionAsInProject(), "camel-blueprint", "camel-spring"),
096            mavenBundle().groupId("commons-codec").artifactId("commons-codec").version(commonsCodecVersion),
097            mavenBundle().groupId("org.apache.commons").artifactId("commons-csv").version(commonsCsvVersion),
098            mavenBundle().groupId("org.apache.commons").artifactId("commons-lang3").versionAsInProject(),
099            mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpclient-osgi").version(httpclientVersion),
100            mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpcore-osgi").version(httpcoreVersion),
101            mavenBundle().groupId("org.apache.jena").artifactId("jena-osgi").version(jenaVersion),
102            mavenBundle().groupId("com.google.guava").artifactId("guava").versionAsInProject(),
103            mavenBundle().groupId("com.fasterxml.jackson.core").artifactId("jackson-core").versionAsInProject(),
104            mavenBundle().groupId("com.fasterxml.jackson.core").artifactId("jackson-annotations").versionAsInProject(),
105            mavenBundle().groupId("com.fasterxml.jackson.core").artifactId("jackson-databind").versionAsInProject(),
106            mavenBundle().groupId("com.github.jsonld-java").artifactId("jsonld-java").versionAsInProject(),
107            mavenBundle().groupId("org.apache.thrift").artifactId("libthrift").version(thriftVersion),
108            mavenBundle().groupId("org.fcrepo.client").artifactId("fcrepo-java-client").versionAsInProject(),
109            bundle(fcrepoCamelBundle).start()
110       };
111    }
112
113    @Test
114    public void testInstallation() throws Exception {
115        assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core")));
116        assertNotNull(bundleContext);
117        assertEquals(ACTIVE, bundleContext.getBundle(System.getProperty("fcrepo-camel-bundle")).getState());
118    }
119}