-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARIES-2165: Duplicate testsupport classes in jmx-itests
testsupport build on java 8 seems to be not usable with jmx accepting minimal java 6
- Loading branch information
1 parent
1172a11
commit bdd8264
Showing
5 changed files
with
332 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
jmx/jmx-itests/src/test/java/org/apache/aries/itest/AbstractIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
219 changes: 219 additions & 0 deletions
219
jmx/jmx-itests/src/test/java/org/apache/aries/itest/RichBundleContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
jmx/jmx-itests/src/test/java/org/apache/aries/itest/packageinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters