Package de.mhus.framework.mod

Examples of de.mhus.framework.mod.ModManager


    // Enable Trace
    DynamicClassLoader.log.setTrace(true);
   
    // Create Base and Manager
    ClassLoadingBase base = new ClassLoadingBase();
    ModManager manager = new ModManager(base);
   
    // Create Config
    HashConfig c = new HashConfig();
    c.setString("class", ClassLoaderActivator.class.getCanonicalName());
    c.setString("id", "test1");
    c.setString("name", "Loading1");
    IConfig cpath = c.createConfig("classpath");
    IConfig loader = cpath.createConfig("resource");
    loader.setString("jar", "etc/test/test.jar");
   
    // Create Bundle and ModConfig
    IBundle b1 = new ModBundle(new IModConfig[] {new ModConfig(c)}, "test1", false);
   
    // Init Bundle
      List<IModActivator> activators = new LinkedList<IModActivator>();
      manager.initializeBundle(b1,activators);
      manager.enableActivators(activators);
     
      assertEquals("alf aloa", c.getString("result", "") );
     
      // disable and dispose
      manager.disableActivators(activators);
      manager.disposeActivators(activators);

      // stop tracing
    DynamicClassLoader.log.setTrace(false);

  }
View Full Code Here


     * Test the normal Lifecycle functionality
     */
    public void testLifecycle() throws Exception
    {
     
      ModManager manager = new ModManager(base);

      MyConfig a1 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c name='Test1'/>").getDocumentElement() ) );
      IModConfig[] ac1 = new IModConfig[] { a1 };
      MyBundle b1 = new MyBundle("mybundle", true, ac1 );
     
      List<IModActivator> activators = new LinkedList<IModActivator>();
      manager.initializeBundle(b1,activators);
      IModActivator act = activators.get(0);
      assertTrue( act.getStatus() == IModActivator.STATUS.INITIALIZED );
      manager.enableActivators(activators);
      assertTrue( act.getStatus() == IModActivator.STATUS.ENABLED );
      manager.disableActivators(activators);
      assertTrue( act.getStatus() == IModActivator.STATUS.DISABLED );
      manager.disposeActivators(activators);
      assertTrue( act.getStatus() == IModActivator.STATUS.CLOSED );
     
    }
