Skip to content

Commit

Permalink
ARIES-2165: Duplicate testsupport classes in jmx-itests
Browse files Browse the repository at this point in the history
testsupport build on java 8 seems to be not usable with jmx accepting minimal java 6
  • Loading branch information
alien11689 committed Jan 30, 2025
1 parent 1172a11 commit bdd8264
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 2 deletions.
9 changes: 9 additions & 0 deletions jmx/jmx-itests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<asm-debug-all.version>5.0.3</asm-debug-all.version>
<commons-jexl.version>2.1.1</commons-jexl.version>
<depends-maven-plugin.version>1.5.0</depends-maven-plugin.version>
<javax.inject.version>1</javax.inject.version>
<org.apache.aries.blueprint.jexl.evaluator.version>1.0.0</org.apache.aries.blueprint.jexl.evaluator.version>
<org.apache.aries.blueprint.sample.version>1.0.0</org.apache.aries.blueprint.sample.version>
<org.apache.aries.blueprint.version>1.0.0</org.apache.aries.blueprint.version>
Expand Down Expand Up @@ -103,12 +104,20 @@
<artifactId>org.osgi.compendium</artifactId>
<scope>provided</scope>
</dependency>
<!-- TODO ARIES-2165 restore dependency
<dependency>
<groupId>org.apache.aries.testsupport</groupId>
<artifactId>org.apache.aries.testsupport.unit</artifactId>
<version>${org.apache.aries.testsupport.unit.version}</version>
<scope>test</scope>
</dependency>
-->
<!-- TODO ARIES-2165 remove testsupport transitive dependency -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>${javax.inject.version}</version>
</dependency>
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>org.apache.aries.blueprint.sample</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 WARRANTIESOR 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.aries.itest;

import javax.inject.Inject;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;

/**
* TODO ARIES-2165 Remove when testsupport is added in pom
*
* Base class for Pax Exam 1.2.x based unit tests
*
* Contains the injection point and various utilities used in most tests
*/
public abstract class AbstractIntegrationTest {

/** Gateway to the test OSGi framework */
@Inject
protected BundleContext bundleContext;

/**
* Get a richer version of {@link BundleContext}
*/
public RichBundleContext context() {
return new RichBundleContext(bundleContext);
}

public String getLocalRepo() {
String localRepo = System.getProperty("maven.repo.local");
if (localRepo == null) {
localRepo = System.getProperty("org.ops4j.pax.url.mvn.localRepository");
}
return localRepo;
}


/**
* Help to diagnose bundles that did not start
*
* @throws BundleException
*/
public void showBundles() throws BundleException {
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
System.out.println(bundle.getBundleId() + ":" + bundle.getSymbolicName() + ":" + bundle.getVersion() + ":" + bundle.getState());
}
}

