Class SyntheticBundleInstaller

java.lang.Object
org.openhab.core.test.SyntheticBundleInstaller

public class SyntheticBundleInstaller extends Object
Utility class for creation, installation, update and uninstallation of synthetic bundles for the purpose of testing. The synthetic bundles content should be stored into separate sub-directories of "/test-bundle-pool" (which itself is situated in the test bundle's source directory). The synthetic bundle is packed as a JAR and installed into the test runtime.
Author:
Alex Tugarev - Initial contribution, Dennis Nobel - Generalized the mechanism for creation of bundles by list of extensions to include, Simon Kaufmann - Install method returns when the bundle is fully loaded, Stefan Bussweiler - The list of extensions to include is extended with JSON, Andre Fuechsel - Implemented method for adding fragment, Kai Kreuzer - Applied formatting and license to the file, Dimitar Ivanov - The extension to include can be configured or default ones can be used; update method is introduced
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.osgi.framework.Bundle
    install(org.osgi.framework.BundleContext bundleContext, String testBundleName)
    Install synthetic bundle, denoted by its name, into the test runtime (by using the given bundle context).
    static org.osgi.framework.Bundle
    install(org.osgi.framework.BundleContext bundleContext, String testBundleName, String... extensionsToInclude)
    Install synthetic bundle, denoted by its name, into the test runtime (by using the given bundle context).
    static org.osgi.framework.Bundle
    install(org.osgi.framework.BundleContext bundleContext, String testBundleName, Set<String> extensionsToInclude)
    Install synthetic bundle, denoted by its name, into the test runtime (by using the given bundle context).
    static org.osgi.framework.Bundle
    installFragment(org.osgi.framework.BundleContext bundleContext, String testBundleName)
    Install synthetic bundle fragment, denoted by its name, into the test runtime (by using the given bundle context).
    static org.osgi.framework.Bundle
    installFragment(org.osgi.framework.BundleContext bundleContext, String testBundleName, Set<String> extensionsToInclude)
    Install synthetic bundle fragment, denoted by its name, into the test runtime (by using the given bundle context).
    static void
    uninstall(org.osgi.framework.Bundle bundle)
    Uninstalls the synthetic bundle (or bundle fragment) from the test runtime.
    static void
    uninstall(org.osgi.framework.BundleContext bundleContext, String testBundleName)
    Uninstalls the synthetic bundle (or bundle fragment), denoted by its name, from the test runtime.
    static org.osgi.framework.Bundle
    update(org.osgi.framework.BundleContext bundleContext, String bundleToUpdateName, String updateDirName)
    Updates given bundle into the test runtime (the content is changed, but the symbolic name of the bundles remains the same) with a new content, prepared in another resources directory.
    static org.osgi.framework.Bundle
    update(org.osgi.framework.BundleContext bundleContext, String bundleToUpdateName, String updateDirName, String... extensionsToInclude)
    Updates given bundle into the test runtime (the content is changed, but the symbolic name of the bundles remains the same) with a new content, prepared in another resources directory.
    static org.osgi.framework.Bundle
    update(org.osgi.framework.BundleContext bundleContext, String bundleToUpdateName, String updateDirName, Set<String> extensionsToInclude)
    Updates given bundle into the test runtime (the content is changed, but the symbolic name of the bundles remains the same) with a new content, prepared in another resources directory.
    static void
    waitUntilLoadingFinished(org.osgi.framework.BundleContext context, org.osgi.framework.Bundle bundle)
    Explicitly wait for the given bundle to finish its loading

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SyntheticBundleInstaller

      public SyntheticBundleInstaller()
  • Method Details

    • install

      public static org.osgi.framework.Bundle install(org.osgi.framework.BundleContext bundleContext, String testBundleName) throws Exception
      Install synthetic bundle, denoted by its name, into the test runtime (by using the given bundle context). Only the default extensions set (DEFAULT_EXTENSIONS) will be included into the synthetic bundle
      Parameters:
      bundleContext - the bundle context of the test runtime
      testBundleName - the symbolic name of the sub-directory of "/test-bundle-pool", which contains the files for the synthetic bundle
      Returns:
      the synthetic bundle representation
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle
    • install

      public static org.osgi.framework.Bundle install(org.osgi.framework.BundleContext bundleContext, String testBundleName, Set<String> extensionsToInclude) throws Exception
      Install synthetic bundle, denoted by its name, into the test runtime (by using the given bundle context).
      Parameters:
      bundleContext - the bundle context of the test runtime
      testBundleNamethe - symbolic name of the sub-directory of "/test-bundle-pool", which contains the files for the synthetic bundle
      extensionsToInclude - a list of extension to be included into the synthetic bundle. In order to use the list of default extensions (DEFAULT_EXTENSIONS)
      Returns:
      the synthetic bundle representation
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle
    • install

      public static org.osgi.framework.Bundle install(org.osgi.framework.BundleContext bundleContext, String testBundleName, String... extensionsToInclude) throws Exception
      Install synthetic bundle, denoted by its name, into the test runtime (by using the given bundle context).
      Parameters:
      bundleContext - the bundle context of the test runtime
      testBundleName - the symbolic name of the sub-directory of "/test-bundle-pool", which contains the files for the synthetic bundle
      extensionsToInclude - a list of extension to be included into the synthetic bundle
      Returns:
      the synthetic bundle representation
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle
    • update

      public static org.osgi.framework.Bundle update(org.osgi.framework.BundleContext bundleContext, String bundleToUpdateName, String updateDirName) throws Exception
      Updates given bundle into the test runtime (the content is changed, but the symbolic name of the bundles remains the same) with a new content, prepared in another resources directory.
      Parameters:
      bundleContext - the bundle context of the test runtime
      bundleToUpdateName - the symbolic name of the bundle to be updated
      updateDirName - the location of the new content, that the target bundle will be updated with
      Returns:
      the Bundle representation of the updated bundle
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle
    • update

      public static org.osgi.framework.Bundle update(org.osgi.framework.BundleContext bundleContext, String bundleToUpdateName, String updateDirName, Set<String> extensionsToInclude) throws Exception
      Updates given bundle into the test runtime (the content is changed, but the symbolic name of the bundles remains the same) with a new content, prepared in another resources directory.
      Parameters:
      bundleContext - the bundle context of the test runtime
      bundleToUpdateName - the symbolic name of the bundle to be updated
      updateDirName - the location of the new content, that the target bundle will be updated with
      extensionsToInclude - a list of extension to be included into the synthetic bundle
      Returns:
      the Bundle representation of the updated bundle
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle
    • update

      public static org.osgi.framework.Bundle update(org.osgi.framework.BundleContext bundleContext, String bundleToUpdateName, String updateDirName, String... extensionsToInclude) throws Exception
      Updates given bundle into the test runtime (the content is changed, but the symbolic name of the bundles remains the same) with a new content, prepared in another resources directory.
      Parameters:
      bundleContextthe - bundle context of the test runtime
      bundleToUpdateName - the symbolic name of the bundle to be updated
      updateDirName - the location of the new content, that the target bundle will be updated with
      extensionsToInclude - a list of extension to be included into the synthetic bundle
      Returns:
      the Bundle representation of the updated bundle
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle
    • installFragment

      public static org.osgi.framework.Bundle installFragment(org.osgi.framework.BundleContext bundleContext, String testBundleName) throws Exception
      Install synthetic bundle fragment, denoted by its name, into the test runtime (by using the given bundle context). Only the default extensions set (DEFAULT_EXTENSIONS) will be included into the synthetic bundle fragment.
      Parameters:
      bundleContext - the bundle context of the test runtime
      testBundleName - the name of the sub-directory of "/test-bundle-pool", which contains the files for the synthetic bundle
      extensionsToInclude - a list of extension to be included into the synthetic bundle fragment. In order to use the list of default extensions (DEFAULT_EXTENSIONS)
      Returns:
      the synthetic bundle representation
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle fragment
    • installFragment

      public static org.osgi.framework.Bundle installFragment(org.osgi.framework.BundleContext bundleContext, String testBundleName, Set<String> extensionsToInclude) throws Exception
      Install synthetic bundle fragment, denoted by its name, into the test runtime (by using the given bundle context). Only the default extensions set (DEFAULT_EXTENSIONS) will be included into the synthetic bundle fragment.
      Parameters:
      bundleContext - the bundle context of the test runtime
      testBundleName - the name of the sub-directory of "/test-bundle-pool", which contains the files for the synthetic bundle
      Returns:
      the synthetic bundle representation
      Throws:
      Exception - thrown when error occurs while installing or starting the synthetic bundle fragment
    • waitUntilLoadingFinished

      public static void waitUntilLoadingFinished(org.osgi.framework.BundleContext context, org.osgi.framework.Bundle bundle)
      Explicitly wait for the given bundle to finish its loading
      Parameters:
      bundle - the bundle object representation
    • uninstall

      public static void uninstall(org.osgi.framework.Bundle bundle) throws org.osgi.framework.BundleException
      Uninstalls the synthetic bundle (or bundle fragment) from the test runtime.
      Parameters:
      bundle - the bundle to uninstall
      Throws:
      org.osgi.framework.BundleException - if error is met during the bundle uninstall
    • uninstall

      public static void uninstall(org.osgi.framework.BundleContext bundleContext, String testBundleName) throws org.osgi.framework.BundleException
      Uninstalls the synthetic bundle (or bundle fragment), denoted by its name, from the test runtime.

      This method should only be used if the bundle itself provides a symbolic name. If possible you should use uninstall(Bundle) and give the bundle that has been provided by one of the install methods.

      Parameters:
      bundleContext - the bundle context of the test runtime
      testBundleName - the name of the test bundle to be uninstalled
      Throws:
      org.osgi.framework.BundleException - if error is met during the bundle uninstall