View Full Code Here

     * Test the fail on init Lifecycle functionality
     */
    public void testLifecycleFailInit() throws Exception
    {
     
      ModManager manager = new ModManager(base);

      MyConfig a1 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c fail_initialize='1'/>").getDocumentElement() ) );
      IModConfig[] ac1 = new IModConfig[] { a1 };
      MyBundle b1 = new MyBundle("mybundle", true, ac1 );
     
      List<IModActivator> activators = new LinkedList<IModActivator>();
      try {
        manager.initializeBundle(b1,activators);
      } catch (Exception e) {}
      System.out.println("-----------------------------------------------");
      System.out.println(activators.size());
      assertEquals(0, activators.size() );

View Full Code Here

     * On fail the hole bundle is not installed
     */
    public void testConsistentOn() throws Exception
    {
     
      ModManager manager = new ModManager(base);

      MyConfig a1 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c id='test1' />").getDocumentElement() ) );
      MyConfig a2 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c id='test2' fail_initialize='1'/>").getDocumentElement() ) );
      IModConfig[] ac1 = new IModConfig[] { a1, a2 };
      MyBundle b1 = new MyBundle("mybundle", true, ac1 );
     
      List<IModActivator> activators = new LinkedList<IModActivator>();
    try {
        manager.initializeBundle(b1,activators);
      } catch (Exception e) {}
      assertTrue( activators.size() == 0 );
      assertTrue( manager.getActivators().size() == 0 );

    }
View Full Code Here

     * On fail the other activators are installed
     */
    public void testConsistentOff() throws Exception
    {
     
      ModManager manager = new ModManager(base);

      MyConfig a1 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c/>").getDocumentElement() ) );
      MyConfig a2 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c fail_initialize='1'/>").getDocumentElement() ) );
      IModConfig[] ac1 = new IModConfig[] { a1, a2 };
      MyBundle b1 = new MyBundle("mybundle", false, ac1 );
           
      List<IModActivator> activators = new LinkedList<IModActivator>();
      manager.initializeBundle(b1,activators);
      assertTrue( activators.size() == 1 );
      assertTrue( manager.getActivators().size() == 1 );

    }
View Full Code Here

     * @throws Exception
     */
    public void testBundles2() throws Exception
    {
     
      ModManager manager = new ModManager(base);

      MyConfig a1 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c/>").getDocumentElement() ) );
      MyConfig a2 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c/>").getDocumentElement() ) );
      IModConfig[] ac1 = new IModConfig[] { a1, a2 };
      MyBundle b1 = new MyBundle("mybundle", false, ac1 );
     
      List<IModActivator> activators1 = new LinkedList<IModActivator>();
      manager.initializeBundle(b1,activators1);
      assertTrue( activators1.size() == 2 );
      assertTrue( manager.getActivators().size() == 2 );
     
      IModActivator act1 = activators1.get(0);
      assertTrue( act1.getStatus() == IModActivator.STATUS.INITIALIZED );
      manager.enableActivators(activators1);
      assertTrue( act1.getStatus() == IModActivator.STATUS.ENABLED );
      manager.disableActivators(activators1);
     
      MyConfig a3 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c/>").getDocumentElement() ) );
      MyConfig a4 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c/>").getDocumentElement() ) );
      IModConfig[] ac2 = new IModConfig[] { a3, a4 };
      MyBundle b2 = new MyBundle("mybundle", false, ac2 );
           
      List<IModActivator> activators2 = new LinkedList<IModActivator>();
      manager.initializeBundle(b2,activators2);
      assertTrue( activators2.size() == 2 );     
      assertTrue( manager.getActivators().size() == 4 );
     
      IModActivator act2 = activators2.get(0);
      assertTrue( act2.getStatus() == IModActivator.STATUS.INITIALIZED );
      manager.enableActivators(activators2);
      assertTrue( act2.getStatus() == IModActivator.STATUS.ENABLED );
      manager.disableActivators(activators2);
     
      assertTrue( act1.getStatus() == IModActivator.STATUS.DISABLED );
      manager.disposeActivators(activators1);
      assertTrue( act1.getStatus() == IModActivator.STATUS.CLOSED );

      assertTrue( act2.getStatus() == IModActivator.STATUS.DISABLED );
      manager.disposeActivators(activators2);
      assertTrue( act2.getStatus() == IModActivator.STATUS.CLOSED );
     
      assertTrue( manager.getActivators().size() == 0 );
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testServiceRegister() throws Exception {
     
      ModManager manager = new ModManager(base);

      MyConfig a1 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c register_service='1'/>").getDocumentElement() ) );
      MyConfig a2 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c lookup_service='1'/>").getDocumentElement() ) );
      IModConfig[] ac1 = new IModConfig[] { a1, a2 };
      MyBundle b1 = new MyBundle("mybundle", false, ac1 );
     
      List<IModActivator> activators = new LinkedList<IModActivator>();
      manager.initializeBundle(b1,activators);
     
      Map<Class<?>, List<IService>> services = manager.getServices();
      assertTrue( services.get( ISimpleService.class ).size() == 1 );
     
      manager.enableActivators(activators); // lookup single service
      assertTrue( activators.get(1).getStatus() == STATUS.ENABLED );
     
      manager.disableActivators(activators);
      manager.disposeActivators(activators);
     
      services = manager.getServices();
      assertTrue( services.get( ISimpleService.class ).size() == 0 );
     
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testServiceLookupException() throws Exception {
     
      ModManager manager = new ModManager(base);

      MyConfig a1 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c id='test1'/>").getDocumentElement() ) );
      MyConfig a2 = new MyConfig( SimpleActivator.class.getCanonicalName(), new XmlConfig( null, MXml.loadXml("<c id='test2' lookup_service='1'/>").getDocumentElement() ) );
      IModConfig[] ac1 = new IModConfig[] { a1, a2 };
      MyBundle b1 = new MyBundle("mybundle", false, ac1 );
     
      List<IModActivator> activators = new LinkedList<IModActivator>();
      manager.initializeBundle(b1,activators);
     
      Map<Class<?>, List<IService>> services = manager.getServices();
      assertTrue( services.get( ISimpleService.class ) == null );
     
     
    manager.enableActivators(activators); // lookup single service
      assertTrue( activators.get(1).getStatus() == STATUS.INITIALIZED );
   
      manager.disableActivators(activators);
      manager.disposeActivators(activators);
     
    }
View Full Code Here

 
  public void testBundle() throws Exception {
    Base base = new Base();
   
    ModManager bundleManager = new ModManager(base);
    ModManager modManager = new ModManager(base);
   
    // Create Config
    HashConfig c1 = new HashConfig();
    c1.setString("class", SimpleActivator.class.getCanonicalName());
    c1.setString("id", "test1");
    c1.setString("name", "Simple1");

    HashConfig c2 = new HashConfig();
    c2.setString("class", SimpleActivator.class.getCanonicalName());
    c2.setString("id", "test2");
    c2.setString("name", "Simple2");
   
    HashConfig c3 = new HashConfig();
    c3.setString("class", SimpleActivator.class.getCanonicalName());
    c3.setString("id", "test3");
    c3.setString("name", "Simple3");
   
    ModBundle bundle1 = new ModBundle(new IModConfig[] { new ModConfig(c1), new ModConfig(c2)}, "bundle1", true);
   
    ModBundle bundle2 = new ModBundle(new IModConfig[] { new ModConfig(c3) }, "bundle2", true);
   
    modManager.append(bundle1);
    modManager.append(bundle2);

    bundleManager.initializeModule(bundle1,null);
    bundleManager.initializeModule(bundle2,null);
    bundleManager.intialize();
    bundleManager.enable();
View Full Code Here

TOP

Related Classes of de.mhus.framework.mod.ModManager

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.