BUG-7473: add Karaf 4 features
[odlparent.git] / bundles4-test / src / test / java / org / opendaylight / odlparent / bundles4test / ServiceReferenceUtilTest.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.odlparent.bundles4test;
9
10 import static com.google.common.truth.Truth.assertThat;
11
12 import java.util.Arrays;
13 import org.junit.Test;
14 import org.osgi.framework.Bundle;
15 import org.osgi.framework.ServiceReference;
16
17 /**
18  * Unit test for ServiceReferenceUtil.
19  *
20  * @author Michael Vorburger.ch
21  */
22 public class ServiceReferenceUtilTest {
23
24     @Test
25     public void testGetUsingBundleSymbolicNames() {
26         assertThat(new ServiceReferenceUtil().getUsingBundleSymbolicNames(getServiceReference())).isEmpty();
27     }
28
29     @Test
30     public void testGetProperties() {
31         assertThat(new ServiceReferenceUtil().getProperties(getServiceReference())).containsExactly(
32                 "property1", "value1",
33                 "property2", Arrays.asList(new String[] { "value2.1", "value2.2" }));
34     }
35
36     private ServiceReference<?> getServiceReference() {
37         return new ServiceReference<Object>() {
38
39             @Override
40             public Object getProperty(String key) {
41                 if ("property1".equals(key)) {
42                     return "value1";
43                 } else if ("property2".equals(key)) {
44                     return new String[] { "value2.1", "value2.2" };
45                 } else {
46                     return null;
47                 }
48             }
49
50             @Override
51             public String[] getPropertyKeys() {
52                 return new String[] { "property1", "property2"};
53             }
54
55             @Override
56             public Bundle getBundle() {
57                 return null;
58             }
59
60             @Override
61             public Bundle[] getUsingBundles() {
62                 return null;
63             }
64
65             @Override
66             public boolean isAssignableTo(Bundle bundle, String className) {
67                 return false;
68             }
69
70             @Override
71             public int compareTo(Object reference) {
72                 return 0;
73             }
74         };
75     }
76
77 }