/**
* Helps to diagnose bundles that are not resolved as it will throw a detailed exception
*
* @throws BundleException
*/
public void resolveBundles() throws BundleException {
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
if (bundle.getState() == Bundle.INSTALLED) {
System.out.println("Found non resolved bundle " + bundle.getBundleId() + ":" + bundle.getSymbolicName() + ":" + bundle.getVersion());
bundle.start();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* 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 WARRANTIESOR 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.aries.itest;

import java.io.File;
import java.io.InputStream;
import java.util.Collection;
import java.util.Dictionary;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;

/**
* TODO ARIES-2165 Remove when testsupport is added in pom
*
* {@link BundleContext} wrapper that adds a couple of additional utilities
*
*/
public class RichBundleContext implements BundleContext {
public static final long DEFAULT_TIMEOUT = 15000;

private final BundleContext delegate;

public RichBundleContext(BundleContext delegate) {
this.delegate = delegate;
}


public <T> T getService(Class<T> type) {
return getService(type, null, DEFAULT_TIMEOUT);
}

public <T> T getService(Class<T> type, long timeout) {
return getService(type, null, timeout);
}

public <T> T getService(Class<T> type, String filter) {
return getService(type, filter, DEFAULT_TIMEOUT);
}

public <T> T getService(Class<T> type, String filter, long timeout) {
ServiceTracker tracker = null;
try {
String flt;
if (filter != null) {
if (filter.startsWith("(")) {
flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
} else {
flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
}
} else {
flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
}
Filter osgiFilter = FrameworkUtil.createFilter(flt);
tracker = new ServiceTracker(delegate, osgiFilter, null);
tracker.open();

Object svc = type.cast(tracker.waitForService(timeout));
if (svc == null) {
System.out.println("Could not obtain a service in time, service-ref="+
tracker.getServiceReference()+
", time="+System.currentTimeMillis());
throw new RuntimeException("Gave up waiting for service " + flt);
}
return type.cast(svc);
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid filter", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}


public Bundle getBundleByName(String symbolicName) {
for (Bundle b : delegate.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}

public String getProperty(String key) {
return delegate.getProperty(key);
}

public Bundle getBundle() {
return delegate.getBundle();
}

public Bundle getBundle(String filter) { return delegate.getBundle(filter); }

public Bundle installBundle(String location, InputStream input)
throws BundleException {
return delegate.installBundle(location, input);
}

public Bundle installBundle(String location) throws BundleException {
return delegate.installBundle(location);
}

public Bundle getBundle(long id) {
return delegate.getBundle(id);
}

public Bundle[] getBundles() {
return delegate.getBundles();
}

public void addServiceListener(ServiceListener listener, String filter)
throws InvalidSyntaxException {
delegate.addServiceListener(listener, filter);
}

public void addServiceListener(ServiceListener listener) {
delegate.addServiceListener(listener);
}

public void removeServiceListener(ServiceListener listener) {
delegate.removeServiceListener(listener);
}

public void addBundleListener(BundleListener listener) {
delegate.addBundleListener(listener);
}

public void removeBundleListener(BundleListener listener) {
delegate.removeBundleListener(listener);
}

public void addFrameworkListener(FrameworkListener listener) {
delegate.addFrameworkListener(listener);
}

public void removeFrameworkListener(FrameworkListener listener) {
delegate.removeFrameworkListener(listener);
}

@SuppressWarnings("rawtypes")
public ServiceRegistration registerService(String[] clazzes,
Object service, Dictionary properties) {
return delegate.registerService(clazzes, service, properties);
}

@SuppressWarnings("rawtypes")
public ServiceRegistration registerService(String clazz, Object service,
Dictionary properties) {
return delegate.registerService(clazz, service, properties);
}

public ServiceRegistration registerService(Class clazz, Object service, Dictionary props) {
return delegate.registerService(clazz, service, props);
}

public ServiceReference[] getServiceReferences(String clazz, String filter)
throws InvalidSyntaxException {
return delegate.getServiceReferences(clazz, filter);
}

public Collection getServiceReferences(Class clazz, String filter) throws InvalidSyntaxException {
return delegate.getServiceReferences(clazz, filter);
}

public ServiceReference[] getAllServiceReferences(String clazz,
String filter) throws InvalidSyntaxException {
return delegate.getAllServiceReferences(clazz, filter);
}

public ServiceReference getServiceReference(String clazz) {
return delegate.getServiceReference(clazz);
}

public ServiceReference getServiceReference(Class clazz) { return delegate.getServiceReference(clazz); }

public Object getService(ServiceReference reference) {
return delegate.getService(reference);
}

public boolean ungetService(ServiceReference reference) {
return delegate.ungetService(reference);
}

public File getDataFile(String filename) {
return delegate.getDataFile(filename);
}

public Filter createFilter(String filter) throws InvalidSyntaxException {
return delegate.createFilter(filter);
}


}
19 changes: 19 additions & 0 deletions jmx/jmx-itests/src/test/java/org/apache/aries/itest/packageinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# 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.
#
version 2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected Option jmxRuntime() {
mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.core.whiteboard").versionAsInProject(),
mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.api").versionAsInProject(),
mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.whiteboard").versionAsInProject(),
mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit").versionAsInProject(),
// TODO ARIES-2165 Bring back testsupport in maven
// mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit").versionAsInProject(),
mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.mbeanserver-platform").versionAsInProject()
);
}
Expand Down Expand Up @@ -201,4 +202,4 @@ protected Bundle getBundleByName(String symName) {
assertNotNull("Bundle " + symName + "should be installed", b);
return b;
}
}
}

0 comments on commit bdd8264

Please sign in to comment.