Examples of Skeleton


Examples of org.apache.aries.unittest.mocks.Skeleton

   
    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));

    ctx = new InitialContext(new Hashtable<Object, Object>());
   
    mock = new BundleMock("scooby.doo.2", 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

Examples of org.apache.aries.unittest.mocks.Skeleton

    persistenceBundleContext = persistenceBundle.getBundleContext();
   
    pp = Skeleton.newMock(PersistenceProvider.class);
   
    providerBundleP100 = Skeleton.newMock(new BundleMock("no.such.Provider", new Hashtable<String, Object>()), Bundle.class);
    Skeleton skel = Skeleton.getSkeleton(providerBundleP100);
    skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("1.0.0"));

    providerBundleP101 = Skeleton.newMock(new BundleMock("no.such.Provider", new Hashtable<String, Object>()), Bundle.class);
    skel = Skeleton.getSkeleton(providerBundleP101);
    skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("1.0.1"));

    providerBundleP110 = Skeleton.newMock(new BundleMock("no.such.Provider", new Hashtable<String, Object>()), Bundle.class);
    skel = Skeleton.getSkeleton(providerBundleP110);
    skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("1.1.0"));

    providerBundleP111 = Skeleton.newMock(new BundleMock("no.such.Provider", new Hashtable<String, Object>()), Bundle.class);
    skel = Skeleton.getSkeleton(providerBundleP111);
    skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("1.1.1"));

    extenderBundle = Skeleton.newMock(new BundleMock("extender", new Hashtable<String, Object>()), Bundle.class);
//    Skeleton.getSkeleton(extenderBundle).setReturnValue(new MethodCall(Bundle.class, "getResource", "schemas/persistence_1_0.xsd"), new File("unittest/resources/persistence_1_0.xsd").toURI().toURL());
   
  }
View Full Code Here

Examples of org.apache.aries.unittest.mocks.Skeleton

  }

  private void setupPersistenceBundle21() throws Exception {
    persistenceBundle.getHeaders().put("Meta-Persistence", "OSGI-INF/found.xml, jarfile.jar!/jar.xml,persistence/another.xml, does-not-exist.xml");
   
    Skeleton skel = Skeleton.getSkeleton(persistenceBundle);
    skel.setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.ACTIVE);

    URL xml = getClass().getClassLoader().getResource("file21/META-INF/persistence.xml");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"), xml);
   
    xml = getClass().getClassLoader().getResource("file21/OSGI-INF/found.xml");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "OSGI-INF/found.xml"), xml);
   
    URL root = getClass().getClassLoader().getResource("file21");
   
    File f = new File(new File(root.toURI()), "jarfile.jar");
   
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(f));
   
    jos.putNextEntry(new ZipEntry("jar.xml"));
   
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(jos));
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    writer.newLine();
    writer.write("<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\"");
    writer.newLine();
    writer.write("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    writer.newLine();   
    writer.write("xsi:schemaLocation=\"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd\"");
    writer.newLine();
    writer.write("version=\"1.0\">");
    writer.newLine();
    writer.write("<persistence-unit name=\"jar\"/>");
    writer.newLine();
    writer.write("</persistence>");
   
    writer.close();
   
    xml = getClass().getClassLoader().getResource("file21/jarfile.jar");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "jarfile.jar"), xml);

    xml = getClass().getClassLoader().getResource("file21/persistence/another.xml");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "persistence/another.xml"), xml);

    xml = getClass().getClassLoader().getResource("file21/OSGI-INF/not-found.xml");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "OSGI-INF/not-found.xml"), xml);
   
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "does-not-exist.xml"), null);
   
    skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("0.0.0"));
   
  }
View Full Code Here

Examples of org.apache.aries.unittest.mocks.Skeleton

  private void setupPersistenceBundle(String root, String header) throws MalformedURLException
  {
    persistenceBundle.getHeaders().put("Meta-Persistence", header);
   
    Skeleton skel = Skeleton.getSkeleton(persistenceBundle);
   
    skel.setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.ACTIVE);
   
    URL rootURL = getClass().getClassLoader().getResource(root);
    URL xml = getClass().getClassLoader().getResource(root + "/META-INF/persistence.xml");
   
    skel.setReturnValue(new MethodCall(Bundle.class, "getResource", "/"), rootURL);
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"), xml);
    skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("0.0.0"));
  }
