You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ga...@apache.org on 2009/10/06 22:41:32 UTC

svn commit: r822489 [3/3] - in /incubator/aries/trunk/jndi-contrib: jndi-core/src/main/java/org/apache/aries/jndi/ jndi-core/src/main/java/org/apache/aries/jndi/startup/ jndi-core/src/test/java/org/apache/aries/jndi/ jndi-url/src/main/java/org/apache/a...

Modified: incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceHelperTest.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceHelperTest.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceHelperTest.java Tue Oct  6 20:41:31 2009
@@ -1,210 +1,210 @@
-///*
-// * Licensed to the Apache Software Foundation (ASF) under one
-// * or more contributor license agreements.  See the NOTICE file
-// * distributed with this work for additional information
-// * regarding copyright ownership.  The ASF licenses this file
-// * to you under the Apache License, Version 2.0 (the
-// * "License"); you may not use this file except in compliance
-// * with the License.  You may obtain a copy of the License at
-// *
-// *   http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing,
-// * software distributed under the License is distributed on an
-// * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
-// * KIND, either express or implied.  See the License for the
-// * specific language governing permissions and limitations
-// * under the License.
-// */
-//package org.apache.aries.jndi.url;
-//
-//import static org.junit.Assert.assertEquals;
-//import static org.junit.Assert.assertFalse;
-//import static org.junit.Assert.assertNotNull;
-//import static org.junit.Assert.assertTrue;
-//
-//import java.lang.reflect.Field;
-//import java.util.Hashtable;
-//import java.util.List;
-//import java.util.Properties;
-//
-//import mocks.BundleContextMock;
-//import mocks.BundleMock;
-//
-//import org.junit.After;
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.osgi.framework.Bundle;
-//import org.osgi.framework.BundleContext;
-//import org.osgi.framework.ServiceFactory;
-//import org.osgi.framework.ServiceReference;
-//import org.osgi.framework.ServiceRegistration;
-//
-//import com.ibm.aries.unittest.mocks.MethodCall;
-//import com.ibm.aries.unittest.mocks.Skeleton;
-//import org.apache.aries.jndi.services.ServiceHelper;
-//import org.apache.aries.jndi.url.Activator;
-//
-//
-///**
-// * This class contains tests for the ServiceHelper
-// */
-//public class ServiceHelperTest
-//{
-//  /** The service we register by default */
-//  private Thread service;
-//  /** The bundle context for the test */
-//  private BundleContext bc;
-//  
-//  /**
-//   * This method does the setup to ensure we always have a service.
-//   * @throws NoSuchFieldException 
-//   * @throws SecurityException 
-//   * @throws IllegalAccessException 
-//   * @throws IllegalArgumentException 
-//   */
-//  @Before
-//  public void registerService() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
-//  {
-//    
-//    bc =  Skeleton.newMock(new BundleContextMock(), BundleContext.class);
-//    new Activator().start(bc);
-//    
-//    Field f = ServiceHelper.class.getDeclaredField("context");
-//    f.setAccessible(true);
-//    f.set(null, bc);
-//
-//    service = new Thread();
-//    
-//    registerService(service);
-//  }
-//
-//  /**
-//   * Register a service in our map.
-//   * 
-//   * @param service2 The service to register.
-//   */
-//  private void registerService(Thread service2)
-//  {
-//    ServiceFactory factory = Skeleton.newMock(ServiceFactory.class);
-//    Skeleton skel = Skeleton.getSkeleton(factory);
-//    
-//    skel.setReturnValue(new MethodCall(ServiceFactory.class, "getService", Bundle.class, ServiceRegistration.class), service2);
-//    
-//    bc.registerService(new String[] {"java.lang.Runnable"}, factory, new Hashtable<String, String>());
-//  }
-//  
-//  /**
-//   * Make sure we clear the caches out before the next test.
-//   */
-//  @After
-//  public void teardown()
-//  {
-//    BundleContextMock.clear();
-//  }
-//  
-//  /**
-//   * Check that the basic behaviour is correct. Do we call ungetService, do
-//   * we call getService the right number of times.
-//   */
-//  @Test
-//  public void getAService()
-//  {
-//    Bundle b = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
-//    
-//    Skeleton skel = Skeleton.getSkeleton(b);
-//    
-//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
-//    
-//    skel = Skeleton.getSkeleton(b.getBundleContext());
-//
-//    Object retrievedService = ServiceHelper.getService("java.lang.Runnable", null);
-//    
-//    assertNotNull("We could not locate the service in the registry", retrievedService);
-//    
-//    assertTrue("We didn't get back the service we expected", service == retrievedService);
-//    
-//    MethodCall getService = new MethodCall(BundleContext.class, "getService", ServiceReference.class);
-//    MethodCall ungetService = new MethodCall(BundleContext.class, "ungetService", ServiceReference.class);
-//    
-//    skel.assertNotCalled(ungetService);
-//    skel.assertCalledExactNumberOfTimes(getService, 1);
-//
-//    Object retrievedService2 = ServiceHelper.getService("java.lang.Runnable", null);
-//
-//    assertTrue("We got different objects, which we did not want", retrievedService == retrievedService2);
-//    skel.assertCalledExactNumberOfTimes(getService, 2);
-//    skel.assertCalledExactNumberOfTimes(ungetService, 1);
-//  }
-//  
-//  /**
-//   * This method checks that we get two different services from different
-//   * bundles if the thread context classloader is different.
-//   */
-//  @Test
-//  public void getAServiceFromTwoDifferentApplications()
-//  {
-//    Bundle b = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
-//    
-//    Skeleton skel = Skeleton.getSkeleton(b);
-//    
-//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
-//    
-//    Object retrievedService = ServiceHelper.getService("java.lang.Runnable", null);
-//    Bundle b2 = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
-//    
-//    skel = Skeleton.getSkeleton(b2);
-//    
-//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
-//    Object retrievedService2 = ServiceHelper.getService("java.lang.Runnable", null);
-//    
-//    assertNotNull("We could not locate the service in the registry", retrievedService);
-//    assertNotNull("We could not locate the service in the registry", retrievedService2);
-//    
-//    assertTrue("We got different objects, which we did not want", retrievedService == retrievedService2);
-//    
-//    assertFalse("We expected different bundles from our calls to the BundleMaker, but we got the same one", b == b2);
-//    
-//    MethodCall getService = new MethodCall(BundleContext.class, "getService", ServiceReference.class);
-//    Skeleton.getSkeleton(b.getBundleContext()).assertCalledExactNumberOfTimes(getService, 1);
-//    Skeleton.getSkeleton(b2.getBundleContext()).assertCalledExactNumberOfTimes(getService, 1);
-//  }
-//  
-//  /**
-//   * This test checks that the getServices method returns the expected number of
-//   * services, and that it changes when new services are registered.
-//   */
-//  @Test
-//  public void getMultipleServices()
-//  {
-//    Bundle b = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
-//    
-//    Skeleton skel = Skeleton.getSkeleton(b);
-//    
-//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
-//    
-//    MethodCall getService = new MethodCall(BundleContext.class, "getService", ServiceReference.class);
-//    MethodCall ungetService = new MethodCall(BundleContext.class, "ungetService", ServiceReference.class);
-//    
-//    List<?> services = ServiceHelper.getServices("java.lang.Runnable", null);
-//
-//    skel = Skeleton.getSkeleton(b.getBundleContext());
-//
-//    skel.assertNotCalled(ungetService);
-//    skel.assertCalledExactNumberOfTimes(getService, 1);
-//
-//    assertEquals("At this point we really should only have one service.", 1, services.size());
-//    Thread anotherService = new Thread();
-//    registerService(anotherService);
-//    
-//    services = ServiceHelper.getServices("java.lang.Runnable", null);
-//    
-//    assertEquals("At this point we really should have two services.", 2, services.size());
-//    assertTrue("The master service was not there, odd.", services.contains(service));
-//    assertTrue("The service we added just for this test was not there, odd.", services.contains(anotherService));
-//    
-//    // this should be 3 times, once for the first call to getServices, and twice for the second
-//    skel.assertCalledExactNumberOfTimes(getService, 3);
-//    skel.assertCalledExactNumberOfTimes(ungetService, 1);
-//  }
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one
+// * or more contributor license agreements.  See the NOTICE file
+// * distributed with this work for additional information
+// * regarding copyright ownership.  The ASF licenses this file
+// * to you under the Apache License, Version 2.0 (the
+// * "License"); you may not use this file except in compliance
+// * with the License.  You may obtain a copy of the License at
+// *
+// *   http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing,
+// * software distributed under the License is distributed on an
+// * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+// * KIND, either express or implied.  See the License for the
+// * specific language governing permissions and limitations
+// * under the License.
+// */
+//package org.apache.aries.jndi.url;
+//
+//import static org.junit.Assert.assertEquals;
+//import static org.junit.Assert.assertFalse;
+//import static org.junit.Assert.assertNotNull;
+//import static org.junit.Assert.assertTrue;
+//
+//import java.lang.reflect.Field;
+//import java.util.Hashtable;
+//import java.util.List;
+//import java.util.Properties;
+//
+//import mocks.BundleContextMock;
+//import mocks.BundleMock;
+//
+//import org.junit.After;
+//import org.junit.Before;
+//import org.junit.Test;
+//import org.osgi.framework.Bundle;
+//import org.osgi.framework.BundleContext;
+//import org.osgi.framework.ServiceFactory;
+//import org.osgi.framework.ServiceReference;
+//import org.osgi.framework.ServiceRegistration;
+//
+//import com.ibm.aries.unittest.mocks.MethodCall;
+//import com.ibm.aries.unittest.mocks.Skeleton;
+//import org.apache.aries.jndi.services.ServiceHelper;
+//import org.apache.aries.jndi.url.Activator;
+//
+//
+///**
+// * This class contains tests for the ServiceHelper
+// */
+//public class ServiceHelperTest
+//{
+//  /** The service we register by default */
+//  private Thread service;
+//  /** The bundle context for the test */
+//  private BundleContext bc;
+//  
+//  /**
+//   * This method does the setup to ensure we always have a service.
+//   * @throws NoSuchFieldException 
+//   * @throws SecurityException 
+//   * @throws IllegalAccessException 
+//   * @throws IllegalArgumentException 
+//   */
+//  @Before
+//  public void registerService() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
+//  {
+//    
+//    bc =  Skeleton.newMock(new BundleContextMock(), BundleContext.class);
+//    new Activator().start(bc);
+//    
+//    Field f = ServiceHelper.class.getDeclaredField("context");
+//    f.setAccessible(true);
+//    f.set(null, bc);
+//
+//    service = new Thread();
+//    
+//    registerService(service);
+//  }
+//
+//  /**
+//   * Register a service in our map.
+//   * 
+//   * @param service2 The service to register.
+//   */
+//  private void registerService(Thread service2)
+//  {
+//    ServiceFactory factory = Skeleton.newMock(ServiceFactory.class);
+//    Skeleton skel = Skeleton.getSkeleton(factory);
+//    
+//    skel.setReturnValue(new MethodCall(ServiceFactory.class, "getService", Bundle.class, ServiceRegistration.class), service2);
+//    
+//    bc.registerService(new String[] {"java.lang.Runnable"}, factory, new Hashtable<String, String>());
+//  }
+//  
+//  /**
+//   * Make sure we clear the caches out before the next test.
+//   */
+//  @After
+//  public void teardown()
+//  {
+//    BundleContextMock.clear();
+//  }
+//  
+//  /**
+//   * Check that the basic behaviour is correct. Do we call ungetService, do
+//   * we call getService the right number of times.
+//   */
+//  @Test
+//  public void getAService()
+//  {
+//    Bundle b = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
+//    
+//    Skeleton skel = Skeleton.getSkeleton(b);
+//    
+//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
+//    
+//    skel = Skeleton.getSkeleton(b.getBundleContext());
+//
+//    Object retrievedService = ServiceHelper.getService("java.lang.Runnable", null);
+//    
+//    assertNotNull("We could not locate the service in the registry", retrievedService);
+//    
+//    assertTrue("We didn't get back the service we expected", service == retrievedService);
+//    
+//    MethodCall getService = new MethodCall(BundleContext.class, "getService", ServiceReference.class);
+//    MethodCall ungetService = new MethodCall(BundleContext.class, "ungetService", ServiceReference.class);
+//    
+//    skel.assertNotCalled(ungetService);
+//    skel.assertCalledExactNumberOfTimes(getService, 1);
+//
+//    Object retrievedService2 = ServiceHelper.getService("java.lang.Runnable", null);
+//
+//    assertTrue("We got different objects, which we did not want", retrievedService == retrievedService2);
+//    skel.assertCalledExactNumberOfTimes(getService, 2);
+//    skel.assertCalledExactNumberOfTimes(ungetService, 1);
+//  }
+//  
+//  /**
+//   * This method checks that we get two different services from different
+//   * bundles if the thread context classloader is different.
+//   */
+//  @Test
+//  public void getAServiceFromTwoDifferentApplications()
+//  {
+//    Bundle b = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
+//    
+//    Skeleton skel = Skeleton.getSkeleton(b);
+//    
+//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
+//    
+//    Object retrievedService = ServiceHelper.getService("java.lang.Runnable", null);
+//    Bundle b2 = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
+//    
+//    skel = Skeleton.getSkeleton(b2);
+//    
+//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
+//    Object retrievedService2 = ServiceHelper.getService("java.lang.Runnable", null);
+//    
+//    assertNotNull("We could not locate the service in the registry", retrievedService);
+//    assertNotNull("We could not locate the service in the registry", retrievedService2);
+//    
+//    assertTrue("We got different objects, which we did not want", retrievedService == retrievedService2);
+//    
+//    assertFalse("We expected different bundles from our calls to the BundleMaker, but we got the same one", b == b2);
+//    
+//    MethodCall getService = new MethodCall(BundleContext.class, "getService", ServiceReference.class);
+//    Skeleton.getSkeleton(b.getBundleContext()).assertCalledExactNumberOfTimes(getService, 1);
+//    Skeleton.getSkeleton(b2.getBundleContext()).assertCalledExactNumberOfTimes(getService, 1);
+//  }
+//  
+//  /**
+//   * This test checks that the getServices method returns the expected number of
+//   * services, and that it changes when new services are registered.
+//   */
+//  @Test
+//  public void getMultipleServices()
+//  {
+//    Bundle b = Skeleton.newMock(new BundleMock("scooby.doo", new Properties()), Bundle.class);
+//    
+//    Skeleton skel = Skeleton.getSkeleton(b);
+//    
+//    Thread.currentThread().setContextClassLoader(((BundleMock)skel.getTemplateObject()).getClassLoader());
+//    
+//    MethodCall getService = new MethodCall(BundleContext.class, "getService", ServiceReference.class);
+//    MethodCall ungetService = new MethodCall(BundleContext.class, "ungetService", ServiceReference.class);
+//    
+//    List<?> services = ServiceHelper.getServices("java.lang.Runnable", null);
+//
+//    skel = Skeleton.getSkeleton(b.getBundleContext());
+//
+//    skel.assertNotCalled(ungetService);
+//    skel.assertCalledExactNumberOfTimes(getService, 1);
+//
+//    assertEquals("At this point we really should only have one service.", 1, services.size());
+//    Thread anotherService = new Thread();
+//    registerService(anotherService);
+//    
+//    services = ServiceHelper.getServices("java.lang.Runnable", null);
+//    
+//    assertEquals("At this point we really should have two services.", 2, services.size());
+//    assertTrue("The master service was not there, odd.", services.contains(service));
+//    assertTrue("The service we added just for this test was not there, odd.", services.contains(anotherService));
+//    
+//    // this should be 3 times, once for the first call to getServices, and twice for the second
+//    skel.assertCalledExactNumberOfTimes(getService, 3);
+//    skel.assertCalledExactNumberOfTimes(ungetService, 1);
+//  }
 //}
\ No newline at end of file

Propchange: incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java Tue Oct  6 20:41:31 2009
@@ -1,354 +1,354 @@
-///*
-// * Licensed to the Apache Software Foundation (ASF) under one
-// * or more contributor license agreements.  See the NOTICE file
-// * distributed with this work for additional information
-// * regarding copyright ownership.  The ASF licenses this file
-// * to you under the Apache License, Version 2.0 (the
-// * "License"); you may not use this file except in compliance
-// * with the License.  You may obtain a copy of the License at
-// *
-// *   http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing,
-// * software distributed under the License is distributed on an
-// * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
-// * KIND, either express or implied.  See the License for the
-// * specific language governing permissions and limitations
-// * under the License.
-// */
-//package org.apache.aries.jndi.url;
-//
-//import static org.junit.Assert.assertEquals;
-//import static org.junit.Assert.assertFalse;
-//import static org.junit.Assert.assertNotNull;
-//import static org.junit.Assert.assertTrue;
-//
-//import java.lang.reflect.Field;
-//import java.util.Hashtable;
-//import java.util.Properties;
-//
-//import javax.naming.Binding;
-//import javax.naming.Context;
-//import javax.naming.InitialContext;
-//import javax.naming.NameClassPair;
-//import javax.naming.NameNotFoundException;
-//import javax.naming.NamingEnumeration;
-//import javax.naming.NamingException;
-//import javax.naming.spi.ObjectFactory;
-//
-//import mocks.BundleContextMock;
-//import mocks.BundleMock;
-//
-//import org.junit.After;
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.osgi.framework.Bundle;
-//import org.osgi.framework.BundleContext;
-//import org.osgi.framework.ServiceFactory;
-//import org.osgi.framework.ServiceReference;
-//import org.osgi.framework.ServiceRegistration;
-//
-//import com.ibm.aries.unittest.mocks.MethodCall;
-//import com.ibm.aries.unittest.mocks.Skeleton;
-//import org.apache.aries.jndi.ContextHelper;
-//import org.apache.aries.jndi.OSGiObjectFactoryBuilder;
-//import org.apache.aries.jndi.services.ServiceHelper;
-//import org.apache.aries.jndi.url.Activator;
-//
-///**
-// * Tests for our JNDI implementation for the service registry.
-// */
-//public class ServiceRegistryContextTest
-//{
-//  /** The service we register by default */
-//  private Thread service;
-//  /** The bundle context for the test */
-//  private BundleContext bc;
-//  /** The service registration for the service */
-//  private ServiceRegistration reg;
-//  
-//  /**
-//   * This method does the setup to ensure we always have a service.
-//   * @throws NamingException 
-//   * @throws NoSuchFieldException 
-//   * @throws SecurityException 
-//   * @throws IllegalAccessException 
-//   * @throws IllegalArgumentException 
-//   */
-//  @Before
-//  public void registerService() throws NamingException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException 
-//  {
-//    bc =  Skeleton.newMock(new BundleContextMock(), BundleContext.class);
-//    new Activator().start(bc);
-//    new com.ibm.osgi.jndi.startup.Activator().start(bc);
-//    
-//    Field f = ServiceHelper.class.getDeclaredField("context");
-//    f.setAccessible(true);
-//    f.set(null, bc);
-//    f = ContextHelper.class.getDeclaredField("context");
-//    f.setAccessible(true);
-//    f.set(null, bc);
-//    f = OSGiObjectFactoryBuilder.class.getDeclaredField("context");
-//    f.setAccessible(true);
-//    f.set(null, bc);
-//
-//
-//    service = new Thread();
-//    
-//    registerService(service);
-//  }
-//  
-//  /**
-//   * Register a service in our map.
-//   * 
-//   * @param service2 The service to register.
-//   */
-//  private void registerService(Thread service2)
-//  {
-//    ServiceFactory factory = Skeleton.newMock(ServiceFactory.class);
-//    Skeleton skel = Skeleton.getSkeleton(factory);
-//    
-//    skel.setReturnValue(new MethodCall(ServiceFactory.class, "getService", Bundle.class, ServiceRegistration.class), service2);
-//    
-//    Hashtable<String, String> props = new Hashtable<String, String>();
-//    props.put("rubbish", "smelly");
-//    
-//    reg = bc.registerService(new String[] {"java.lang.Runnable"}, factory, props);
-//  }
-//  
-//  /**
-//   * Make sure we clear the caches out before the next test.
-//   */
-//  @After
-//  public void teardown()
-//  {
-//    BundleContextMock.clear();
-//    
-//    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-//  }
-//  
-//  /**
-//   * This test checks that we correctly register and deregister the url context
-//   * object factory in the service registry.
-//   */
-//  @Test
-//  public void testJNDIRegistration()
-//  {
-//    ServiceReference ref = bc.getServiceReference(ObjectFactory.class.getName());
-//    
-//    assertNotNull("The aries url context object factory was not registered", ref);
-//    
-//    ObjectFactory factory = (ObjectFactory) bc.getService(ref);
-//    
-//    assertNotNull("The aries url context object factory was null", factory);
-//  }
-//  
-//  /**
-//   * This test does a simple JNDI lookup to prove that works.
-//   * @throws NamingException
-//   */
-//  @Test
-//  public void simpleJNDILookup() throws NamingException
-//  {
-//    System.setProperty(Context.URL_PKG_PREFIXES, "helloMatey");
-//        
-//    InitialContext ctx = new InitialContext(new Hashtable<Object, Object>());
-//    
-//    BundleMock mock = new BundleMock("scooby.doo", new Properties());
-//    
-//    Thread.currentThread().setContextClassLoader(mock.getClassLoader());
-//    
-//    Object s = ctx.lookup("aries:services/java.lang.Runnable");
-//    
-//    assertNotNull("We didn't get a service back from our lookup :(", s);
-//    
-//    assertEquals("The SR did not return the object we expected", service, s);
-//    
-//    Skeleton skel = Skeleton.getSkeleton(mock.getBundleContext());
-//    
-//    skel.assertCalled(new MethodCall(BundleContext.class, "getAllServiceReferences", "java.lang.Runnable", null));
-//
-//    mock = new BundleMock("scooby.doo", new Properties());
-//    
-//    Thread.currentThread().setContextClassLoader(mock.getClassLoader());
-//
-//    s = ctx.lookup("osgi:services/java.lang.Runnable");
-//    
-//    // Check we have the packages set correctly
-//    
-//    String packages = System.getProperty(Context.URL_PKG_PREFIXES, null);
-//    
-//    assertTrue(ctx.getEnvironment().containsValue(packages));
-//
-//    
-//    assertNotNull("We didn't get a service back from our lookup :(", s);
-//    
-//    assertEquals("The SR did not return the object we expected", service, s);
-//
-//    skel = Skeleton.getSkeleton(mock.getBundleContext());
-//    skel.assertCalled(new MethodCall(BundleContext.class, "getAllServiceReferences", "java.lang.Runnable", null));
-//  }
-//
-//  /**
-//   * This test checks that we can pass a filter in without things blowing up.
-//   * Right now our mock service registry does not implement filtering, so the
-//   * effect is the same as simpleJNDILookup, but we at least know it is not
-//   * blowing up.
-//   * 
-//   * @throws NamingException
-//   */
-//  @Test
-//  public void jndiLookupWithFilter() throws NamingException
-//  {
-//    InitialContext ctx = new InitialContext();
-//    
-//    Object s = ctx.lookup("aries:services/java.lang.Runnable/(rubbish=smelly)");
-//    
-//    assertNotNull("We didn't get a service back from our lookup :(", s);
-//    
-//    assertEquals("The SR did not return the object we expected", service, s);
-//    
-//    Skeleton.getSkeleton(bc).assertCalled(new MethodCall(BundleContext.class, "getAllServiceReferences", "java.lang.Runnable", "(rubbish=smelly)"));
-//  }
-//  
-//  /**
-//   * Check that we get a NameNotFoundException if we lookup after the service
-//   * has been unregistered.
-//   * 
-//   * @throws NamingException
-//   */
-//  @Test(expected=NameNotFoundException.class)
-//  public void testLookupWhenServiceHasBeenRemoved() throws NamingException
-//  {
-//    reg.unregister();
-//    InitialContext ctx = new InitialContext();
-//    
-//    ctx.lookup("aries:services/java.lang.Runnable");
-//  }
-//  
-//  /**
-//   * Check that we get a NameNotFoundException if we lookup something not in the
-//   * registry.
-//   * 
-//   * @throws NamingException
-//   */
-//  @Test(expected=NameNotFoundException.class)
-//  public void testLookupForServiceWeNeverHad() throws NamingException
-//  {
-//    InitialContext ctx = new InitialContext();
-//    
-//    ctx.lookup("aries:services/java.lang.Integer");
-//  }
-//  
-//  /**
-//   * This test checks that we can list the contents of the repository using the
-//   * list method
-//   * 
-//   * @throws NamingException
-//   */
-//  @Test
-//  public void listRepositoryContents() throws NamingException
-//  {
-//    InitialContext ctx = new InitialContext();
-//    
-//    NamingEnumeration<NameClassPair> serviceList = ctx.list("aries:services/java.lang.Runnable/(rubbish=smelly)");
-//    
-//    checkThreadRetrievedViaListMethod(serviceList);
-//    
-//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
-//    
-//    //Now add a second service
-//    
-//    registerService(new Thread());
-//    
-//    serviceList = ctx.list("aries:services/java.lang.Runnable/(rubbish=smelly)");
-//    
-//    checkThreadRetrievedViaListMethod(serviceList);
-//    
-//    checkThreadRetrievedViaListMethod(serviceList);
-//    
-//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
-//    
-//  }
-//
-//  /**
-//   * Check that the NamingEnumeration passed in has another element, which represents a java.lang.Thread
-//   * @param serviceList
-//   * @throws NamingException
-//   */
-//  private void checkThreadRetrievedViaListMethod(NamingEnumeration<NameClassPair> serviceList)
-//      throws NamingException
-//  {
-//    assertTrue("The repository was empty", serviceList.hasMoreElements());
-//    
-//    NameClassPair ncp = serviceList.next();
-//    
-//    assertNotNull("We didn't get a service back from our lookup :(", ncp);
-//    
-//    assertNotNull("The object from the SR was null", ncp.getClassName());
-//    
-//    assertEquals("The service retrieved was not of the correct type", "java.lang.Thread", ncp.getClassName());
-//    
-//    assertEquals("aries:services/java.lang.Runnable/(rubbish=smelly)", ncp.getName().toString());
-//  }
-//  
-//  /**
-//   * This test checks that we can list the contents of the repository using the
-//   * list method
-//   * 
-//   * @throws NamingException
-//   */
-//  @Test
-//  public void listRepositoryBindings() throws NamingException
-//  {
-//    InitialContext ctx = new InitialContext();
-//    
-//    NamingEnumeration<Binding> serviceList = ctx.listBindings("aries:services/java.lang.Runnable/(rubbish=smelly)");
-//    
-//    Object returnedService = checkThreadRetrievedViaListBindingsMethod(serviceList);
-//    
-//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
-//    
-//    assertTrue("The returned service was not the service we expected", returnedService == service);
-//    
-//    //Now add a second service
-//    Thread secondService = new Thread();
-//    registerService(secondService);
-//    
-//    serviceList = ctx.listBindings("aries:services/java.lang.Runnable/(rubbish=smelly)");
-//    
-//    Object returnedService1 = checkThreadRetrievedViaListBindingsMethod(serviceList);
-//    
-//    Object returnedService2 = checkThreadRetrievedViaListBindingsMethod(serviceList);
-//    
-//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
-//    
-//    assertTrue("The services were not the ones we expected!",(returnedService1 == service || returnedService2 == service) && (returnedService1 == secondService || returnedService2 == secondService) && (returnedService1 != returnedService2));
-//    
-//  }
-//
-//  /**
-//   * Check that the NamingEnumeration passed in has another element, which represents a java.lang.Thread
-//   * @param serviceList
-//   * @return the object in the registry
-//   * @throws NamingException
-//   */
-//  private Object checkThreadRetrievedViaListBindingsMethod(NamingEnumeration<Binding> serviceList)
-//      throws NamingException
-//  {
-//    assertTrue("The repository was empty", serviceList.hasMoreElements());
-//    
-//    Binding binding = serviceList.nextElement();
-//    
-//    assertNotNull("We didn't get a service back from our lookup :(", binding);
-//    
-//    assertNotNull("The object from the SR was null", binding.getObject());
-//    
-//    assertTrue("The service retrieved was not of the correct type", binding.getObject() instanceof Thread);
-//    
-//    assertEquals("aries:services/java.lang.Runnable/(rubbish=smelly)", binding.getName().toString());
-//    
-//    return binding.getObject();
-//  }
-//  
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one
+// * or more contributor license agreements.  See the NOTICE file
+// * distributed with this work for additional information
+// * regarding copyright ownership.  The ASF licenses this file
+// * to you under the Apache License, Version 2.0 (the
+// * "License"); you may not use this file except in compliance
+// * with the License.  You may obtain a copy of the License at
+// *
+// *   http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing,
+// * software distributed under the License is distributed on an
+// * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+// * KIND, either express or implied.  See the License for the
+// * specific language governing permissions and limitations
+// * under the License.
+// */
+//package org.apache.aries.jndi.url;
+//
+//import static org.junit.Assert.assertEquals;
+//import static org.junit.Assert.assertFalse;
+//import static org.junit.Assert.assertNotNull;
+//import static org.junit.Assert.assertTrue;
+//
+//import java.lang.reflect.Field;
+//import java.util.Hashtable;
+//import java.util.Properties;
+//
+//import javax.naming.Binding;
+//import javax.naming.Context;
+//import javax.naming.InitialContext;
+//import javax.naming.NameClassPair;
+//import javax.naming.NameNotFoundException;
+//import javax.naming.NamingEnumeration;
+//import javax.naming.NamingException;
+//import javax.naming.spi.ObjectFactory;
+//
+//import mocks.BundleContextMock;
+//import mocks.BundleMock;
+//
+//import org.junit.After;
+//import org.junit.Before;
+//import org.junit.Test;
+//import org.osgi.framework.Bundle;
+//import org.osgi.framework.BundleContext;
+//import org.osgi.framework.ServiceFactory;
+//import org.osgi.framework.ServiceReference;
+//import org.osgi.framework.ServiceRegistration;
+//
+//import com.ibm.aries.unittest.mocks.MethodCall;
+//import com.ibm.aries.unittest.mocks.Skeleton;
+//import org.apache.aries.jndi.ContextHelper;
+//import org.apache.aries.jndi.OSGiObjectFactoryBuilder;
+//import org.apache.aries.jndi.services.ServiceHelper;
+//import org.apache.aries.jndi.url.Activator;
+//
+///**
+// * Tests for our JNDI implementation for the service registry.
+// */
+//public class ServiceRegistryContextTest
+//{
+//  /** The service we register by default */
+//  private Thread service;
+//  /** The bundle context for the test */
+//  private BundleContext bc;
+//  /** The service registration for the service */
+//  private ServiceRegistration reg;
+//  
+//  /**
+//   * This method does the setup to ensure we always have a service.
+//   * @throws NamingException 
+//   * @throws NoSuchFieldException 
+//   * @throws SecurityException 
+//   * @throws IllegalAccessException 
+//   * @throws IllegalArgumentException 
+//   */
+//  @Before
+//  public void registerService() throws NamingException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException 
+//  {
+//    bc =  Skeleton.newMock(new BundleContextMock(), BundleContext.class);
+//    new Activator().start(bc);
+//    new com.ibm.osgi.jndi.startup.Activator().start(bc);
+//    
+//    Field f = ServiceHelper.class.getDeclaredField("context");
+//    f.setAccessible(true);
+//    f.set(null, bc);
+//    f = ContextHelper.class.getDeclaredField("context");
+//    f.setAccessible(true);
+//    f.set(null, bc);
+//    f = OSGiObjectFactoryBuilder.class.getDeclaredField("context");
+//    f.setAccessible(true);
+//    f.set(null, bc);
+//
+//
+//    service = new Thread();
+//    
+//    registerService(service);
+//  }
+//  
+//  /**
+//   * Register a service in our map.
+//   * 
+//   * @param service2 The service to register.
+//   */
+//  private void registerService(Thread service2)
+//  {
+//    ServiceFactory factory = Skeleton.newMock(ServiceFactory.class);
+//    Skeleton skel = Skeleton.getSkeleton(factory);
+//    
+//    skel.setReturnValue(new MethodCall(ServiceFactory.class, "getService", Bundle.class, ServiceRegistration.class), service2);
+//    
+//    Hashtable<String, String> props = new Hashtable<String, String>();
+//    props.put("rubbish", "smelly");
+//    
+//    reg = bc.registerService(new String[] {"java.lang.Runnable"}, factory, props);
+//  }
+//  
+//  /**
+//   * Make sure we clear the caches out before the next test.
+//   */
+//  @After
+//  public void teardown()
+//  {
+//    BundleContextMock.clear();
+//    
+//    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+//  }
+//  
+//  /**
+//   * This test checks that we correctly register and deregister the url context
+//   * object factory in the service registry.
+//   */
+//  @Test
+//  public void testJNDIRegistration()
+//  {
+//    ServiceReference ref = bc.getServiceReference(ObjectFactory.class.getName());
+//    
+//    assertNotNull("The aries url context object factory was not registered", ref);
+//    
+//    ObjectFactory factory = (ObjectFactory) bc.getService(ref);
+//    
+//    assertNotNull("The aries url context object factory was null", factory);
+//  }
+//  
+//  /**
+//   * This test does a simple JNDI lookup to prove that works.
+//   * @throws NamingException
+//   */
+//  @Test
+//  public void simpleJNDILookup() throws NamingException
+//  {
+//    System.setProperty(Context.URL_PKG_PREFIXES, "helloMatey");
+//        
+//    InitialContext ctx = new InitialContext(new Hashtable<Object, Object>());
+//    
+//    BundleMock mock = new BundleMock("scooby.doo", new Properties());
+//    
+//    Thread.currentThread().setContextClassLoader(mock.getClassLoader());
+//    
+//    Object s = ctx.lookup("aries:services/java.lang.Runnable");
+//    
+//    assertNotNull("We didn't get a service back from our lookup :(", s);
+//    
+//    assertEquals("The SR did not return the object we expected", service, s);
+//    
+//    Skeleton skel = Skeleton.getSkeleton(mock.getBundleContext());
+//    
+//    skel.assertCalled(new MethodCall(BundleContext.class, "getAllServiceReferences", "java.lang.Runnable", null));
+//
+//    mock = new BundleMock("scooby.doo", new Properties());
+//    
+//    Thread.currentThread().setContextClassLoader(mock.getClassLoader());
+//
+//    s = ctx.lookup("osgi:services/java.lang.Runnable");
+//    
+//    // Check we have the packages set correctly
+//    
+//    String packages = System.getProperty(Context.URL_PKG_PREFIXES, null);
+//    
+//    assertTrue(ctx.getEnvironment().containsValue(packages));
+//
+//    
+//    assertNotNull("We didn't get a service back from our lookup :(", s);
+//    
+//    assertEquals("The SR did not return the object we expected", service, s);
+//
+//    skel = Skeleton.getSkeleton(mock.getBundleContext());
+//    skel.assertCalled(new MethodCall(BundleContext.class, "getAllServiceReferences", "java.lang.Runnable", null));
+//  }
+//
+//  /**
+//   * This test checks that we can pass a filter in without things blowing up.
+//   * Right now our mock service registry does not implement filtering, so the
+//   * effect is the same as simpleJNDILookup, but we at least know it is not
+//   * blowing up.
+//   * 
+//   * @throws NamingException
+//   */
+//  @Test
+//  public void jndiLookupWithFilter() throws NamingException
+//  {
+//    InitialContext ctx = new InitialContext();
+//    
+//    Object s = ctx.lookup("aries:services/java.lang.Runnable/(rubbish=smelly)");
+//    
+//    assertNotNull("We didn't get a service back from our lookup :(", s);
+//    
+//    assertEquals("The SR did not return the object we expected", service, s);
+//    
+//    Skeleton.getSkeleton(bc).assertCalled(new MethodCall(BundleContext.class, "getAllServiceReferences", "java.lang.Runnable", "(rubbish=smelly)"));
+//  }
+//  
+//  /**
+//   * Check that we get a NameNotFoundException if we lookup after the service
+//   * has been unregistered.
+//   * 
+//   * @throws NamingException
+//   */
+//  @Test(expected=NameNotFoundException.class)
+//  public void testLookupWhenServiceHasBeenRemoved() throws NamingException
+//  {
+//    reg.unregister();
+//    InitialContext ctx = new InitialContext();
+//    
+//    ctx.lookup("aries:services/java.lang.Runnable");
+//  }
+//  
+//  /**
+//   * Check that we get a NameNotFoundException if we lookup something not in the
+//   * registry.
+//   * 
+//   * @throws NamingException
+//   */
+//  @Test(expected=NameNotFoundException.class)
+//  public void testLookupForServiceWeNeverHad() throws NamingException
+//  {
+//    InitialContext ctx = new InitialContext();
+//    
+//    ctx.lookup("aries:services/java.lang.Integer");
+//  }
+//  
+//  /**
+//   * This test checks that we can list the contents of the repository using the
+//   * list method
+//   * 
+//   * @throws NamingException
+//   */
+//  @Test
+//  public void listRepositoryContents() throws NamingException
+//  {
+//    InitialContext ctx = new InitialContext();
+//    
+//    NamingEnumeration<NameClassPair> serviceList = ctx.list("aries:services/java.lang.Runnable/(rubbish=smelly)");
+//    
+//    checkThreadRetrievedViaListMethod(serviceList);
+//    
+//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
+//    
+//    //Now add a second service
+//    
+//    registerService(new Thread());
+//    
+//    serviceList = ctx.list("aries:services/java.lang.Runnable/(rubbish=smelly)");
+//    
+//    checkThreadRetrievedViaListMethod(serviceList);
+//    
+//    checkThreadRetrievedViaListMethod(serviceList);
+//    
+//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
+//    
+//  }
+//
+//  /**
+//   * Check that the NamingEnumeration passed in has another element, which represents a java.lang.Thread
+//   * @param serviceList
+//   * @throws NamingException
+//   */
+//  private void checkThreadRetrievedViaListMethod(NamingEnumeration<NameClassPair> serviceList)
+//      throws NamingException
+//  {
+//    assertTrue("The repository was empty", serviceList.hasMoreElements());
+//    
+//    NameClassPair ncp = serviceList.next();
+//    
+//    assertNotNull("We didn't get a service back from our lookup :(", ncp);
+//    
+//    assertNotNull("The object from the SR was null", ncp.getClassName());
+//    
+//    assertEquals("The service retrieved was not of the correct type", "java.lang.Thread", ncp.getClassName());
+//    
+//    assertEquals("aries:services/java.lang.Runnable/(rubbish=smelly)", ncp.getName().toString());
+//  }
+//  
+//  /**
+//   * This test checks that we can list the contents of the repository using the
+//   * list method
+//   * 
+//   * @throws NamingException
+//   */
+//  @Test
+//  public void listRepositoryBindings() throws NamingException
+//  {
+//    InitialContext ctx = new InitialContext();
+//    
+//    NamingEnumeration<Binding> serviceList = ctx.listBindings("aries:services/java.lang.Runnable/(rubbish=smelly)");
+//    
+//    Object returnedService = checkThreadRetrievedViaListBindingsMethod(serviceList);
+//    
+//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
+//    
+//    assertTrue("The returned service was not the service we expected", returnedService == service);
+//    
+//    //Now add a second service
+//    Thread secondService = new Thread();
+//    registerService(secondService);
+//    
+//    serviceList = ctx.listBindings("aries:services/java.lang.Runnable/(rubbish=smelly)");
+//    
+//    Object returnedService1 = checkThreadRetrievedViaListBindingsMethod(serviceList);
+//    
+//    Object returnedService2 = checkThreadRetrievedViaListBindingsMethod(serviceList);
+//    
+//    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
+//    
+//    assertTrue("The services were not the ones we expected!",(returnedService1 == service || returnedService2 == service) && (returnedService1 == secondService || returnedService2 == secondService) && (returnedService1 != returnedService2));
+//    
+//  }
+//
+//  /**
+//   * Check that the NamingEnumeration passed in has another element, which represents a java.lang.Thread
+//   * @param serviceList
+//   * @return the object in the registry
+//   * @throws NamingException
+//   */
+//  private Object checkThreadRetrievedViaListBindingsMethod(NamingEnumeration<Binding> serviceList)
+//      throws NamingException
+//  {
+//    assertTrue("The repository was empty", serviceList.hasMoreElements());
+//    
+//    Binding binding = serviceList.nextElement();
+//    
+//    assertNotNull("We didn't get a service back from our lookup :(", binding);
+//    
+//    assertNotNull("The object from the SR was null", binding.getObject());
+//    
+//    assertTrue("The service retrieved was not of the correct type", binding.getObject() instanceof Thread);
+//    
+//    assertEquals("aries:services/java.lang.Runnable/(rubbish=smelly)", binding.getName().toString());
+//    
+//    return binding.getObject();
+//  }
+//  
 //}
