Fix warnings in config-manager
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / util / InterfacesHelperTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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.controller.config.manager.impl.util;
9
10 import static org.junit.Assert.assertEquals;
11 import com.google.common.collect.ImmutableSet;
12 import com.google.common.collect.Sets;
13 import java.util.Collections;
14 import java.util.HashSet;
15 import java.util.Set;
16 import javax.management.MXBean;
17 import org.junit.Test;
18 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
19 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
20 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingScheduledThreadPoolServiceInterface;
21 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
22 import org.opendaylight.controller.config.spi.Module;
23 import org.opendaylight.yangtools.concepts.Identifiable;
24
25 public class InterfacesHelperTest {
26
27     interface SuperA {
28
29     }
30
31     interface SuperBMXBean {
32
33     }
34
35     interface SuperC extends SuperA, SuperBMXBean {
36
37     }
38
39     class SuperClass implements SuperC {
40
41     }
42
43     @MXBean
44     interface SubA {
45
46     }
47
48     @ServiceInterfaceAnnotation(value = "a", osgiRegistrationType = SuperA.class, namespace = "n", revision = "r", localName = "l")
49     interface Service extends AbstractServiceInterface{}
50     @ServiceInterfaceAnnotation(value = "b", osgiRegistrationType = SuperC.class, namespace = "n", revision = "r", localName = "l")
51     interface SubService extends Service{}
52
53     abstract class SubClass extends SuperClass implements SubA, Module {
54
55     }
56
57     abstract class SubClassWithService implements SubService, Module {
58
59     }
60
61     @Test
62     public void testGetAllInterfaces() {
63         Set<Class<?>> expected = Sets.<Class<?>> newHashSet(SuperA.class, SuperBMXBean.class, SuperC.class,
64                 SubA.class, Identifiable.class, Module.class);
65         assertEquals(expected,
66                 InterfacesHelper.getAllInterfaces(SubClass.class));
67     }
68
69     @Test
70     public void testGetServiceInterfaces() throws Exception {
71         assertEquals(Collections.<Class<?>>emptySet(), InterfacesHelper.getServiceInterfaces(SubClass.class));
72         assertEquals(Sets.<Class<?>>newHashSet(Service.class, SubService.class), InterfacesHelper.getServiceInterfaces(SubClassWithService.class));
73     }
74
75     @Test
76     public void testGetOsgiRegistrationTypes() throws Exception {
77         assertEquals(Collections.<Class<?>>emptySet(), InterfacesHelper.getOsgiRegistrationTypes(SubClass.class));
78         assertEquals(Sets.<Class<?>>newHashSet(SuperA.class, SuperC.class),
79                 InterfacesHelper.getOsgiRegistrationTypes(SubClassWithService.class));
80     }
81
82     @Test
83     public void testGetMXInterfaces() {
84         Set<Class<?>> expected = Sets.<Class<?>> newHashSet(SuperBMXBean.class, SubA.class);
85         assertEquals(expected, InterfacesHelper.getMXInterfaces(SubClass.class));
86     }
87
88     @Test
89     public void testGetAllAbstractServiceInterfaceClasses(){
90         Class<? extends AbstractServiceInterface> clazz = TestingScheduledThreadPoolServiceInterface.class;
91         Set<Class<? extends AbstractServiceInterface>> input = new HashSet<>();
92         input.add(clazz);
93         Set<Class<? extends AbstractServiceInterface>> result = InterfacesHelper.getAllAbstractServiceInterfaceClasses(input);
94
95         Set<Class<?>> expected = ImmutableSet.of((Class<?>) TestingScheduledThreadPoolServiceInterface.class,
96                 TestingThreadPoolServiceInterface.class
97                 );
98         assertEquals(expected, result);
99     }
100
101 }