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.Filter;
 
A set of OSGi services 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 ServiceAssert extends OSGiAssert {
    
Utility class. Only static methods are available.
 
     private ServiceAssert() {
     }

    
Asserts that service with class is available in OSGi registry. If it not as expected AssertionError without a message is thrown

Parameters:
clazz service class
 
     public static void assertServiceAvailable(Class clazz) {
         assertServiceAvailable(nullclazz);
     }

    
Asserts that service with class is available in OSGi registry. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
clazz service class
 
     public static void assertServiceAvailable(String messageClass clazz) {
         Assert.assertNotNull("Class is null"clazz);
         //noinspection unchecked
         Object service = ServiceUtils.getService(getBundleContext(), clazz);
         Assert.assertNotNull(messageservice);
     }

    
Asserts that service with class is available in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
 
     public static void assertServiceAvailable(Class clazzlong timeout) {
         assertServiceAvailable(nullclazztimeout);
     }

    
Asserts that service with class is available in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
 
     public static void assertServiceAvailable(String messageClass clazzlong timeout) {
         assertServiceAvailable(messageclazztimeout.);
     }

    
Asserts that service with class is available in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
 
     public static void assertServiceAvailable(Class clazzlong timeoutTimeUnit timeUnit) {
         assertServiceAvailable(nullclazztimeouttimeUnit);
     }

    
Asserts that service with class is available in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
 
    public static void assertServiceAvailable(String messageClass clazzlong timeoutTimeUnit timeUnit) {
        Assert.assertNotNull("Class is null"clazz);
        Assert.assertNotNull("TimeUnit is null"timeUnit);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), clazztimeouttimeUnit);
        Assert.assertNotNull(messageservice);
    }

    
Asserts that service with class name is available in OSGi registry. If it not as expected AssertionError without a message is thrown

Parameters:
className service class name
    public static void assertServiceAvailable(String className) {
        assertServiceAvailable(nullclassName);
    }

    
Asserts that service with class name is available in OSGi registry. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
className service class name
    public static void assertServiceAvailable(String messageString className) {
        Assert.assertNotNull("Class name is null"className);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), className);
        Assert.assertNotNull(messageservice);
    }

    
Asserts that service with class name is available in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceAvailable(String classNamelong timeout) {
        assertServiceAvailable(nullclassNametimeout);
    }

    
Asserts that service with class name is available in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceAvailable(String messageString classNamelong timeout) {
        assertServiceAvailable(messageclassNametimeout.);
    }

    
Asserts that service with class name is available in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceAvailable(String classNamelong timeoutTimeUnit timeUnit) {
        assertServiceAvailable(nullclassNametimeouttimeUnit);
    }

    
Asserts that service with class name is available in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceAvailable(String messageString classNamelong timeoutTimeUnit timeUnit) {
        Assert.assertNotNull("Class name is null"className);
        Assert.assertNotNull("TimeUnit is null"timeUnit);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), classNametimeouttimeUnit);
        Assert.assertNotNull(messageservice);
    }

    
Asserts that service with filter is available in OSGi registry. If it not as expected AssertionError without a message is thrown

Parameters:
filter service filter
    public static void assertServiceAvailable(Filter filter) {
        assertServiceAvailable(nullfilter);
    }

    
Asserts that service with filter is available in OSGi registry. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
filter service filter
    public static void assertServiceAvailable(String message, Filter filter) {
        Assert.assertNotNull("Filter is null"filter);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), filter);
        Assert.assertNotNull(messageservice);
    }

    
Asserts that service with filter is available in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceAvailable(Filter filterlong timeout) {
        assertServiceAvailable(nullfiltertimeout);
    }

    
Asserts that service with filter is available in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceAvailable(String message, Filter filterlong timeout) {
        assertServiceAvailable(messagefiltertimeout.);
    }

    
Asserts that service with filter is available in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceAvailable(Filter filterlong timeoutTimeUnit timeUnit) {
        assertServiceAvailable(nullfiltertimeouttimeUnit);
    }

    
Asserts that service with filter is available in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceAvailable(String message, Filter filterlong timeoutTimeUnit timeUnit) {
        Assert.assertNotNull("Filter is null"filter);
        Assert.assertNotNull("TimeUnit is null"timeUnit);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), filtertimeouttimeUnit);
        Assert.assertNotNull(messageservice);
    }

    
Asserts that service with class is unavailable in OSGi registry. If it not as expected AssertionError without a message is thrown

