Examples of Skeleton


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

   
    Bundle persistenceBundle2 = Skeleton.newMock(new BundleMock("scrappy.doo", new Hashtable<String, Object>()), Bundle.class);

    persistenceBundle2.getHeaders().put("Meta-Persistence", "");
   
    Skeleton skel = Skeleton.getSkeleton(persistenceBundle2);
   
    skel.setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.ACTIVE);
   
    URL rootURL = getClass().getClassLoader().getResource("file12");
    URL xml = getClass().getClassLoader().getResource("file12" + "/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"));
   

    mgr.start(ctx);
   
    mgr.addingBundle(persistenceBundle2, new BundleEvent(BundleEvent.STARTING, persistenceBundle2));
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

   
    persistenceBundle.getHeaders().put("Web-ContextPath", "/test2");
    persistenceBundle.getHeaders().put("Bundle-ClassPath", "WEB-INF/classes/onClasspath, WEB-INF/lib/onClasspath.jar;" +
        " WEB-INF/lib/alsoOnClasspath.jar; prop=\"value\"; complexProp:=\"a,b\";complexProp2:= \"c;d\";anotherProp=anotherValue; yetMoreProp=something");
   
    Skeleton skel = Skeleton.getSkeleton(persistenceBundle);
    skel.setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.ACTIVE);

    URL xml = getClass().getClassLoader().getResource("file23/META-INF/persistence.xml");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"), xml);
   
    xml = getClass().getClassLoader().getResource("file23/WEB-INF/classes/onClasspath/META-INF/persistence.xml");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "WEB-INF/classes/onClasspath/META-INF/persistence.xml"), xml);
   
    xml = getClass().getClassLoader().getResource("file23/WEB-INF/classes/notOnClasspath/META-INF/persistence.xml");
    skel.setReturnValue(new MethodCall(Bundle.class, "getEntry", "WEB-INF/classes/notOnClasspath/META-INF/persistence.xml"), xml);
   
    URL root = getClass().getClassLoader().getResource("file23");
   
    buildJarFile(skel, root, "WEB-INF/lib/onClasspath.jar", "jarOne");
    buildJarFile(skel, root, "WEB-INF/lib/alsoOnClasspath.jar", "jarTwo");
   
    buildJarFile(skel, root, "WEB-INF/lib/notOnClasspath.jar", "jarNotOnClassPath");
   
    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, 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, Arrays.<Class<?>>asList(clazzToo), constantly(null), null);
      assertTrue(clazzToo.isInstance(proxyToo));
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

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

    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
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.