Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2010 Dmytro Pishchukhin (http://osgilab.org)
   * This program is made available under the terms of the MIT License.
   */
  
  package org.osgilab.testing.commons.assertions;
  
  import  org.osgi.framework.Bundle;
 import  org.osgi.framework.Version;
 import  org.osgi.service.packageadmin.PackageAdmin;
A set of OSGi Bundle specific assertion methods useful for writing tests.

Before use it should be initialized org.osgilab.testing.commons.assertions.OSGiAssert.init(org.osgi.framework.BundleContext)

Author(s):
dmytro.pishchukhin
Version:
1.0
See also:
java.lang.AssertionError
org.osgilab.testing.commons.assertions.OSGiAssert
 
 public class BundleAssert extends OSGiAssert {
    
Utility class. Only static methods are available.
 
     private BundleAssert() {
     }

    
Asserts that Bundle with bundleId has given state value. If it not as expected AssertionError without a message is thrown

Parameters:
state bundle state value
bundleId bundle id
 
     public static void assertBundleState(int statelong bundleId) {
         assertBundleState(nullstatebundleId);
     }

    
Asserts that Bundle with bundleId has given state value. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
state bundle state value
bundleId bundle id
 
     public static void assertBundleState(String messageint statelong bundleId) {
         Bundle bundle = BundleUtils.findBundle(getBundleContext(), bundleId);
         Assert.assertNotNull(String.format("Unknown bundle with ID: %d"bundleId), bundle);
         Assert.assertEquals(messagestatebundle.getState());
     }

    
Asserts that Bundle with symbolic name has given state value. If it not as expected AssertionError without a message is thrown

Parameters:
state bundle state value
symbolicName symbolic name
 
     public static void assertBundleState(int stateString symbolicName) {
         assertBundleState(nullstatesymbolicName);
     }

    
Asserts that Bundle with symbolic name has given state value. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
state bundle state value
symbolicName symbolic name
 
     public static void assertBundleState(String messageint stateString symbolicName) {
         Assert.assertNotNull("SymbolicName is null"symbolicName);
         Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicName);
         Assert.assertNotNull(String.format("Unknown bundle with SymbolicName: %s"symbolicName), bundle);
         Assert.assertEquals(messagestatebundle.getState());
     }

    
Asserts that Bundle with symbolic name and version has given state value. If it not as expected AssertionError without a message is thrown

Parameters:
state bundle state value
symbolicName symbolic name
version version
 
     public static void assertBundleState(int stateString symbolicName, Version version) {
         assertBundleState(nullstatesymbolicNameversion);
     }

    
Asserts that Bundle with symbolic name and version has given state value. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
state bundle state value
symbolicName symbolic name
version version
    public static void assertBundleState(String messageint stateString symbolicName, Version version) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicNameversion);
        Assert.assertNotNull(String.format("Unknown bundle with SymbolicName: %s and version: %s"symbolicNameversion), bundle);
        Assert.assertEquals(messagestatebundle.getState());
    }

    
Asserts that Bundle with bundleId is available in OSGi framework. If it not as expected AssertionError without a message is thrown

Parameters:
bundleId bundle id
    public static void assertBundleAvailable(long bundleId) {
        assertBundleAvailable(nullbundleId);
    }

    
Asserts that Bundle with bundleId is available in OSGi framework. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
bundleId bundle id
    public static void assertBundleAvailable(String messagelong bundleId) {
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), bundleId);
        Assert.assertNotNull(messagebundle);
    }

    
Asserts that Bundle with symbolic name is available in OSGi framework. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
    public static void assertBundleAvailable(String symbolicName) {
        assertBundleAvailable(nullsymbolicName);
    }

    
Asserts that Bundle with symbolic name is available in OSGi framework. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
    public static void assertBundleAvailable(String messageString symbolicName) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicName);
        Assert.assertNotNull(messagebundle);
    }

    
Asserts that Bundle with symbolic name and version is available in OSGi framework. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
version version
    public static void assertBundleAvailable(String symbolicName, Version version) {
        assertBundleAvailable(nullsymbolicNameversion);
    }

    
Asserts that Bundle with symbolic name and version is available in OSGi framework. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
version version
    public static void assertBundleAvailable(String messageString symbolicName, Version version) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicNameversion);
        Assert.assertNotNull(messagebundle);
    }

    
Asserts that Bundle with bundleId is unavailable in OSGi framework. If it not as expected AssertionError without a message is thrown

Parameters:
bundleId bundle id
    public static void assertBundleUnavailable(long bundleId) {
        assertBundleUnavailable(nullbundleId);
    }

    
Asserts that Bundle with bundleId is unavailable in OSGi framework. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
bundleId bundle id
    public static void assertBundleUnavailable(String messagelong bundleId) {
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), bundleId);
        Assert.assertNull(messagebundle);
    }

    
Asserts that Bundle with symbolic name is unavailable in OSGi framework. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
    public static void assertBundleUnavailable(String symbolicName) {
        assertBundleUnavailable(nullsymbolicName);
    }

    
Asserts that Bundle with symbolic name is unavailable in OSGi framework. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
    public static void assertBundleUnavailable(String messageString symbolicName) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicName);
        Assert.assertNull(messagebundle);
    }

    
Asserts that Bundle with symbolic name and version is unavailable in OSGi framework. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
version version
    public static void assertBundleUnavailable(String symbolicName, Version version) {
        assertBundleUnavailable(nullsymbolicNameversion);
    }

    
Asserts that Bundle with symbolic name and version is unavailable in OSGi framework. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
version version
    public static void assertBundleUnavailable(String messageString symbolicName, Version version) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicNameversion);
        Assert.assertNull(messagebundle);
    }

    
