Repository: karaf Updated Branches: refs/heads/master 08d0c386f -> 307846d5c
[KARAF-4100] Tests after pax-url-2.5.2 update - only one MavenResolver registered Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/307846d5 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/307846d5 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/307846d5 Branch: refs/heads/master Commit: 307846d5c7d95308dacce2531bf2a91f0950a8be Parents: 08d0c38 Author: Grzegorz Grzybek <[email protected]> Authored: Fri Dec 9 20:46:26 2016 +0100 Committer: Grzegorz Grzybek <[email protected]> Committed: Fri Dec 9 20:46:44 2016 +0100 ---------------------------------------------------------------------- itests/pom.xml | 35 +++ .../filtered-resources/etc/config.properties | 216 +++++++++++++++++++ .../etc/org.apache.karaf.features.cfg | 28 +++ .../KarafMinimalMonitoredTestSupport.java | 105 +++++++++ .../apache/karaf/itests/KarafTestSupport.java | 2 +- ...ResolverRegisteredBeforeConfigAdminTest.java | 73 +++++++ ...olverRegisteredOnlyAfterConfigAdminTest.java | 74 +++++++ .../karaf/itests/monitoring/Activator.java | 43 ++++ .../itests/monitoring/RegisteredService.java | 34 +++ .../karaf/itests/monitoring/ServiceMonitor.java | 42 ++++ 10 files changed, 651 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/pom.xml ---------------------------------------------------------------------- diff --git a/itests/pom.xml b/itests/pom.xml index f94364b..834f2de 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -157,6 +157,22 @@ </dependencies> <build> + <testResources> + <testResource> + <directory>${project.basedir}/src/test/resources</directory> + <filtering>false</filtering> + <includes> + <include>**/*</include> + </includes> + </testResource> + <testResource> + <directory>${project.basedir}/src/test/filtered-resources</directory> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </testResource> + </testResources> <plugins> <plugin> <groupId>org.apache.servicemix.tooling</groupId> @@ -196,6 +212,25 @@ </systemPropertyVariables> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <configuration> + <useDefaultDelimiters>false</useDefaultDelimiters> + <delimiters> + <delimiter>@@</delimiter> + </delimiters> + </configuration> + <executions> + <execution> + <id>filter</id> + <phase>generate-resources</phase> + <goals> + <goal>resources</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/filtered-resources/etc/config.properties ---------------------------------------------------------------------- diff --git a/itests/src/test/filtered-resources/etc/config.properties b/itests/src/test/filtered-resources/etc/config.properties new file mode 100644 index 0000000..4659e33 --- /dev/null +++ b/itests/src/test/filtered-resources/etc/config.properties @@ -0,0 +1,216 @@ +################################################################################ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +# +# This file lists Karaf default settings for this particular version of Karaf. +# For easier maintenance when upgrading Karaf and to better document which +# default values have changed, it is recommended to place any changes to +# these values in a custom.properties file in the same folder as this file. +# Each value specified in custom.properties will override the default value +# here. +# + +# +# Properties file inclusions (as a space separated list of relative paths) +# Included files will override the values specified in this file +# NB: ${includes} properties files are mandatory, it means that Karaf will not start +# if the include file is not found +# +${includes} = jre.properties custom.properties + +# +# Properties file inclusions (as a space separated list of relative paths) +# Included files will override the values specified in this file +# NB: ${optionals} properties files are optionals, it means that Karaf will just +# display a warning message but the bootstrap will be performed +# +# ${optionals} = my.properties + +# +# Framework selection properties +# +karaf.framework=felix + +# +# Location of the OSGi frameworks +# +karaf.framework.equinox=mvn\:@@equinox.groupId@@/@@equinox.artifactId@@/@@equinox.version@@ +karaf.framework.felix=mvn\:org.apache.felix/org.apache.felix.framework/@@felix.framework.version@@ + +# +# Framework config properties. +# +org.osgi.framework.system.packages= \ + org.osgi.dto;version="1.0",\ + org.osgi.resource;version="1.0",\ + org.osgi.resource.dto;version="1.0";uses:="org.osgi.dto",\ + org.osgi.framework;version="1.8",\ + org.osgi.framework.dto;version="1.8";uses:="org.osgi.dto",\ + org.osgi.framework.hooks.bundle;version="1.1";uses:="org.osgi.framework",\ + org.osgi.framework.hooks.resolver;version="1.0";uses:="org.osgi.framework.wiring",\ + org.osgi.framework.hooks.service;version="1.1";uses:="org.osgi.framework",\ + org.osgi.framework.hooks.weaving;version="1.1";uses:="org.osgi.framework.wiring",\ + org.osgi.framework.launch;version="1.2";uses:="org.osgi.framework",\ + org.osgi.framework.namespace;version="1.1";uses:="org.osgi.resource",\ + org.osgi.framework.startlevel;version="1.0";uses:="org.osgi.framework",\ + org.osgi.framework.startlevel.dto;version="1.0";uses:="org.osgi.dto",\ + org.osgi.framework.wiring;version="1.2";uses:="org.osgi.framework,org.osgi.resource",\ + org.osgi.framework.wiring.dto;version="1.2";uses:="org.osgi.dto,org.osgi.resource.dto",\ + org.osgi.service.condpermadmin;version="1.1.1";uses:="org.osgi.framework,org.osgi.service.permissionadmin",\ + org.osgi.service.packageadmin;version="1.2";uses:="org.osgi.framework",org.osgi.service.permissionadmin;version="1.2",\ + org.osgi.service.resolver;version="1.0";uses:="org.osgi.resource",\ + org.osgi.service.startlevel;version="1.1";uses:="org.osgi.framework",\ + org.osgi.service.url;version="1.0",\ + org.osgi.util.tracker;version="1.5.1";uses:="org.osgi.framework",\ + org.apache.karaf.version;version="@@karaf.osgi.version@@",\ + org.apache.karaf.jaas.boot.principal;uses:=javax.security.auth;version="@@karaf.osgi.version@@",\ + org.apache.karaf.jaas.boot;uses:="javax.security.auth,javax.security.auth.callback,javax.security.auth.login,javax.security.auth.spi,org.osgi.framework";version="@@karaf.osgi.version@@",\ + ${jre-${java.specification.version}} + +# +# Extra packages appended after standard packages +# +org.osgi.framework.system.packages.extra= \ + org.apache.karaf.branding, \ + org.apache.karaf.jaas.boot.principal, \ + org.apache.karaf.jaas.boot, \ + sun.misc + +org.osgi.framework.system.capabilities= \ + ${eecap-${java.specification.version}}, \ + osgi.service;effective:=active;objectClass=org.osgi.service.packageadmin.PackageAdmin, \ + osgi.service;effective:=active;objectClass=org.osgi.service.resolver.Resolver, \ + osgi.service;effective:=active;objectClass=org.osgi.service.startlevel.StartLevel, \ + osgi.service;effective:=active;objectClass=org.osgi.service.url.URLHandlers + +eecap-9= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1,1.2", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,9" +eecap-1.8= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1,1.2", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8" +eecap-1.7= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1,1.2", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7" +eecap-1.6= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1,1.2", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2,1.3,1.4,1.5,1.6" +eecap-1.5= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1,1.2", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2,1.3,1.4,1.5" +eecap-1.4= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1,1.2", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2,1.3,1.4" +eecap-1.3= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2,1.3" +eecap-1.2= osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0,1.1", \ + osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0,1.1,1.2" + +# +# javax.transaction is needed to avoid class loader constraint violation when using javax.sql +# +org.osgi.framework.bootdelegation=\ + com.sun.*, \ + javax.transaction, \ + javax.transaction.*, \ + javax.xml.crypto, \ + javax.xml.crypto.*, \ + sun.*, \ + org.apache.karaf.jaas.boot, \ + org.apache.karaf.jaas.boot.principal + +# jVisualVM support +# in order to use Karaf with jvisualvm, the org.osgi.framework.bootdelegation property has to contain the org.netbeans.lib.profiler.server package +# and, so, it should look like: +# +# org.osgi.framework.bootdelegation=org.apache.karaf.jaas.boot,org.apache.karaf.jaas.boot.principal,sun.*,com.sun.*,javax.transaction,javax.transaction.*,javax.xml.crypto,javax.xml.crypto.*,org.apache.xerces.jaxp.datatype,org.apache.xerces.stax,org.apache.xerces.parsers,org.apache.xerces.jaxp,org.apache.xerces.jaxp.validation,org.apache.xerces.dom,org.netbeans.lib.profiler.server +# +# YourKit support +# in order to use Karaf with YourKit, the org.osgi.framework.bootdelegation property has to contain the com.yourkit.* packages +#Â and, so, it should look like: +# +# org.osgi.framework.bootdelegation=org.apache.karaf.jaas.boot,org.apache.karaf.jaas.boot.principal,sun.*,com.sun.*,javax.transaction,javax.transaction.*,javax.xml.crypto,javax.xml.crypto.*,org.apache.xerces.jaxp.datatype,org.apache.xerces.stax,org.apache.xerces.parsers,org.apache.xerces.jaxp,org.apache.xerces.jaxp.validation,org.apache.xerces.dom,com.yourkit.* +# + +# +# OSGi Execution Environment +# +org.osgi.framework.executionenvironment=J2SE-1.7,JavaSE-1.7,J2SE-1.6,JavaSE-1.6,J2SE-1.5,JavaSE-1.5,J2SE-1.4,JavaSE-1.4,J2SE-1.3,JavaSE-1.3,J2SE-1.2,,JavaSE-1.2,CDC-1.1/Foundation-1.1,CDC-1.0/Foundation-1.0,J2ME,OSGi/Minimum-1.1,OSGi/Minimum-1.0 + +# +# Set the parent classloader for the bundle to the classloader that loads the Framework (i.e. everything in lib/*.jar) +# +org.osgi.framework.bundle.parent=framework + +# +# Definition of the default bundle start level +# +org.osgi.framework.startlevel.beginning=100 +karaf.startlevel.bundle=80 + +# +# The location of the Karaf shutdown port file +# +karaf.shutdown.port.file=${karaf.data}/port + +# +# Configuration FileMonitor properties +# +felix.fileinstall.enableConfigSave = true +felix.fileinstall.dir = ${karaf.etc} +felix.fileinstall.filter = .*\\.(cfg|config) +felix.fileinstall.poll = 1000 +felix.fileinstall.noInitialDelay = true +felix.fileinstall.log.level = 3 +felix.fileinstall.log.default = jul + +# Use cached urls for bundle CodeSource to avoid +# problems with JCE cached informations, see KARAF-3974 +felix.bundlecodesource.usecachedurls = true + +# +# Delay for writing the framework state to disk in equinox +# must be >= 1000 and <= 1800000 +# +eclipse.stateSaveDelayInterval = 1000 + +# +# OBR Repository list +# This property will be modified by the obr:addUrl and obr:removeUrl commands. +# +obr.repository.url = + +# +# Start blueprint bundles synchronously when possible +# +org.apache.aries.blueprint.synchronous=true + +# +# Do not weave all any classes by default +# +org.apache.aries.proxy.weaving.enabled= + +# +# mvn url handler requires config instance configuration +# +#org.ops4j.pax.url.mvn.requireConfigAdminConfig=true + +# +# Don't delay the console startup. Set to true if you want the console to start after all other bundles +# +karaf.delay.console=false + +# +# Enable native Karaf support for systemd's watchdog. +# +#karaf.systemd.enabled=false http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/filtered-resources/etc/org.apache.karaf.features.cfg ---------------------------------------------------------------------- diff --git a/itests/src/test/filtered-resources/etc/org.apache.karaf.features.cfg b/itests/src/test/filtered-resources/etc/org.apache.karaf.features.cfg new file mode 100644 index 0000000..1ff7d70 --- /dev/null +++ b/itests/src/test/filtered-resources/etc/org.apache.karaf.features.cfg @@ -0,0 +1,28 @@ +################################################################################ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +# +# Comma separated list of features repositories to register by default +# +featuresRepositories = \ + mvn:org.apache.karaf.features/framework/@@project.version@@/xml/features, \ + mvn:org.apache.karaf.features/spring/@@project.version@@/xml/features, \ + mvn:org.apache.karaf.features/standard/@@project.version@@/xml/features +featuresBoot = management +featuresBootAsynchronous=false http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/java/org/apache/karaf/itests/KarafMinimalMonitoredTestSupport.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/KarafMinimalMonitoredTestSupport.java b/itests/src/test/java/org/apache/karaf/itests/KarafMinimalMonitoredTestSupport.java new file mode 100644 index 0000000..fd4cfe3 --- /dev/null +++ b/itests/src/test/java/org/apache/karaf/itests/KarafMinimalMonitoredTestSupport.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.itests; + +import java.io.File; +import java.io.InputStream; +import java.net.URL; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import javax.inject.Inject; + +import org.apache.karaf.itests.monitoring.Activator; +import org.apache.karaf.itests.monitoring.RegisteredService; +import org.apache.karaf.itests.monitoring.ServiceMonitor; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; +import org.ops4j.pax.exam.karaf.options.LogLevelOption; +import org.ops4j.pax.exam.options.MavenArtifactUrlReference; +import org.ops4j.pax.exam.options.TimeoutOption; +import org.ops4j.store.Handle; +import org.ops4j.store.Store; +import org.ops4j.store.intern.TemporaryStore; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.karaf.itests.KarafTestSupport.*; +import static org.ops4j.pax.exam.CoreOptions.maven; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*; +import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle; + +public abstract class KarafMinimalMonitoredTestSupport { + + public static Logger LOG = LoggerFactory.getLogger(KarafMinimalMonitoredTestSupport.class); + + @Inject + protected BundleContext bundleContext; + + // don't extend, because we don't want @Rule Retry + private static KarafTestSupport karafTestSupport = new KarafTestSupport(); + + public Option[] baseConfig() throws Exception { + MavenArtifactUrlReference karafUrl = maven() + .groupId("org.apache.karaf").artifactId("apache-karaf-minimal") + .versionAsInProject().type("tar.gz"); + + InputStream monitorBundle = bundle() + .set(Constants.BUNDLE_SYMBOLICNAME, "monitor") + .set(Constants.BUNDLE_ACTIVATOR, Activator.class.getName()) + .set(Constants.IMPORT_PACKAGE, "org.osgi.framework") + .set(Constants.EXPORT_PACKAGE, Activator.class.getPackage().getName()) + .set(Constants.BUNDLE_VERSION, "1.0.0") + .set(Constants.BUNDLE_MANIFESTVERSION, "2") + .add(Activator.class) + .add(RegisteredService.class) + .add(ServiceMonitor.class) + .build(); + + String rmiRegistryPort = Integer.toString(karafTestSupport.getAvailablePort(Integer.parseInt(MIN_RMI_REG_PORT), Integer.parseInt(MAX_RMI_REG_PORT))); + String rmiServerPort = Integer.toString(karafTestSupport.getAvailablePort(Integer.parseInt(MIN_RMI_SERVER_PORT), Integer.parseInt(MAX_RMI_SERVER_PORT))); + + Store<InputStream> store = new TemporaryStore(new File("target/exam"), false); + + Handle handle = store.store(monitorBundle); + URL url = store.getLocation(handle).toURL(); + + Option[] baseOptions = new Option[] { + karafDistributionConfiguration().frameworkUrl(karafUrl).name("Apache Karaf").unpackDirectory(new File("target/exam")), + // enable JMX RBAC security, thanks to the KarafMBeanServerBuilder + configureSecurity().disableKarafMBeanServerBuilder(), + keepRuntimeFolder(), + logLevel(LogLevelOption.LogLevel.INFO), + editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort), + editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort), + editConfigurationFilePut("etc/startup.properties", "file:../../" + new File(url.toURI()).getName(), "1"), +// new TimeoutOption(3600000), +// KarafDistributionOption.debugConfiguration("8889", true), + }; + List<Option> options = new LinkedList<>(Arrays.asList(baseOptions)); + + options.addAll(Arrays.asList( + editConfigurationFilePut("etc/org.apache.karaf.features.cfg", new File("target/test-classes/etc/org.apache.karaf.features.cfg")) + )); + + return options.toArray(new Option[options.size()]); + } + +} http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java index 861a38e..aada8a7 100644 --- a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java +++ b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java @@ -210,7 +210,7 @@ public class KarafTestSupport { }; } - private int getAvailablePort(int min, int max) { + protected int getAvailablePort(int min, int max) { for (int i = min; i <= max; i++) { try { ServerSocket socket = new ServerSocket(i); http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredBeforeConfigAdminTest.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredBeforeConfigAdminTest.java b/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredBeforeConfigAdminTest.java new file mode 100644 index 0000000..367aeb1 --- /dev/null +++ b/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredBeforeConfigAdminTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.itests; + +import java.io.File; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import org.apache.karaf.itests.monitoring.Activator; +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.ProbeBuilder; +import org.ops4j.pax.exam.TestProbeBuilder; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerMethod; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile; + +/** + * Test shows that without <code>org.ops4j.pax.url.mvn.requireConfigAdminConfig=true</code>, + * there are two instances of MavenResolver service being published. + */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerMethod.class) +public class MavenResolverRegisteredBeforeConfigAdminTest extends KarafMinimalMonitoredTestSupport { + + public static Logger LOG = LoggerFactory.getLogger(MavenResolverRegisteredBeforeConfigAdminTest.class); + + @Configuration + public Option[] config() throws Exception { + List<Option> result = new LinkedList<>(); + result.addAll(Arrays.asList(super.baseConfig())); + result.addAll(Arrays.asList(editConfigurationFilePut("etc/org.apache.karaf.features.cfg", new File("target/test-classes/etc/org.apache.karaf.features.cfg")))); + // etc/config.properties which doesn't have org.ops4j.pax.url.mvn.requireConfigAdminConfig=true + result.add(replaceConfigurationFile("etc/config.properties", new File("target/test-classes/etc/config.properties"))); + + return result.toArray(new Option[result.size()]); + } + + @Test + public void mavenResolverAvailable() throws Exception { + assertNotNull(bundleContext); + ServiceReference<List> sr = bundleContext.getBundle(0L).getBundleContext().getServiceReference(List.class); + List<String> services = bundleContext.getService(sr); + assertTrue("There should be two registrations/unregistrations of MavenResolver before final (ConfigAdmin based) registration", services.stream() + .filter(v -> v.equals("org.ops4j.pax.url.mvn.MavenResolver")).count() == 5L); + } + +} http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredOnlyAfterConfigAdminTest.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredOnlyAfterConfigAdminTest.java b/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredOnlyAfterConfigAdminTest.java new file mode 100644 index 0000000..0f1bfe5 --- /dev/null +++ b/itests/src/test/java/org/apache/karaf/itests/MavenResolverRegisteredOnlyAfterConfigAdminTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.itests; + +import java.io.File; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import org.apache.karaf.itests.monitoring.Activator; +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.ProbeBuilder; +import org.ops4j.pax.exam.TestProbeBuilder; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerMethod; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFileExtend; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile; + +/** + * Test shows that without <code>org.ops4j.pax.url.mvn.requireConfigAdminConfig=true</code>, + * there are two instances of MavenResolver service being published. + */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerMethod.class) +public class MavenResolverRegisteredOnlyAfterConfigAdminTest extends KarafMinimalMonitoredTestSupport { + + public static Logger LOG = LoggerFactory.getLogger(MavenResolverRegisteredOnlyAfterConfigAdminTest.class); + + @Configuration + public Option[] config() throws Exception { + List<Option> result = new LinkedList<>(); + result.addAll(Arrays.asList(super.baseConfig())); + result.addAll(Arrays.asList(editConfigurationFilePut("etc/org.apache.karaf.features.cfg", new File("target/test-classes/etc/org.apache.karaf.features.cfg")))); + // etc/config.properties which have org.ops4j.pax.url.mvn.requireConfigAdminConfig=true + result.add(editConfigurationFileExtend("etc/config.properties", "etc/org.apache.karaf.features.cfg", "true")); + + return result.toArray(new Option[result.size()]); + } + + @Test + public void mavenResolverAvailable() throws Exception { + assertNotNull(bundleContext); + ServiceReference<List> sr = bundleContext.getBundle(0L).getBundleContext().getServiceReference(List.class); + List<String> services = bundleContext.getService(sr); + assertTrue("There should be only one MavenResolver registration - after non-INITIAL ConfigAdmin update", services.stream() + .filter(v -> v.equals("org.ops4j.pax.url.mvn.MavenResolver")).count() == 1L); + } + +} http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java b/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java new file mode 100644 index 0000000..bd49a06 --- /dev/null +++ b/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.itests.monitoring; + +import java.util.List; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +public class Activator implements BundleActivator { + + private ServiceRegistration<List> registration; + private ServiceMonitor service; + + @Override + public void start(BundleContext context) throws Exception { + service = new ServiceMonitor(context.getBundle(0L).getBundleContext()); + registration = context.registerService(List.class, service.getServices(), null); + context.addServiceListener(service::addServiceEvent); + } + + @Override + public void stop(BundleContext context) throws Exception { + context.removeServiceListener(service::addServiceEvent); + registration.unregister(); + } + +} http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java b/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java new file mode 100644 index 0000000..51f51b5 --- /dev/null +++ b/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.itests.monitoring; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; + +public class RegisteredService { + + private String[] objectClass; + private int type; + private Object service; + + public RegisteredService(BundleContext context, ServiceEvent event) { + objectClass = (String[])event.getServiceReference().getProperty("objectClass"); + type = event.getType(); + service = context.getService(event.getServiceReference()); + } + +} http://git-wip-us.apache.org/repos/asf/karaf/blob/307846d5/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java b/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java new file mode 100644 index 0000000..3712c7e --- /dev/null +++ b/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.itests.monitoring; + +import java.util.LinkedList; +import java.util.List; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; + +public class ServiceMonitor { + + private BundleContext systemContext; + private List<String> services = new LinkedList<>(); + + public ServiceMonitor(BundleContext systemContext) { + this.systemContext = systemContext; + } + + public void addServiceEvent(ServiceEvent event) { + services.add(((String[])event.getServiceReference().getProperty("objectClass"))[0]); + } + + public List<String> getServices() { + return services; + } + +}