\ No newline at end of file

Propchange: incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryNameParserTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryNameParserTest.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryNameParserTest.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryNameParserTest.java Tue Oct  6 20:41:31 2009
@@ -1,94 +1,94 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.aries.jndi.url;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
-
-import javax.naming.InvalidNameException;
-import javax.naming.Name;
-import javax.naming.NameParser;
-import javax.naming.NamingException;
-
-import org.junit.Test;
-
-/**
- * This is where we test the service registry name parser.
- */
-public class ServiceRegistryNameParserTest
-{
-  /** The parser we are going to use for testing */
-  private NameParser parser = new ServiceRegistryNameParser();
-
-  /**
-   * OK, so we check that we can call checkNames multiple times.
-   * @throws NamingException
-   */
-  @Test
-  public void checkValidNames() throws NamingException
-  {
-    checkName("aries:services/java.lang.Runnable/(a=b)");
-    checkName("aries:services/java.lang.Runnable");
-  }
-  
-  /**
-   * Make sure it fails if we try to parse something that isn't in aries:services
-   * @throws NamingException
-   */
-  @Test(expected=InvalidNameException.class)
-  public void checkOutsideNamespace() throws NamingException
-  {
-    checkName("java:comp/env/jms/cf");
-  }
-  
-  /**
-   * Check that it fails if no interface name is provided.
-   * @throws NamingException
-   */
-  @Test(expected=InvalidNameException.class)
-  public void checkMissingInterface() throws NamingException
-  {
-    checkName("aries:services");
-  }
-  
-  /**
-   * Check that it fails if no interface name is provided in a subtly different
-   * way from the previous method.
-   * @throws NamingException
-   */
-  @Test(expected=InvalidNameException.class)
-  public void checkMissingInterface2() throws NamingException
-  {
-    checkName("aries:services/");
-  }
-
-  /**
-   * This method parses the name and then makes sure what was parsed was parsed
-   * correctly.
-   * 
-   * @param name
-   * @throws NamingException
-   */
-  private void checkName(String name) throws NamingException
-  {
-    Name n = parser.parse(name);
-    assertNotNull("We got a null name back, which is not allowed.", n);
-    assertEquals("The name's toString does not produce the original value", name, n.toString());
-  }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.jndi.url;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
+
+import org.junit.Test;
+
+/**
+ * This is where we test the service registry name parser.
+ */
+public class ServiceRegistryNameParserTest
+{
+  /** The parser we are going to use for testing */
+  private NameParser parser = new ServiceRegistryNameParser();
+
+  /**
+   * OK, so we check that we can call checkNames multiple times.
+   * @throws NamingException
+   */
+  @Test
+  public void checkValidNames() throws NamingException
+  {
+    checkName("aries:services/java.lang.Runnable/(a=b)");
+    checkName("aries:services/java.lang.Runnable");
+  }
+  
+  /**
+   * Make sure it fails if we try to parse something that isn't in aries:services
+   * @throws NamingException
+   */
+  @Test(expected=InvalidNameException.class)
+  public void checkOutsideNamespace() throws NamingException
+  {
+    checkName("java:comp/env/jms/cf");
+  }
+  
+  /**
+   * Check that it fails if no interface name is provided.
+   * @throws NamingException
+   */
+  @Test(expected=InvalidNameException.class)
+  public void checkMissingInterface() throws NamingException
+  {
+    checkName("aries:services");
+  }
+  
+  /**
+   * Check that it fails if no interface name is provided in a subtly different
+   * way from the previous method.
+   * @throws NamingException
+   */
+  @Test(expected=InvalidNameException.class)
+  public void checkMissingInterface2() throws NamingException
+  {
+    checkName("aries:services/");
+  }
+
+  /**
+   * This method parses the name and then makes sure what was parsed was parsed
+   * correctly.
+   * 
+   * @param name
+   * @throws NamingException
+   */
+  private void checkName(String name) throws NamingException
+  {
+    Name n = parser.parse(name);
+    assertNotNull("We got a null name back, which is not allowed.", n);
+    assertEquals("The name's toString does not produce the original value", name, n.toString());
+  }
 }
\ No newline at end of file

Propchange: incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryNameParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native