Asserts that Bundle with bundleId is fragment bundle. If it not as expected AssertionError without a message is thrown

Parameters:
bundleId bundle id
    public static void assertFragment(long bundleId) {
        assertFragment(nullbundleId);
    }

    
Asserts that Bundle with bundleId is fragment bundle. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
bundleId bundle id
    public static void assertFragment(String messagelong bundleId) {
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), bundleId);
        Assert.assertNotNull(String.format("Unknown bundle with ID: %d"bundleId), bundle);
        PackageAdmin packageAdmin = ServiceUtils.getService(getBundleContext(), PackageAdmin.class);
        Assert.assertNotNull("PackageAdmin is unavailable"packageAdmin);
        int type = packageAdmin.getBundleType(bundle);
        Assert.assertTrue(message, (type & PackageAdmin.BUNDLE_TYPE_FRAGMENT) != 0);
    }

    
Asserts that Bundle with symbolic name is fragment bundle. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
    public static void assertFragment(String symbolicName) {
        assertFragment(nullsymbolicName);
    }

    
Asserts that Bundle with symbolic name is fragment bundle. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
    public static void assertFragment(String messageString symbolicName) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicName);
        Assert.assertNotNull(String.format("Unknown bundle with SymbolicName: %s"symbolicName), bundle);
        PackageAdmin packageAdmin = ServiceUtils.getService(getBundleContext(), PackageAdmin.class);
        Assert.assertNotNull("PackageAdmin is unavailable"packageAdmin);
        int type = packageAdmin.getBundleType(bundle);
        Assert.assertTrue(message, (type & PackageAdmin.BUNDLE_TYPE_FRAGMENT) != 0);
    }

    
Asserts that Bundle with symbolic name and version is fragment bundle. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
version version
    public static void assertFragment(String symbolicName, Version version) {
        assertFragment(nullsymbolicNameversion);
    }

    
Asserts that Bundle with symbolic name and version is fragment bundle. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
version version
    public static void assertFragment(String messageString symbolicName, Version version) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicNameversion);
        Assert.assertNotNull(String.format("Unknown bundle with SymbolicName: %s and version: %s"symbolicNameversion), bundle);
        PackageAdmin packageAdmin = ServiceUtils.getService(getBundleContext(), PackageAdmin.class);
        Assert.assertNotNull("PackageAdmin is unavailable"packageAdmin);
        int type = packageAdmin.getBundleType(bundle);
        Assert.assertTrue(message, (type & PackageAdmin.BUNDLE_TYPE_FRAGMENT) != 0);
    }

    
Asserts that Bundle with bundleId is not a fragment bundle. If it not as expected AssertionError without a message is thrown

Parameters:
bundleId bundle id
    public static void assertNotFragment(long bundleId) {
        assertNotFragment(nullbundleId);
    }

    
Asserts that Bundle with bundleId is not a fragment bundle. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
bundleId bundle id
    public static void assertNotFragment(String messagelong bundleId) {
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), bundleId);
        Assert.assertNotNull(String.format("Unknown bundle with ID: %d"bundleId), bundle);
        PackageAdmin packageAdmin = ServiceUtils.getService(getBundleContext(), PackageAdmin.class);
        Assert.assertNotNull("PackageAdmin is unavailable"packageAdmin);
        int type = packageAdmin.getBundleType(bundle);
        Assert.assertTrue(message, (type & PackageAdmin.BUNDLE_TYPE_FRAGMENT) != 0);
    }

    
Asserts that Bundle with symbolic name is not a fragment bundle. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
    public static void assertNotFragment(String symbolicName) {
        assertNotFragment(nullsymbolicName);
    }

    
Asserts that Bundle with symbolic name is not a fragment bundle. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
    public static void assertNotFragment(String messageString symbolicName) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicName);
        Assert.assertNotNull(String.format("Unknown bundle with SymbolicName: %s"symbolicName), bundle);
        PackageAdmin packageAdmin = ServiceUtils.getService(getBundleContext(), PackageAdmin.class);
        Assert.assertNotNull("PackageAdmin is unavailable"packageAdmin);
        int type = packageAdmin.getBundleType(bundle);
        Assert.assertTrue(message, (type & PackageAdmin.BUNDLE_TYPE_FRAGMENT) != 0);
    }

    
Asserts that Bundle with symbolic name and version is not a fragment bundle. If it not as expected AssertionError without a message is thrown

Parameters:
symbolicName symbolic name
version version
    public static void assertNotFragment(String symbolicName, Version version) {
        assertNotFragment(nullsymbolicNameversion);
    }

    
Asserts that Bundle with symbolic name and version is not a fragment bundle. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
symbolicName symbolic name
version version
    public static void assertNotFragment(String messageString symbolicName, Version version) {
        Assert.assertNotNull("SymbolicName is null"symbolicName);
        Bundle bundle = BundleUtils.findBundle(getBundleContext(), symbolicNameversion);
        Assert.assertNotNull(String.format("Unknown bundle with SymbolicName: %s and version: %s"symbolicNameversion), bundle);
        PackageAdmin packageAdmin = ServiceUtils.getService(getBundleContext(), PackageAdmin.class);
        Assert.assertNotNull("PackageAdmin is unavailable"packageAdmin);
        int type = packageAdmin.getBundleType(bundle);
        Assert.assertTrue(message, (type & PackageAdmin.BUNDLE_TYPE_FRAGMENT) != 0);
    }
New to GrepCode? Check out our FAQ X