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.karaf;
017
018import static org.slf4j.LoggerFactory.getLogger;
019import static org.junit.Assert.assertTrue;
020import static org.ops4j.pax.exam.CoreOptions.maven;
021import static org.ops4j.pax.exam.CoreOptions.bundle;
022import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
023import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
024import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
025import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
026import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
027import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
028
029import java.io.File;
030
031import javax.inject.Inject;
032
033import org.apache.karaf.features.FeaturesService;
034import org.junit.Test;
035import org.junit.runner.RunWith;
036import org.ops4j.pax.exam.Configuration;
037import org.ops4j.pax.exam.ConfigurationManager;
038import org.ops4j.pax.exam.Option;
039import org.ops4j.pax.exam.junit.PaxExam;
040import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
041import org.slf4j.Logger;
042
043/**
044 * @author Aaron Coburn
045 * @since February 8, 2016
046 */
047@RunWith(PaxExam.class)
048public class KarafIT {
049
050    private static Logger LOG = getLogger(KarafIT.class);
051
052    @Inject
053    protected FeaturesService featuresService;
054
055    @Configuration
056    public Option[] config() {
057        final ConfigurationManager cm = new ConfigurationManager();
058        final String fcrepoPort = cm.getProperty("fcrepo.dynamic.test.port");
059        final String jmsPort = cm.getProperty("fcrepo.dynamic.jms.port");
060        final String fcrepoFeatures = "file:" + cm.getProperty("project.build.outputDirectory") + "/features.xml";
061        return new Option[] {
062            karafDistributionConfiguration()
063                .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf")
064                        .versionAsInProject().type("zip"))
065                .unpackDirectory(new File("target", "exam"))
066                .useDeployFolder(false),
067            logLevel(LogLevel.WARN),
068            keepRuntimeFolder(),
069            configureConsole().ignoreLocalConsole(),
070            features(maven().groupId("org.apache.karaf.features").artifactId("standard")
071                        .versionAsInProject().classifier("features").type("xml"), "scr"),
072            features(maven().groupId("org.apache.camel.karaf").artifactId("apache-camel")
073                        .type("xml").classifier("features").versionAsInProject(), "camel-blueprint"),
074            features(bundle(fcrepoFeatures).start(), "fcrepo-indexing-triplestore",
075                    "fcrepo-indexing-solr", "fcrepo-reindexing", "fcrepo-serialization",
076                    "fcrepo-fixity", "fcrepo-audit-triplestore"),
077            editConfigurationFilePut("etc/org.fcrepo.camel.indexing.triplestore.cfg", "fcrepo.baseUrl", "localhost:" + fcrepoPort + "/fcrepo/rest"),
078            editConfigurationFilePut("etc/org.fcrepo.camel.indexing.triplestore.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort),
079            editConfigurationFilePut("etc/org.fcrepo.camel.indexing.solr.cfg", "fcrepo.baseUrl", "localhost:" + fcrepoPort + "/fcrepo/rest"),
080            editConfigurationFilePut("etc/org.fcrepo.camel.indexing.solr.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort),
081            editConfigurationFilePut("etc/org.fcrepo.camel.reindexing.cfg", "fcrepo.baseUrl", "localhost:" + fcrepoPort + "/fcrepo/rest"),
082            editConfigurationFilePut("etc/org.fcrepo.camel.reindexing.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort),
083            editConfigurationFilePut("etc/org.fcrepo.camel.serialization.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort),
084            editConfigurationFilePut("etc/org.fcrepo.camel.audit.triplestore.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort),
085            editConfigurationFilePut("etc/org.fcrepo.camel.fixity.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort),
086       };
087    }
088
089    @Test
090    public void testInstallation() throws Exception {
091        assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core")));
092        assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-camel")));
093        assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-indexing-triplestore")));
094        assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-indexing-solr")));
095        assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-reindexing")));
096        assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-serialization")));
097        assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-audit-triplestore")));
098        assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-fixity")));
099    }
100}