Parameters:
clazz service class
    public static void assertServiceUnavailable(Class clazz) {
        assertServiceUnavailable(nullclazz);
    }

    
Asserts that service with class is unavailable in OSGi registry. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
clazz service class
    public static void assertServiceUnavailable(String messageClass clazz) {
        Assert.assertNotNull("Class is null"clazz);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), clazz);
        Assert.assertNull(messageservice);
    }

    
Asserts that service with class is unavailable in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceUnavailable(Class clazzlong timeout) {
        assertServiceUnavailable(nullclazztimeout);
    }

    
Asserts that service with class is unavailable in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceUnavailable(String messageClass clazzlong timeout) {
        assertServiceUnavailable(messageclazztimeout.);
    }

    
Asserts that service with class is unavailable in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceUnavailable(Class clazzlong timeoutTimeUnit timeUnit) {
        assertServiceUnavailable(nullclazztimeouttimeUnit);
    }

    
Asserts that service with class is unavailable in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
clazz service class
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceUnavailable(String messageClass clazzlong timeoutTimeUnit timeUnit) {
        Assert.assertNotNull("Class is null"clazz);
        Assert.assertNotNull("TimeUnit is null"timeUnit);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), clazztimeouttimeUnit);
        Assert.assertNull(messageservice);
    }

    
Asserts that service with class name is unavailable in OSGi registry. If it not as expected AssertionError without a message is thrown

Parameters:
className service class name
    public static void assertServiceUnavailable(String className) {
        assertServiceUnavailable(nullclassName);
    }

    
Asserts that service with class name is unavailable in OSGi registry. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
className service class name
    public static void assertServiceUnavailable(String messageString className) {
        Assert.assertNotNull("Class name is null"className);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), className);
        Assert.assertNull(messageservice);
    }

    
Asserts that service with class name is unavailable in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceUnavailable(String classNamelong timeout) {
        assertServiceUnavailable(nullclassNametimeout);
    }

    
Asserts that service with class name is unavailable in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceUnavailable(String messageString classNamelong timeout) {
        assertServiceUnavailable(messageclassNametimeout.);
    }

    
Asserts that service with class name is unavailable in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceUnavailable(String classNamelong timeoutTimeUnit timeUnit) {
        assertServiceUnavailable(nullclassNametimeouttimeUnit);
    }

    
Asserts that service with class name is unavailable in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
className service class name
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceUnavailable(String messageString classNamelong timeoutTimeUnit timeUnit) {
        Assert.assertNotNull("Class name is null"className);
        Assert.assertNotNull("TimeUnit is null"timeUnit);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), classNametimeouttimeUnit);
        Assert.assertNull(messageservice);
    }

    
Asserts that service with filter is unavailable in OSGi registry. If it not as expected AssertionError without a message is thrown

Parameters:
filter service filter
    public static void assertServiceUnavailable(Filter filter) {
        assertServiceUnavailable(nullfilter);
    }

    
Asserts that service with filter is unavailable in OSGi registry. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
filter service filter
    public static void assertServiceUnavailable(String message, Filter filter) {
        Assert.assertNotNull("Filter is null"filter);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), filter);
        Assert.assertNull(messageservice);
    }

    
Asserts that service with filter is unavailable in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceUnavailable(Filter filterlong timeout) {
        assertServiceUnavailable(nullfiltertimeout);
    }

    
Asserts that service with filter is unavailable in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
    public static void assertServiceUnavailable(String message, Filter filterlong timeout) {
        assertServiceUnavailable(messagefiltertimeout.);
    }

    
Asserts that service with filter is unavailable in OSGi registry within given timeout. If it not as expected AssertionError without a message is thrown

Parameters:
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceUnavailable(Filter filterlong timeoutTimeUnit timeUnit) {
        assertServiceUnavailable(nullfiltertimeouttimeUnit);
    }

    
Asserts that service with filter is unavailable in OSGi registry within given timeout. If it not as expected AssertionError is thrown with the given message

Parameters:
message message
filter service filter
timeout time interval in milliseconds to wait. If zero, the method will wait indefinately.
timeUnit timeout time unit
    public static void assertServiceUnavailable(String message, Filter filterlong timeoutTimeUnit timeUnit) {
        Assert.assertNotNull("Filter is null"filter);
        Assert.assertNotNull("TimeUnit is null"timeUnit);
        //noinspection unchecked
        Object service = ServiceUtils.getService(getBundleContext(), filtertimeouttimeUnit);
        Assert.assertNull(messageservice);
    }
New to GrepCode? Check out our FAQ X