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