Package: OSGiAssert

OSGiAssert

nameinstructionbranchcomplexitylinemethod
OSGiAssert()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
assertBundleListenerCount(StubBundleContext, int)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
assertCleanState(StubBundleContext)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
assertFrameworkListenerCount(StubBundleContext, int)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
assertServiceListenerCount(StubBundleContext, int)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
assertServiceRegistrationCount(StubBundleContext, Class, int)
M: 59 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
assertServiceRegistrationCount(StubBundleContext, int)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.test.stubs.framework;
13:
14: import static org.junit.Assert.assertEquals;
15:
16: import org.osgi.framework.BundleListener;
17: import org.osgi.framework.Constants;
18: import org.osgi.framework.FrameworkListener;
19: import org.osgi.framework.ServiceListener;
20: import org.osgi.framework.ServiceRegistration;
21:
22: /**
23: * A set of assertion methods for testing the state of the Stub OSGi Framework classes. This class makes its assertions
24: * using JUnit4 assertion classes.
25: * <p />
26: *
27: * <strong>Concurrent Semantics</strong><br />
28: *
29: * Threadsafe
30: *
31: */
32: public final class OSGiAssert {
33:
34: /**
35: * Asserts that this {@link StubBundleContext} in is a clean state. A clean consists of the following
36: *
37: * <ul>
38: * <li>0 {@link BundleListener}s</li>
39: * <li>0 {@link FrameworkListener}s</li>
40: * <li>0 {@link ServiceListener}s</li>
41: * <li>0 {@link ServiceRegistration}s</li>
42: * </ul>
43: *
44: * @param bundleContext The context to assert against
45: * @see #assertBundleListenerCount(StubBundleContext, int)
46: * @see #assertFrameworkListenerCount(StubBundleContext, int)
47: * @see #assertServiceListenerCount(StubBundleContext, int)
48: * @see #assertServiceRegistrationCount(StubBundleContext, int)
49: */
50: public static void assertCleanState(StubBundleContext bundleContext) {
51: assertBundleListenerCount(bundleContext, 0);
52: assertFrameworkListenerCount(bundleContext, 0);
53: assertServiceListenerCount(bundleContext, 0);
54: assertServiceRegistrationCount(bundleContext, 0);
55: }
56:
57: /**
58: * Asserts that a number of {@link BundleListener}s are currently registered
59: *
60: * @param bundleContext The context to assert against
61: * @param count The number of listeners to assert
62: */
63: public static void assertBundleListenerCount(StubBundleContext bundleContext, int count) {
64: assertEquals("Invalid number of BundleListeners", count, bundleContext.getBundleListeners().size());
65: }
66:
67: /**
68: * Asserts that a number of {@link FrameworkListener}s are currently registered
69: *
70: * @param bundleContext The context to assert against
71: * @param count The number of listeners to assert
72: */
73: public static void assertFrameworkListenerCount(StubBundleContext bundleContext, int count) {
74: assertEquals("Invalid number of FrameworkListeners", count, bundleContext.getFrameworkListeners().size());
75: }
76:
77: /**
78: * Asserts that a number of {@link ServiceListener}s are currently registered
79: *
80: * @param bundleContext The context to assert against
81: * @param count The number of listeners to assert
82: */
83: public static void assertServiceListenerCount(StubBundleContext bundleContext, int count) {
84: assertEquals("Invalid number of ServiceListeners", count, bundleContext.getServiceListeners().size());
85: }
86:
87: /**
88: * Asserts that a number of {@link ServiceRegistration}s of are currently registered
89: *
90: * @param bundleContext The context to assert against
91: * @param count The number of registered services to assert
92: */
93: public static void assertServiceRegistrationCount(StubBundleContext bundleContext, int count) {
94: assertEquals("Invalid number of ServiceRegistrations", count, bundleContext.getServiceRegistrations().size());
95: }
96:
97: /**
98: * Asserts that a number of {@link ServiceRegistration}s of are currently registered
99: *
100: * @param bundleContext The context to assert against
101: * @param type The {@link Constants#OBJECTCLASS} of the services to assert
102: * @param count The number of registered services to assert
103: */
104: public static void assertServiceRegistrationCount(StubBundleContext bundleContext, Class<?> type, int count) {
105: String typeName = type.getName();
106: int found = 0;
107:• for (ServiceRegistration<?> serviceRegistration : bundleContext.getServiceRegistrations()) {
108: String[] objectClasses = (String[]) serviceRegistration.getReference().getProperty(Constants.OBJECTCLASS);
109:• for (String objectClass : objectClasses) {
110:• if (typeName.equals(objectClass)) {
111: found++;
112: break;
113: }
114: }
115: }
116: assertEquals(String.format("Invalid number of ServiceRegistrations of type %s", typeName), count, found);
117: }
118: }