geronimo-osgi-support-1.0.orig/ 0000755 0000000 0000000 00000000000 11400013473 013460 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/ 0000755 0000000 0000000 00000000000 11400013473 017526 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/ 0000755 0000000 0000000 00000000000 11400013473 020315 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/ 0000755 0000000 0000000 00000000000 11400013473 021241 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/ 0000755 0000000 0000000 00000000000 11400013473 023253 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/ 0000755 0000000 0000000 00000000000 11400013473 024426 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/providers/ 0000755 0000000 0000000 00000000000 11400013473 026443 5 ustar ././@LongLink 0000000 0000000 0000000 00000000216 00000000000 011564 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/providers/org.apache.geronimo.osgi.registry.itest.TestTarget2 geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/providers/org.apache0000644 0000000 0000000 00000002024 11361326165 030406 0 ustar # 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.
# Tests normal class mapping...NOTE: this uses
# TestTarget2 to ensure we're picking up the
# services version, not the providers one.
org.apache.geronimo.osgi.itestb.TestTargetTwo # Used as an override to map TestTarget to TestTargetTwo
././@LongLink 0000000 0000000 0000000 00000000215 00000000000 011563 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/providers/org.apache.geronimo.osgi.registry.itest.TestTarget geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/providers/org.apache0000644 0000000 0000000 00000001771 11361326165 030416 0 ustar # 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.
# Tests normal class mapping...NOTE: this uses
# TestTarget2 to ensure we're picking up the
# services version, not the providers one.
# Tests normal class mapping....
org.apache.geronimo.osgi.itestb.TestTarget
././@LongLink 0000000 0000000 0000000 00000000216 00000000000 011564 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/providers/org.apache.geronimo.osgi.registry.itest.TestTarget4 geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/OSGI-INF/providers/org.apache0000644 0000000 0000000 00000002136 11361326165 030412 0 ustar # 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.
# Tests normal class mapping...NOTE: this uses
# TestTarget2 to ensure we're picking up the
# services version, not the providers one.
# Tests normal class mapping....
org.apache.geronimo.osgi.itestb.TestTarget
# using multiple provider definitions for a single key
org.apache.geronimo.osgi.itestb.TestTarget2
geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/META-INF/ 0000755 0000000 0000000 00000000000 11400013473 024413 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/META-INF/services/ 0000755 0000000 0000000 00000000000 11400013473 026236 5 ustar ././@LongLink 0000000 0000000 0000000 00000000215 00000000000 011563 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/META-INF/services/org.apache.geronimo.osgi.registry.itest.MultiTarget geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/META-INF/services/org.apache.0000644 0000000 0000000 00000001656 11361326165 030271 0 ustar # 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.
# Tests normal class mapping for multiple providers
org.apache.geronimo.osgi.itestb.TestTarget
org.apache.geronimo.osgi.itestb.TestTarget2
././@LongLink 0000000 0000000 0000000 00000000214 00000000000 011562 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/META-INF/services/org.apache.geronimo.osgi.registry.itest.TestTarget geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/resources/META-INF/services/org.apache.0000644 0000000 0000000 00000001730 11361326165 030262 0 ustar # 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.
# Tests normal class mapping...NOTE: this uses
# TestTarget2 to ensure we're picking up the
# services version, not the providers one.
org.apache.geronimo.osgi.itestb.TestTarget2
geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/ 0000755 0000000 0000000 00000000000 11400013473 022162 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/ 0000755 0000000 0000000 00000000000 11400013473 022751 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/ 0000755 0000000 0000000 00000000000 11400013473 024172 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/ 0000755 0000000 0000000 00000000000 11400013473 026011 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/ 0000755 0000000 0000000 00000000000 11400013473 026752 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/ 0000755 0000000 0000000 00000000000 11400013473 030244 5 ustar ././@LongLink 0000000 0000000 0000000 00000000165 00000000000 011567 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTargetTwo.java geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/Te0000644 0000000 0000000 00000002353 11350204263 030545 0 ustar /**
* 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.geronimo.osgi.itestb;
public class TestTargetTwo {
public TestTargetTwo() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTargetTwo";
}
}
././@LongLink 0000000 0000000 0000000 00000000163 00000000000 011565 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTarget2.java geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/Te0000644 0000000 0000000 00000002345 11350204263 030546 0 ustar /**
* 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.geronimo.osgi.itestb;
public class TestTarget2 {
public TestTarget2() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget2";
}
}
././@LongLink 0000000 0000000 0000000 00000000163 00000000000 011565 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTarget3.java geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/Te0000644 0000000 0000000 00000002345 11350204263 030546 0 ustar /**
* 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.geronimo.osgi.itestb;
public class TestTarget3 {
public TestTarget3() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget3";
}
}
././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011564 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTarget.java geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/Te0000644 0000000 0000000 00000002342 11350204263 030543 0 ustar /**
* 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.geronimo.osgi.itestb;
public class TestTarget {
public TestTarget() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
geronimo-osgi-support-1.0.orig/geronimo-osgi-itestb/pom.xml 0000644 0000000 0000000 00000004454 11364013573 021064 0 ustar
4.0.0org.apache.geronimo.specsgeronimo-osgi-support1.0org.apache.geronimo.specsgeronimo-osgi-itestbbundleGeronimo OSGi integration tests1.0
Separately built test bundle for use in the various integration tests. This
bundle will have provider and services definitions used to test different class
provider resolution scenarios.
org.apache.felixmaven-bundle-plugin${groupId}.${artifactId};singleton=trueorg.apache.geronimo.osgi.testb
geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/ 0000755 0000000 0000000 00000000000 11400013473 021415 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/ 0000755 0000000 0000000 00000000000 11400013473 022204 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/ 0000755 0000000 0000000 00000000000 11400013473 023163 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/ 0000755 0000000 0000000 00000000000 11400013473 024104 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/ 0000755 0000000 0000000 00000000000 11400013473 024673 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/ 0000755 0000000 0000000 00000000000 11400013473 026114 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/ 0000755 0000000 0000000 00000000000 11400013473 027733 5 ustar ././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/ geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000755 0000000 0000000 00000000000 11400013473 030674 5 ustar ././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011567 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/ geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000755 0000000 0000000 00000000000 11400013473 030674 5 ustar ././@LongLink 0000000 0000000 0000000 00000000164 00000000000 011566 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/ geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000755 0000000 0000000 00000000000 11400013473 030674 5 ustar ././@LongLink 0000000 0000000 0000000 00000000230 00000000000 011560 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorMultipleProviderTest.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000014702 11350204263 030705 0 ustar /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiLocatorMultipleProviderTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// the target code we're testing
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itestb"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly.
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testLocator() throws Exception {
Bundle bundle1 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itesta");
Bundle bundle2 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itestb");
// check for the target class a verify we got the correct one
Class> target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// now stop the first bundle, which should shuffle the deck
bundle1.stop();
// The returned class should now be from the second provisioned bundle
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget", target.getName());
// now stop the the second bundle. There should not be anything registred with that name now.
bundle2.stop();
// The returned class should now be null since there are no registered providers
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNull(target);
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
././@LongLink 0000000 0000000 0000000 00000000206 00000000000 011563 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTargetTwo.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000002363 11350204263 030705 0 ustar /**
* 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.geronimo.osgi.registry.itest;
public class TestTargetTwo {
public TestTargetTwo() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTargetTwo";
}
}
././@LongLink 0000000 0000000 0000000 00000000210 00000000000 011556 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorTest.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000030727 11353120551 030712 0 ustar /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiLocatorTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// the target code we're testing...
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
// bundle containing test resources
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// we don't have any direct references to this class, so force it to be
// included.
.add(org.apache.geronimo.osgi.registry.itest.TestTargetLocal.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly.
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testLocator() throws Exception {
Bundle bundle1 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itesta");
// check for the target class a verify we got the correct one
Class> target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
List> targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget");
// should return one entry and it should be the same class mapping
assertEquals(1, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", targets.get(0).getName());
// now load the second target interface. This is really the same as the first, but
// uses a different commenting style.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget2");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTargetTwo", target.getName());
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget2");
// should return one entry and it should be the same class mapping
assertEquals(1, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTargetTwo", targets.get(0).getName());
// this class is defined using the header form. It should map back to itself.
target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta.TestTarget2");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", target.getName());
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.itesta.TestTarget2");
// should return one entry and it should be the same class mapping
assertEquals(1, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", targets.get(0).getName());
// This is not in the provider registry, so it should just return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.ClassNotFound");
assertNull(target);
// This is in the provider registry, but the class cannot be loaded. This should still
// return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.NoClass");
assertNull(target);
// This is defined as a header, but the class cannot be loaded. This should still
// return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta..NoClass");
assertNull(target);
// Now test some of the class loading support. This will search the provider registry first,
// then the classpath. We should still get the registered class returned.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass());
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// similar to the above, but since the context class is not provided, this will fail to resolve the
// locally resident class.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget", null);
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// And just a straight load class of a bundle-local class.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTargetTwo", this.getClass());
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.registry.itest.TestTargetTwo", target.getName());
// this one should be handled from the provider registry and resolve to a class
// defined in the test bundle.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget4", this.getClass());
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// this should not be located at all
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.ClassNotFound", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this is in the registry, but there is an error resolving the class
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this is defined with a header, but there is an error resolving the class
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.itesta.NoClass", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this mapping defines multiple classes for the single key. The first should be returned for
// a singleton request, the locate all should return in definition order
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget4");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget4");
// should return one entry and it should be the same class mapping
assertEquals(2, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", targets.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", targets.get(1).getName());
// now stop the first bundle, which should shuffle the deck
bundle1.stop();
// The returned class should now be null since there are no registered providers
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNull(target);
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget");
// should return an empty list
assertNotNull(targets);
assertEquals(0, targets.size());
// The returned class should now be null since there are no registered providers
target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta.TestTarget2");
assertNull(target);
// This is in the provider registry, but the class cannot be loaded. This should still
// return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.NoClass");
assertNull(target);
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
././@LongLink 0000000 0000000 0000000 00000000204 00000000000 011561 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTarget2.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000002355 11350204263 030706 0 ustar /**
* 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.geronimo.osgi.registry.itest;
public class TestTarget2 {
public TestTarget2() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget2";
}
}
././@LongLink 0000000 0000000 0000000 00000000204 00000000000 011561 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTarget3.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000002355 11350204263 030706 0 ustar /**
* 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.geronimo.osgi.registry.itest;
public class TestTarget3 {
public TestTarget3() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget3";
}
}
././@LongLink 0000000 0000000 0000000 00000000210 00000000000 011556 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTargetLocal.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000002364 11350204263 030706 0 ustar /**
* 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.geronimo.osgi.registry.itest;
public class TestTargetLocal {
public TestTargetLocal() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
././@LongLink 0000000 0000000 0000000 00000000213 00000000000 011561 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000017055 11353120551 030711 0 ustar /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiNoRegistryTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// NOTE: This test is supposed to test that the ProviderLocator
// does not raise exceptions if the provider registry is not
// available and the ProviderRegistry api class is not resolvable.
// mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
// bundle containing test resources
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// we don't have any direct references to this class, so force it to be
// included.
.add(org.apache.geronimo.osgi.registry.itest.TestTargetLocal.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly...make sure the resolution
// is optional, which is the typical way of dealing with this
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api;resolution:=optional")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testLocator() throws Exception {
// Ok, just a few quick tests to make sure things fail gracefully.
Class> target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNull(target);
List> targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget");
// should return an empty list
assertNotNull(targets);
assertEquals(0, targets.size());
// this should not be located at all
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.ClassNotFound", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// now some service tests
Object service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// now testing a multiple instances get. This should only pick up the definition from the
// bundle that includes the SPI-Provider header (testa)
List services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
// same set of tests, but this time we're looking for classes, not instances
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(target);
List> classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(0, classes.size());
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
././@LongLink 0000000 0000000 0000000 00000000217 00000000000 011565 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiServiceLocatorTest.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000034356 11353120551 030714 0 ustar /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiServiceLocatorTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// the target code we're testing...
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
// bundle containing test resources
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
// this bundle opts out of the SPI-Provider status
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itestb"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// we don't have any direct references to this class, so force it to be
// included.
.add(org.apache.geronimo.osgi.registry.itest.TestTargetLocal.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly.
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testServiceLocator() throws Exception {
Bundle bundle1 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itesta");
// now testing the services lookup and instantiation mechanism. These should all be satisfied by
// the extender rather than loaded from the classpath.
Object service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service.getClass().getName());
// we expect a new instance on each call. Verify that the instances are different
Object service2 = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service2);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service2.getClass().getName());
assertNotSame(service, service2);
// now testing a multiple instances get. This should only pick up the definition from the
// bundle that includes the SPI-Provider header (testa)
List services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(1, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", services.get(0).getClass().getName());
// these should be different instances
assertNotSame(service, services.get(0));
// this is multiple instances defined in a single services file.
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itesta.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(2, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", services.get(0).getClass().getName());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", services.get(1).getClass().getName());
// this should not be found
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// again, not found. Should return an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this should return an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (NullPointerException e) {
}
// but this should just give an empty list again
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (InstantiationException e) {
}
// and again, an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (IllegalAccessException e) {
}
// empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// same set of tests, but this time we're looking for classes, not instances
Class> target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(target);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", target.getName());
// now testing a multiple instances get. This should pick up a definition from both
// jars on the class path
List> classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(1, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(0).getName());
// this is multiple instances defined in a single services file.
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itesta.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(2, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", classes.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(1).getName());
// this should not be found
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(target);
// again, not found. Should return an empty list
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(0, classes.size());
// this should result in an exception
try {
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// an empty list again
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertTrue(classes.isEmpty());
// now stop the first bundle, which should remove the service defintions.
bundle1.stop();
// repeat the first queries, which should fail now
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// this should revert to an empty list now.
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
././@LongLink 0000000 0000000 0000000 00000000203 00000000000 011560 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTarget.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/0000644 0000000 0000000 00000002352 11350204263 030703 0 ustar /**
* 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.geronimo.osgi.registry.itest;
public class TestTarget {
public TestTarget() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
geronimo-osgi-support-1.0.orig/geronimo-osgi-registry-itests/pom.xml 0000644 0000000 0000000 00000014313 11364013573 022746 0 ustar
4.0.0org.apache.geronimo.specsgeronimo-osgi-support1.0org.apache.geronimo.specsgeronimo-osgi-registry-itests
Tests for the OSGi provider registry inside of an OSGi framework.
org.apache.geronimo.specsgeronimo-osgi-registrytestorg.apache.geronimo.specsgeronimo-osgi-locatortestorg.apache.geronimo.specsgeronimo-osgi-itestatestorg.apache.geronimo.specsgeronimo-osgi-itestbtestorg.osgiorg.osgi.coretestorg.osgiorg.osgi.compendiumtestorg.ops4j.pax.exampax-examtestorg.ops4j.pax.exampax-exam-junittestorg.ops4j.pax.exampax-exam-container-defaulttestorg.ops4j.pax.exampax-exam-junit-extender-impltestorg.ops4j.pax.swissboxpax-swissbox-tinybundlestestorg.ops4j.pax.loggingpax-logging-apitestorg.apache.felixorg.apache.felix.configadmintestorg.apache.servicemix.toolingdepends-maven-plugin1.1generate-depends-filegenerate-depends-fileorg.apache.maven.pluginsmaven-surefire-plugintruefalse**/OSGi*.javaorg.codehaus.mojofailsafe-maven-plugin2.4.3-alpha-1integration-testintegration-testverifyverifytruefalse**/OSGiLocatorTest.java**/OSGiNoRegistryTest.java**/OSGiLocatorMultipleProviderTest.java**/OSGiServiceLocatorTest.java
geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/ 0000755 0000000 0000000 00000000000 11400013473 021210 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/ 0000755 0000000 0000000 00000000000 11400013473 021777 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/ 0000755 0000000 0000000 00000000000 11400013473 022756 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/ 0000755 0000000 0000000 00000000000 11400013473 023677 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/ 0000755 0000000 0000000 00000000000 11400013473 024466 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/ 0000755 0000000 0000000 00000000000 11400013473 025707 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/ 0000755 0000000 0000000 00000000000 11400013473 027526 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/ 0000755 0000000 0000000 00000000000 11400013473 030467 5 ustar ././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011565 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator/ geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/l0000755 0000000 0000000 00000000000 11400013473 030643 5 ustar ././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011564 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator/itest/ geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/l0000755 0000000 0000000 00000000000 11400013473 030643 5 ustar ././@LongLink 0000000 0000000 0000000 00000000211 00000000000 011557 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator/itest/NonOSGiLocatorTest.java geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/l0000644 0000000 0000000 00000026566 11350204263 030667 0 ustar /*
* 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.geronimo.osgi.loader.itest;
import java.io.InputStream;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.apache.geronimo.osgi.locator.ProviderLocator;
public class NonOSGiLocatorTest {
@Test
public void testLocator() throws Exception {
// this is verifying that the ProviderLocater can be called when used outside of
// an OSGi framework without causing an exception. This will verify that the OSGi
// classes are not on the classpath before attempting this.
try {
this.getClass().getClassLoader().loadClass("org.osgi.util.tracker.ServiceTracker");
fail("OSGi framework classes must not be on the class path for this test");
} catch (ClassNotFoundException e) {
// this should happen if the test is run correctly.
}
// Run outside of an OSGi framework, this should just return null without
// causing an error
Class> target = ProviderLocator.locate("org.apache.geronimo.osgi.locator.itest.TestTarget");
assertNull(target);
// this should be located on our local classpath, so it should get a good return
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.locator.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.locator.itest.TestTarget", target.getName());
// this will be on our dependency class path, so it should still be located.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.itesta.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// this should not be located at all
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.ClassNotFound");
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// now testing the services lookup and instantiation mechanism
Object service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service.getClass().getName());
// we expect a new instance on each call. Verify that the instances are different
Object service2 = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service2);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service2.getClass().getName());
assertNotSame(service, service2);
// now testing a multiple instances get. This should pick up a definition from both
// jars on the class path
List services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(2, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", services.get(0).getClass().getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", services.get(1).getClass().getName());
assertNotSame(service, services.get(0));
// this is multiple instances defined in a single services file.
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(2, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget", services.get(0).getClass().getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", services.get(1).getClass().getName());
// this should not be found
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// again, not found. Should return an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (NullPointerException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (NullPointerException e) {
}
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (InstantiationException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (InstantiationException e) {
}
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (IllegalAccessException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (IllegalAccessException e) {
}
// same set of tests, but this time we're looking for classes, not instances
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(target);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", target.getName());
// now testing a multiple instances get. This should pick up a definition from both
// jars on the class path
List> classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(2, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", classes.get(1).getName());
// this is multiple instances defined in a single services file.
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(2, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget", classes.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", classes.get(1).getName());
// this should not be found
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(target);
// again, not found. Should return an empty list
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(0, classes.size());
// this should result in an exception
try {
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// as should this
try {
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
}
}
././@LongLink 0000000 0000000 0000000 00000000201 00000000000 011556 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator/itest/TestTarget.java geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/l0000644 0000000 0000000 00000002351 11350204263 030651 0 ustar /**
* 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.geronimo.osgi.locator.itest;
public class TestTarget {
public TestTarget() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
geronimo-osgi-support-1.0.orig/geronimo-osgi-locator-itests/pom.xml 0000644 0000000 0000000 00000005600 11364013573 022540 0 ustar
4.0.0org.apache.geronimo.specsgeronimo-osgi-support1.0org.apache.geronimo.specsgeronimo-osgi-locator-itests
This project contains integration tests to ensure that the code
in the locator will function correctly if used outside of an OSGi framework.
These tests will have no dependnecies on any OSGi classes when run, and should
function without error.
org.apache.geronimo.specsgeronimo-osgi-locatortestorg.apache.geronimo.specsgeronimo-osgi-itestatestorg.apache.geronimo.specsgeronimo-osgi-itestbtestjunitjunittestorg.apache.maven.pluginsmaven-surefire-plugintruefalse
geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/ 0000755 0000000 0000000 00000000000 11400013473 020104 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/ 0000755 0000000 0000000 00000000000 11400013472 020672 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/ 0000755 0000000 0000000 00000000000 11400013472 021616 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/ 0000755 0000000 0000000 00000000000 11400013472 022537 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/ 0000755 0000000 0000000 00000000000 11400013472 023326 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/apache/ 0000755 0000000 0000000 00000000000 11400013472 024547 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/apache/geronimo/ 0000755 0000000 0000000 00000000000 11400013472 026366 5 ustar geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/ 0000755 0000000 0000000 00000000000 11400013472 027327 5 ustar ././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registr0000755 0000000 0000000 00000000000 11400013473 030730 5 ustar ././@LongLink 0000000 0000000 0000000 00000000200 00000000000 011555 L ustar root root geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java geronimo-osgi-support-1.0.orig/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registr0000644 0000000 0000000 00000062046 11353120551 030745 0 ustar /**
* 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.geronimo.osgi.registry;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.osgi.framework.Bundle;
import org.osgi.service.log.LogService;
/**
* The implementation of the provider registry used to store
* the bundle registrations.
*/
public class ProviderRegistryImpl implements org.apache.geronimo.osgi.registry.api.ProviderRegistry {
// indicates a bundle wishes to opt in to the META-INF/services registration and tracking.
public static final String OPT_IN_HEADER = "SPI-Provider";
// provider classes exported via a header.
public static final String EXPORT_PROVIDER_HEADER = "Export-SPI-Provider";
// our mapping between a provider id and the implementation information. There
// might be a one-to-many relationship between the ids and implementing classes.
private SPIRegistry providers = new SPIRegistry();
// our mapping between an interface name and a META-INF/services SPI implementation. There
// might be a one-to-many relationship between the ids and implementing classes.
private SPIRegistry serviceProviders = new SPIRegistry();
// our base Activator (used as a service source)
private Activator activator;
public ProviderRegistryImpl(Activator activator) {
this.activator = activator;
}
/**
* Add a bundle to the provider registry. This searches
* for services information in the OSGI-INF/providers
* directory of the bundle and registers this information
* in a provider registry. Bundles that need to locate
* class instances can use the provider registry to
* locate classes that might reside in other bundles.
*
* @param bundle The source bundle.
*
* @return A map of the located registrations. Returns null if
* this bundle does not contain any providers.
*/
public Object addBundle(Bundle bundle) {
log(LogService.LOG_DEBUG, "adding bundle " + bundle);
// create a tracker item for this bundle. This will record all of the information
// that's relevent to this bundle
BundleResources tracker = new BundleResources(bundle);
// if the tracker found information of interest, return it to the
// BundleTracker to let it know we need to watch this one.
return tracker.needsTracking() ? tracker : null;
}
/**
* Remove a bundle from the registry.
*
* @param bundle The target bundle.
*/
public void removeBundle(Bundle bundle, Object obj) {
log(LogService.LOG_DEBUG, "removing bundle " + bundle);
BundleResources tracker = (BundleResources)obj;
if (tracker != null) {
tracker.remove();
}
}
/**
* Register an individual provivider item by its provider identifier.
*
* @param id The provider id.
* @param provider The loader used to resolve the provider class.
*/
protected void registerProvider(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "registering provider " + provider);
providers.register(provider);
}
/**
* Removed a provider registration for a named provider id.
*
* @param id The target id
* @param provider The provider registration instance
*/
protected void unregisterProvider(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "unregistering provider " + provider);
providers.unregister(provider);
}
/**
* Register an individual provivider item by its provider identifier.
*
* @param id The provider id.
* @param provider The loader used to resolve the provider class.
*/
protected void registerService(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "registering service " + provider);
serviceProviders.register(provider);
}
/**
* Removed a provider registration for a named provider id.
*
* @param id The target id
* @param provider The provider registration instance
*/
protected void unregisterService(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "unregistering service " + provider);
serviceProviders.unregister(provider);
}
/**
* Locate a class by its provider id indicator. .
*
* @param providerId The provider id (generally, a fully qualified class name).
*
* @return The Class corresponding to this provider id. Returns null
* if this is not registered or the indicated class can't be
* loaded.
*/
public Class> locate(String providerId) {
// see if we have a registered match for this...getting just the first instance
BundleProviderLoader loader = providers.getLoader(providerId);
if (loader != null) {
try {
// try to load this. We always return null
return loader.loadClass();
} catch (Exception e) {
e.printStackTrace();
// just swallow this and return null. The exception has already
// been logged.
}
}
// no match to return
return null;
}
/**
* Locate all class files that match a given provider id.
*
* @param providerId The target provider identifier.
*
* @return A List containing the class objects corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located.
*/
public List> locateAll(String providerId) {
List> classes = new ArrayList>();
List l = providers.getLoaders(providerId);
// this returns null if nothing is found.
if (l != null) {
for (BundleProviderLoader c : l) {
try {
classes.add(c.loadClass());
} catch (Exception e) {
// just swallow this and proceed to the next. The exception has
// already been logged.
}
}
}
return classes;
}
/**
* Locate and instantiate an instance of a service provider
* defined in the META-INF/services directory of tracked bundles.
*
* @param providerId The name of the target interface class.
*
* @return The service instance. Returns null if no service defintions
* can be located.
* @exception Exception Any classloading or other exceptions thrown during
* the process of creating this service instance.
*/
public Object getService(String providerId) throws Exception {
// see if we have a registered match for this...getting just the first instance
BundleProviderLoader loader = serviceProviders.getLoader(providerId);
if (loader != null) {
// try to load this and create an instance. Any/all exceptions get
// thrown here
return loader.createInstance();
}
// no match to return
return null;
}
/**
* Locate all services that match a given provider id and create instances.
*
* @param providerId The target provider identifier.
*
* @return A List containing the instances corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located or created
*/
public List