Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Nettleton2010-06-28 21:13:38 +0000
committerBob Nettleton2010-06-28 21:13:38 +0000
commit423099b2ac2ccd5dd9d09e5e9e123392f8a0ae3f (patch)
tree7a33af2e3eb5c5a2fba4efafc3b53653a42a980b
parent125f54055181812fc67505c6294b7c4ba595b5e1 (diff)
downloadorg.eclipse.gemini.naming-423099b2ac2ccd5dd9d09e5e9e123392f8a0ae3f.tar.gz
org.eclipse.gemini.naming-423099b2ac2ccd5dd9d09e5e9e123392f8a0ae3f.tar.xz
org.eclipse.gemini.naming-423099b2ac2ccd5dd9d09e5e9e123392f8a0ae3f.zip
1. Fixed some unit test failures that were present at the time of the Initial Contribution review.
2. Modified the integration-testing suite to use the OSGI Enterprise API bundle without having to implement a workaround in a local maven repository. Currently, the OSGi Enterprise API bundle is not available via maven. This change modifies the Gemini Naming integration tests to use the Spring OSGi Test APIs to add the OSGi Enterprise API bundle to the set of required test bundles at test time. This change is a workaround until the OSGi Enterprise bundle is available in maven.
-rw-r--r--framework/src/main/java/org/eclipse/gemini/naming/Activator.java4
-rw-r--r--framework/src/main/java/org/eclipse/gemini/naming/DefaultRuntimeInitialContextFactoryBuilder.java4
-rw-r--r--framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java1
-rw-r--r--framework/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java54
-rw-r--r--framework/src/test/java/org/eclipse/gemini/naming/OSGiURLContextFactoryTestCase.java75
-rw-r--r--integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextAdminTestCase.java8
-rw-r--r--integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextManagerTestCase.java9
-rw-r--r--integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java8
-rw-r--r--integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java50
9 files changed, 103 insertions, 110 deletions
diff --git a/framework/src/main/java/org/eclipse/gemini/naming/Activator.java b/framework/src/main/java/org/eclipse/gemini/naming/Activator.java
index 7e5b243..c5335e3 100644
--- a/framework/src/main/java/org/eclipse/gemini/naming/Activator.java
+++ b/framework/src/main/java/org/eclipse/gemini/naming/Activator.java
@@ -133,6 +133,7 @@ public class Activator implements BundleActivator {
NamingException namingException =
new NamingException("Error occurred while attempting to set the IntialContextFactoryBuilder.");
namingException.setRootCause(illegalStateException);
+ throw namingException;
}
catch(SecurityException securityException) {
logger.log(Level.SEVERE,
@@ -141,6 +142,7 @@ public class Activator implements BundleActivator {
NamingException namingException =
new NamingException("Error occurred while attempting to set the IntialContextFactoryBuilder.");
namingException.setRootCause(securityException);
+ throw namingException;
}
}
@@ -161,6 +163,7 @@ public class Activator implements BundleActivator {
NamingException namingException =
new NamingException("Error occurred while attempting to set the ObjectFactoryBuilder.");
namingException.setRootCause(illegalStateException);
+ throw namingException;
}
catch(SecurityException securityException) {
logger.log(Level.SEVERE,
@@ -169,6 +172,7 @@ public class Activator implements BundleActivator {
NamingException namingException =
new NamingException("Error occurred while attempting to set the ObjectFactoryBuilder.");
namingException.setRootCause(securityException);
+ throw namingException;
}
}
diff --git a/framework/src/main/java/org/eclipse/gemini/naming/DefaultRuntimeInitialContextFactoryBuilder.java b/framework/src/main/java/org/eclipse/gemini/naming/DefaultRuntimeInitialContextFactoryBuilder.java
index b51e4c8..1c385a8 100644
--- a/framework/src/main/java/org/eclipse/gemini/naming/DefaultRuntimeInitialContextFactoryBuilder.java
+++ b/framework/src/main/java/org/eclipse/gemini/naming/DefaultRuntimeInitialContextFactoryBuilder.java
@@ -41,8 +41,8 @@ class DefaultRuntimeInitialContextFactoryBuilder implements
Logger.getLogger(DefaultRuntimeInitialContextFactoryBuilder.class.getName());
public InitialContextFactory createInitialContextFactory(Hashtable environment) throws NamingException {
-
- if (environment.get(Context.INITIAL_CONTEXT_FACTORY) != null) {
+ if ((environment != null) &&
+ (environment.get(Context.INITIAL_CONTEXT_FACTORY) != null)) {
final String initialContextFactoryName =
(String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
diff --git a/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java b/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java
index 3c8371e..5367502 100644
--- a/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java
+++ b/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java
@@ -69,6 +69,7 @@ class OSGiURLParser {
}
public boolean isServiceListURL() {
+ checkParserState();
return m_isServiceList;
}
diff --git a/framework/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java b/framework/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java
index da5b304..4f1c6fd 100644
--- a/framework/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java
+++ b/framework/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java
@@ -123,32 +123,6 @@ public class ActivatorTestCase extends TestCase {
BundleContext bundleContextMock =
mockSupport.createMock(BundleContext.class);
- setupBundleContextMock(mockSupport, bundleContextMock);
- // expect OSGi URLContextFactory
- Hashtable<String, Object> serviceProperties = new Hashtable<String, Object>();
- serviceProperties.put(JNDIConstants.JNDI_URLSCHEME, "osgi");
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- ObjectFactory.class.getName(),
- OSGiURLContextFactoryServiceFactory.class, serviceProperties);
-
- // expect the "default" InitialContextFactoryBuilder
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- InitialContextFactoryBuilder.class.getName(),
- DefaultRuntimeInitialContextFactoryBuilder.class,
- null);
-
- // expect the JNDIContextManager service registration
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- JNDIContextManager.class.getName(),
- ContextManagerServiceFactoryImpl.class,
- null);
- // expect the JNDIProviderAdmin service registration
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- JNDIProviderAdmin.class.getName(),
- SecurityAwareProviderAdminImpl.class,
- null);
-
-
mockSupport.replayAll();
// begin test
@@ -179,36 +153,8 @@ public class ActivatorTestCase extends TestCase {
// if already set, test can continue
}
-
-
BundleContext bundleContextMock =
mockSupport.createMock(BundleContext.class);
- setupBundleContextMock(mockSupport, bundleContextMock);
- // expect OSGi URLContextFactory
- Hashtable<String, Object> serviceProperties = new Hashtable<String, Object>();
- serviceProperties.put(JNDIConstants.JNDI_URLSCHEME, "osgi");
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- ObjectFactory.class.getName(),
- OSGiURLContextFactoryServiceFactory.class, serviceProperties);
-
- // expect the "default" InitialContextFactoryBuilder
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- InitialContextFactoryBuilder.class.getName(),
- DefaultRuntimeInitialContextFactoryBuilder.class,
- null);
-
- // expect the JNDIContextManager service registration
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- JNDIContextManager.class.getName(),
- ContextManagerServiceFactoryImpl.class,
- null);
- // expect the JNDIProviderAdmin service registration
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- JNDIProviderAdmin.class.getName(),
- SecurityAwareProviderAdminImpl.class,
- null);
-
-
mockSupport.replayAll();
// begin test
diff --git a/framework/src/test/java/org/eclipse/gemini/naming/OSGiURLContextFactoryTestCase.java b/framework/src/test/java/org/eclipse/gemini/naming/OSGiURLContextFactoryTestCase.java
index 24ce1ad..8173002 100644
--- a/framework/src/test/java/org/eclipse/gemini/naming/OSGiURLContextFactoryTestCase.java
+++ b/framework/src/test/java/org/eclipse/gemini/naming/OSGiURLContextFactoryTestCase.java
@@ -15,11 +15,23 @@
package org.eclipse.gemini.naming;
+import java.security.AccessControlContext;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.PrivilegedAction;
+import java.security.ProtectionDomain;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
import javax.naming.Context;
+import javax.naming.NamingException;
import javax.naming.OperationNotSupportedException;
import javax.naming.spi.ObjectFactory;
import org.easymock.EasyMockSupport;
+import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -64,37 +76,42 @@ public class OSGiURLContextFactoryTestCase extends TestCase {
mockSupport.verifyAll();
}
- public void testLookupBundleContext() throws Exception {
- // not sure if this is easily unit testable, since
+ public void testLookupBundleContextWithNoPermissions() throws Exception {
+ // not sure if testing this scenario is easily unit testable, since
// there is interaction with the AccessController
+ // For now, test the failure condition of having a client without
+ // the correct permission
+
+ // mock setup
+ EasyMockSupport mockSupport = new EasyMockSupport();
+ BundleContext bundleContextMock =
+ mockSupport.createMock(BundleContext.class);
+ final Bundle bundleMock =
+ mockSupport.createMock(Bundle.class);
+
+ expect(bundleContextMock.getBundle()).andReturn(bundleMock);
+ expect(bundleMock.getBundleId()).andReturn(new Long(10));
+
+ mockSupport.replayAll();
+ // begin test
+ ObjectFactory testFactory =
+ new OSGiURLContextFactory(bundleContextMock);
+ Object result =
+ testFactory.getObjectInstance(null, null, null, null);
+ assertTrue("OSGiURLContextFactory returned an object that is not a Context",
+ result instanceof Context);
+ final Context context = (Context)result;
+
+ try {
+ context.lookup("osgi:framework/bundleContext");
+ fail("NamingException should have been thrown");
+ } catch(NamingException namingException) {
+ // expected exception
+ assertTrue("NamingException did not contain the expected root exception",
+ namingException.getRootCause() instanceof AccessControlException);
+ }
- // mock setup
-// EasyMockSupport mockSupport = new EasyMockSupport();
-// BundleContext bundleContextMock =
-// mockSupport.createMock(BundleContext.class);
-// Bundle bundleMock =
-// mockSupport.createMock(Bundle.class);
-//
-// expect(bundleContextMock.getBundle()).andReturn(bundleMock);
-// expect(bundleMock.getBundleId()).andReturn(new Long(10));
-// expect(bundleMock.hasPermission(isA(Object.class))).andReturn(true);
-//
-// mockSupport.replayAll();
-// // begin test
-// ObjectFactory testFactory =
-// new OSGiURLContextFactory(bundleContextMock);
-// Object result =
-// testFactory.getObjectInstance(null, null, null, null);
-// assertTrue("OSGiURLContextFactory returned an object that is not a Context",
-// result instanceof Context);
-// Context context = (Context)result;
-//
-// assertSame("OSGiURLContextFactory did not return the expected BundleContext instance",
-// bundleContextMock, context.lookup("osgi:framework/bundleContext"));
-//
-//
-// mockSupport.verifyAll();
- fail("test not implemented yet");
+ mockSupport.verifyAll();
}
public void testLookupService() throws Exception {
diff --git a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextAdminTestCase.java b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextAdminTestCase.java
index ab37a8a..9b9b6cd 100644
--- a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextAdminTestCase.java
+++ b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextAdminTestCase.java
@@ -40,14 +40,6 @@ import org.osgi.service.jndi.JNDIProviderAdmin;
public class ContextAdminTestCase extends NamingTestCase {
- private static String VERSION = "1.0-SNAPSHOT";
-
- protected String[] getTestBundlesNames() {
- return new String[]{ "org.eclipse.gemini.naming, org.eclipse.gemini.naming.impl.bundle-Incubation," + VERSION,
- "org.osgi.service.jndi,org.osgi.service.jndi,1.0",
- };
- }
-
/**
* Verifies that the JNDIProviderAdmin service is made
* available by the Gemini Naming implementation.
diff --git a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextManagerTestCase.java b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextManagerTestCase.java
index a701c8c..f7dbbec 100644
--- a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextManagerTestCase.java
+++ b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/ContextManagerTestCase.java
@@ -52,15 +52,6 @@ import org.osgi.service.jndi.JNDIContextManager;
*
*/
public class ContextManagerTestCase extends NamingTestCase {
-
- private static String VERSION = "1.0-SNAPSHOT";
-
- protected String[] getTestBundlesNames() {
- return new String[]{ "org.eclipse.gemini.naming, org.eclipse.gemini.naming.impl.bundle-Incubation," + VERSION,
- "org.osgi.service.jndi,org.osgi.service.jndi,1.0",
- };
- }
-
/**
* Verifies that if a specific InitialContextFactory is requested by
* a client, and that factory is not available, the Factory Manager will query the
diff --git a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java
index aa03703..457de82 100644
--- a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java
+++ b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java
@@ -58,8 +58,6 @@ import org.osgi.framework.*;
*/
public class FactoryResolutionTestCase extends NamingTestCase {
- private static String VERSION = "1.0-SNAPSHOT";
-
private ClassLoader m_oldClassLoader = null;
protected void onSetUp() throws Exception {
@@ -67,12 +65,6 @@ public class FactoryResolutionTestCase extends NamingTestCase {
m_oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(new TestClassLoaderTwo());
}
-
- protected String[] getTestBundlesNames() {
- return new String[]{ "org.eclipse.gemini.naming, org.eclipse.gemini.naming.impl.bundle-Incubation," + VERSION,
- "org.osgi.service.jndi,org.osgi.service.jndi,1.0",
- };
- }
protected void onTearDown() throws Exception {
diff --git a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java
index 35c32da..5e95672 100644
--- a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java
+++ b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java
@@ -21,6 +21,7 @@
package org.eclipse.gemini.naming.test;
+import java.io.File;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
@@ -29,10 +30,14 @@ import java.util.Set;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;
public abstract class NamingTestCase extends AbstractConfigurableBundleCreatorTests {
+ private static String VERSION = "1.0-SNAPSHOT";
+
private Map m_mapOfServicesToRegistrations =
new HashMap();
@@ -45,6 +50,51 @@ public abstract class NamingTestCase extends AbstractConfigurableBundleCreatorTe
unregisterAllServices();
}
+ /**
+ * Declaratively specify the dependency on the Gemini Naming implementation bundle.
+ */
+ protected String[] getTestBundlesNames() {
+ return new String[]{ "org.eclipse.gemini.naming, org.eclipse.gemini.naming.impl.bundle-Incubation," + VERSION };
+ }
+
+
+ /**
+ * This method overrides some of the loading of the dependencies for a Gemini
+ * Naming integration test run. Currently, the OSGi Enterprise API jar is not available
+ * as a Maven bundle. As a workaround, the Gemini Naming tests will use the bundles
+ * that are set declaratively as a starting point, and then add the OSGi Enterprise API
+ * bundle as a file-based resource.
+ *
+ * Currently, this test depends upon the GEMINI_NAMING_HOME environment variable in order
+ * to locate the OSGi Enterprise API bundle. Once this bundle is available from Maven, this
+ * code should be removed and the maven dependency should be added to the getTestBundlesNames()
+ * implementation above.
+ */
+ @Override
+ protected Resource[] getTestBundles() {
+ // get the existing set of test bundles
+ Resource[] generatedResources = super.getTestBundles();
+ // locate the OSGi Enterprise API jar
+ final String GEMINI_NAMING_HOME =
+ System.getenv("GEMINI_NAMING_HOME");
+ String pathToEnterpriseJar =
+ GEMINI_NAMING_HOME + File.separator + "lib" + File.separator + "osgi.enterprise.jar";
+ FileSystemResource resource =
+ new FileSystemResource(pathToEnterpriseJar);
+
+ Resource[] resourcesToReturn =
+ new Resource[generatedResources.length + 1];
+ for(int i = 0; i < generatedResources.length; i++) {
+ resourcesToReturn[i] = generatedResources[i];
+ }
+
+ // add the OSGi Enterprise API bundle to the list of test bundles
+ int newLength = resourcesToReturn.length;
+ resourcesToReturn[newLength - 1] = resource;
+ // return the new list
+ return resourcesToReturn;
+ }
+
protected void registerService(String serviceType, Object service, Dictionary properties) {
ServiceRegistration registration =
bundleContext.registerService(serviceType, service, properties);

Back to the top