Package org.apache.aries.mocks

Examples of org.apache.aries.mocks.BundleMock$BundleClassLoader


  }
 
  @Test
  public void checkServiceOrderObserved() throws NamingException
  {
    BundleMock mock = new BundleMock("scooby.doo", new Properties());
   
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());

    InitialContext ctx = new InitialContext();
   
    String className = Runnable.class.getName();
   
View Full Code Here


  }
 
 
  @BeforeClass
  public static void setup() {
    bundle = Skeleton.newMock(new BundleMock("aBundle", new Hashtable<String, String>()), Bundle.class);
    BundleContext bc = bundle.getBundleContext();
    new org.apache.aries.jndi.startup.Activator().start(bc);
    Activator a = new Activator();
    a.start(bc);
    a.serviceFound();
View Full Code Here

    BundleContextMock.clear();
  }
 
  @Before
  public void setupClassLoader() {
    BundleMock mock = new BundleMock("bundle.for.new.initial.context", new Properties());
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());
  }
View Full Code Here

  }
 
  Bundle bundleMock (String bundleSymbolicNameHeader) {
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(Constants.BUNDLE_SYMBOLICNAME, bundleSymbolicNameHeader);
    Bundle result = Skeleton.newMock(new BundleMock("aBundle", props), Bundle.class);
    return result;
  }
View Full Code Here

  }
 
  @Test
  public void testBaseLookup() throws NamingException
  {
     BundleMock mock = new BundleMock("scooby.doo", new Properties());
       
     Thread.currentThread().setContextClassLoader(mock.getClassLoader());

     InitialContext ctx = new InitialContext();
    
     Context ctx2 = (Context) ctx.lookup("osgi:service");
    
View Full Code Here

  @Test
  public void jndiLookupServiceNameTest() throws NamingException, SQLException
  {
    InitialContext ctx = new InitialContext(new Hashtable<Object, Object>());
   
    BundleMock mock = new BundleMock("scooby.doo", new Properties());
   
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());
   
    DataSource first = Skeleton.newMock(DataSource.class);
    DataSource second = Skeleton.newMock(DataSource.class);
   
    Hashtable<String, String> properties = new Hashtable<String, String>();
View Full Code Here

  {
    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());
   
    Runnable s = (Runnable) ctx.lookup("aries:services/java.lang.Runnable");
   
    assertNotNull("We didn't get a service back from our lookup :(", s);
   
    s.run();
   
    Skeleton.getSkeleton(service).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
   
    Skeleton skel = Skeleton.getSkeleton(mock.getBundleContext());
   
    skel.assertCalled(new MethodCall(BundleContext.class, "getServiceReferences", "java.lang.Runnable", null));

    mock = new BundleMock("scooby.doo", new Properties());
   
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());

    s = (Runnable) ctx.lookup("osgi:service/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);

    s.run();
   
    Skeleton.getSkeleton(service).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 2);

    skel = Skeleton.getSkeleton(mock.getBundleContext());
    skel.assertCalled(new MethodCall(BundleContext.class, "getServiceReferences", "java.lang.Runnable", null));
  }
View Full Code Here

   * @throws NamingException
   */
  @Test
  public void jndiLookupWithFilter() throws NamingException
  {
    BundleMock mock = new BundleMock("scooby.doo", new Properties());
   
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());

    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);
   
    service.run();
   
    Skeleton.getSkeleton(service).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);

    Skeleton.getSkeleton(mock.getBundleContext()).assertCalled(new MethodCall(BundleContext.class, "getServiceReferences", "java.lang.Runnable", "(rubbish=smelly)"));
  }
View Full Code Here

  @Test(expected=NameNotFoundException.class)
  public void testLookupWhenServiceHasBeenRemoved() throws NamingException
  {
    reg.unregister();

    BundleMock mock = new BundleMock("scooby.doo", new Properties());
   
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());

    InitialContext ctx = new InitialContext();
   
    ctx.lookup("aries:services/java.lang.Runnable");
  }
View Full Code Here

   * @throws NamingException
   */
  @Test(expected=NameNotFoundException.class)
  public void testLookupForServiceWeNeverHad() throws NamingException
  {
    BundleMock mock = new BundleMock("scooby.doo", new Properties());
   
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());

    InitialContext ctx = new InitialContext();
   
    ctx.lookup("aries:services/java.lang.Integer");
  }
View Full Code Here

TOP

Related Classes of org.apache.aries.mocks.BundleMock$BundleClassLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.