View Full Code Here

Examples of org.apache.aries.unittest.mocks.Skeleton

  }
 
  @Test
  public void testNoStaleProxiesForRefreshedBundle() throws Exception {
      Bundle bundle = (Bundle) Skeleton.newMock(new Class<?>[] { Bundle.class, ClassLoaderProxy.class });     
      Skeleton skel = Skeleton.getSkeleton(bundle);
     
      TestClassLoader loader = new TestClassLoader();
      skel.setReturnValue(new MethodCall(ClassLoaderProxy.class, "getClassLoader"), loader);
      skel.setReturnValue(new MethodCall(Bundle.class, "getLastModified"), 10l);
     
      Class<?> clazz = loader.loadClass("org.apache.aries.blueprint.proxy.TestInterface");
     
      Object proxy = InterfaceProxyGenerator.getProxyInstance(bundle, null, Arrays.<Class<?>>asList(clazz), constantly(null), null);
      assertTrue(clazz.isInstance(proxy));
     
      /* Now again but with a changed classloader as if the bundle had refreshed */
     
      TestClassLoader loaderToo = new TestClassLoader();
      skel.setReturnValue(new MethodCall(ClassLoaderProxy.class, "getClassLoader"), loaderToo);
      skel.setReturnValue(new MethodCall(Bundle.class, "getLastModified"), 20l);
     
      Class<?> clazzToo = loaderToo.loadClass("org.apache.aries.blueprint.proxy.TestInterface");
     
      Object proxyToo = InterfaceProxyGenerator.getProxyInstance(bundle, null, Arrays.<Class<?>>asList(clazzToo), constantly(null), null);
      assertTrue(clazzToo.isInstance(proxyToo));
View Full Code Here

Examples of org.apache.aries.unittest.mocks.Skeleton

        sut.open();
    }
   
    private CompositeBundle composite(String symbolicName, String version) {
        CompositeBundle cb = Skeleton.newMock(CompositeBundle.class);
        Skeleton cbSkel = Skeleton.getSkeleton(cb);
        cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getSymbolicName"), symbolicName);
        cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getVersion"), new Version(version));
        return cb;
    }
View Full Code Here

Examples of org.apache.aries.unittest.mocks.Skeleton

   * @param service2 The service to register.
   */
  private void registerService(Runnable 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);
View Full Code Here

Examples of org.apache.aries.unittest.mocks.Skeleton

   
    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));

    ctx = new InitialContext(new Hashtable<Object, Object>());
   
    mock = new BundleMock("scooby.doo.2", 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

Examples of org.apache.aries.unittest.mocks.Skeleton

    zos.closeEntry();
  }
 
  private void assertXML(boolean b) {

    Skeleton s = Skeleton.getSkeleton(registry);
    MethodCall mc = new MethodCall(EJBRegistry.class, "addEJBView",
        "XML", "SINGLETON", "local.Iface", false);
   
    if(b)
      s.assertCalledExactNumberOfTimes(mc, 1);
    else
      s.assertNotCalled(mc);
   
    mc = new MethodCall(EJBRegistry.class, "addEJBView",
        "XML", "SINGLETON", "remote.Iface", true);
   
    if(b)
      s.assertCalledExactNumberOfTimes(mc, 1);
    else
      s.assertNotCalled(mc);
  }
View Full Code Here

Examples of org.apache.aries.unittest.mocks.Skeleton

      s.assertNotCalled(mc);
  }

  private void assertAnnotation(boolean b) {

    Skeleton s = Skeleton.getSkeleton(registry);
    MethodCall mc = new MethodCall(EJBRegistry.class, "addEJBView",
        "Annotated", "STATELESS", "test.ejbs.StatelessSessionBean", false);
   
    if(b)
      s.assertCalledExactNumberOfTimes(mc, 1);
    else
      s.assertNotCalled(mc);
   
    mc = new MethodCall(EJBRegistry.class, "addEJBView",
        String.class, "STATEFUL", String.class, boolean.class);
   
    if(b)
      s.assertCalledExactNumberOfTimes(mc, 1);
    else
      s.assertNotCalled(mc);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.