Pin requests to <2.16
[odlparent.git] / bundles-test / src / test / java / org / opendaylight / odlparent / bundlestest / 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.bundlestest;
9
10 import static com.google.common.truth.Truth.assertThat;
11
12 import com.google.common.collect.Lists;
13 import com.google.common.collect.Maps;
14 import java.util.Arrays;
15 import java.util.Map;
16 import org.junit.Test;
17 import org.osgi.framework.Bundle;
18 import org.osgi.framework.ServiceReference;
19
20 /**
21  * Unit test for ServiceReferenceUtil.
22  *
23  * @author Michael Vorburger.ch
24  */
25 public class ServiceReferenceUtilTest {
26
27     @Test
28     public void testGetUsingBundleSymbolicNames() {
29         assertThat(new ServiceReferenceUtil().getUsingBundleSymbolicNames(getServiceReference())).isEmpty();
30     }
31
32     @Test
33     public void testGetProperties() {
34         assertThat(new ServiceReferenceUtil().getProperties(getServiceReference())).containsExactly(
35                 "property1", "value1",
36                 "property2", Arrays.asList(new String[] { "value2.1", "value2.2" }),
37                 "property3", null);
38     }
39
40     private static ServiceReference<?> getServiceReference() {
41         return new TestServiceReference();
42     }
43
44     private static final class TestServiceReference implements ServiceReference<Object> {
45
46         private Map<String, Object> properties = Maps.newHashMap();
47
48         TestServiceReference() {
49             properties.put("property1", "value1");
50             properties.put("property2", Lists.newArrayList("value2.1", "value2.2"));
51             properties.put("property3", null);
52         }
53
54         @Override
55         public Object getProperty(String key) {
56             return properties.get(key);
57         }
58
59         @Override
60         public String[] getPropertyKeys() {
61             return properties.keySet().stream().toArray(String[]::new);
62         }
63
64         @Override
65         public Bundle getBundle() {
66             return null;
67         }
68
69         @Override
70         public Bundle[] getUsingBundles() {
71             return null;
72         }
73
74         @Override
75         public boolean isAssignableTo(Bundle bundle, String className) {
76             return false;
77         }
78
79         @Override
80         public int compareTo(Object reference) {
81             return 0;
82         }
83     }
84
85 }