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.apache.http.HttpStatus.SC_OK; 019import static org.apache.http.impl.client.HttpClientBuilder.create; 020import static org.slf4j.LoggerFactory.getLogger; 021import static org.junit.Assert.assertEquals; 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.systemProperty; 026import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole; 027import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features; 028import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; 029import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; 030import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; 031import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel; 032 033import java.io.File; 034 035import javax.inject.Inject; 036 037import org.apache.http.client.methods.CloseableHttpResponse; 038import org.apache.http.client.methods.HttpGet; 039import org.apache.http.client.methods.HttpPost; 040import org.apache.http.entity.StringEntity; 041import org.apache.http.impl.client.CloseableHttpClient; 042import org.apache.karaf.features.FeaturesService; 043import org.junit.Test; 044import org.junit.runner.RunWith; 045import org.ops4j.pax.exam.Configuration; 046import org.ops4j.pax.exam.ConfigurationManager; 047import org.ops4j.pax.exam.Option; 048import org.ops4j.pax.exam.junit.PaxExam; 049import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel; 050import org.slf4j.Logger; 051 052/** 053 * @author Aaron Coburn 054 * @since February 8, 2016 055 */ 056@RunWith(PaxExam.class) 057public class KarafIT { 058 059 private static Logger LOG = getLogger(KarafIT.class); 060 061 @Inject 062 protected FeaturesService featuresService; 063 064 @Configuration 065 public Option[] config() { 066 final ConfigurationManager cm = new ConfigurationManager(); 067 final String fcrepoPort = cm.getProperty("fcrepo.dynamic.test.port"); 068 final String jmsPort = cm.getProperty("fcrepo.dynamic.jms.port"); 069 final String reindexingPort = cm.getProperty("fcrepo.dynamic.reindexing.port"); 070 final String rmiRegistryPort = cm.getProperty("karaf.rmiRegistry.port"); 071 final String rmiServerPort = cm.getProperty("karaf.rmiServer.port"); 072 final String sshPort = cm.getProperty("karaf.ssh.port"); 073 final String fcrepoFeatures = "file:" + cm.getProperty("project.build.outputDirectory") + "/features.xml"; 074 return new Option[] { 075 karafDistributionConfiguration() 076 .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf") 077 .versionAsInProject().type("zip")) 078 .unpackDirectory(new File("target", "exam")) 079 .useDeployFolder(false), 080 logLevel(LogLevel.WARN), 081 keepRuntimeFolder(), 082 configureConsole().ignoreLocalConsole(), 083 features(maven().groupId("org.apache.karaf.features").artifactId("standard") 084 .versionAsInProject().classifier("features").type("xml"), "scr"), 085 features(maven().groupId("org.apache.camel.karaf").artifactId("apache-camel") 086 .type("xml").classifier("features").versionAsInProject(), "camel-blueprint"), 087 features(bundle(fcrepoFeatures).start(), "fcrepo-indexing-triplestore", 088 "fcrepo-indexing-solr", "fcrepo-reindexing", "fcrepo-serialization", 089 "fcrepo-fixity", "fcrepo-audit-triplestore"), 090 systemProperty("karaf.reindexing.port").value(reindexingPort), 091 editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort), 092 editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort), 093 editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort), 094 editConfigurationFilePut("etc/org.fcrepo.camel.indexing.triplestore.cfg", "fcrepo.baseUrl", "localhost:" + fcrepoPort + "/fcrepo/rest"), 095 editConfigurationFilePut("etc/org.fcrepo.camel.indexing.triplestore.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort), 096 editConfigurationFilePut("etc/org.fcrepo.camel.indexing.solr.cfg", "fcrepo.baseUrl", "localhost:" + fcrepoPort + "/fcrepo/rest"), 097 editConfigurationFilePut("etc/org.fcrepo.camel.indexing.solr.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort), 098 editConfigurationFilePut("etc/org.fcrepo.camel.reindexing.cfg", "fcrepo.baseUrl", "localhost:" + fcrepoPort + "/fcrepo/rest"), 099 editConfigurationFilePut("etc/org.fcrepo.camel.reindexing.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort), 100 editConfigurationFilePut("etc/org.fcrepo.camel.reindexing.cfg", "rest.port", reindexingPort), 101 editConfigurationFilePut("etc/org.fcrepo.camel.serialization.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort), 102 editConfigurationFilePut("etc/org.fcrepo.camel.audit.triplestore.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort), 103 editConfigurationFilePut("etc/org.fcrepo.camel.fixity.cfg", "jms.brokerUrl", "tcp://localhost:" + jmsPort), 104 }; 105 } 106 107 @Test 108 public void testInstallation() throws Exception { 109 assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core"))); 110 assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-camel"))); 111 assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-indexing-triplestore"))); 112 assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-indexing-solr"))); 113 assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-reindexing"))); 114 assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-serialization"))); 115 assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-audit-triplestore"))); 116 assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-fixity"))); 117 } 118 119 @Test 120 public void testReindexingService() throws Exception { 121 final CloseableHttpClient client = create().build(); 122 final String reindexingUrl = "http://localhost:" + System.getProperty("karaf.reindexing.port") + "/reindexing/"; 123 try (final CloseableHttpResponse response = client.execute(new HttpGet(reindexingUrl))) { 124 assertEquals(SC_OK, response.getStatusLine().getStatusCode()); 125 } 126 127 final HttpPost post = new HttpPost(reindexingUrl); 128 post.addHeader("Content-Type", "application/json"); 129 post.setEntity(new StringEntity("[\"log:fcrepo\"]")); 130 try (final CloseableHttpResponse response = client.execute(post)) { 131 assertEquals(SC_OK, response.getStatusLine().getStatusCode()); 132 } 133 } 134}