Merge "Bug 116 - Revisit SanityTest"
[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
12 import java.util.HashSet;
13 import java.util.Set;
14
15 import javax.management.MXBean;
16
17 import org.junit.Test;
18 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
19 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingScheduledThreadPoolServiceInterface;
20 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
21 import org.opendaylight.controller.config.spi.Module;
22 import org.opendaylight.yangtools.concepts.Identifiable;
23
24 import com.google.common.collect.Sets;
25
26 public class InterfacesHelperTest {
27
28     interface SuperA {
29
30     }
31
32     interface SuperBMXBean {
33
34     }
35
36     interface SuperC extends SuperA, SuperBMXBean {
37
38     }
39
40     class SuperClass implements SuperC {
41
42     }
43
44     @MXBean
45     interface SubA {
46
47     }
48
49     abstract class SubClass extends SuperClass implements SubA, Module {
50
51     }
52
53     @Test
54     public void testGetAllInterfaces() {
55         Set<Class<?>> expected = Sets.<Class<?>> newHashSet(SuperA.class, SuperBMXBean.class, SuperC.class,
56                 SubA.class, Identifiable.class, Module.class);
57         assertEquals(expected,
58                 InterfacesHelper.getAllInterfaces(SubClass.class));
59     }
60
61     @Test
62     public void testGetMXInterfaces() {
63         Set<Class<?>> expected = Sets.<Class<?>> newHashSet(SuperBMXBean.class, SubA.class);
64         assertEquals(expected, InterfacesHelper.getMXInterfaces(SubClass.class));
65     }
66
67     @Test
68     public void testGetAllAbstractServiceInterfaceClasses(){
69         Class<? extends AbstractServiceInterface> clazz = TestingScheduledThreadPoolServiceInterface.class;
70         Set<Class<? extends AbstractServiceInterface>> input = new HashSet<>();
71         input.add(clazz);
72         Set<Class<? extends AbstractServiceInterface>> result = InterfacesHelper.getAllAbstractServiceInterfaceClasses(input);
73
74         Set<Class<?>> expected = Sets.newHashSet((Class<?>) TestingScheduledThreadPoolServiceInterface.class,
75                 TestingThreadPoolServiceInterface.class
76                 );
77         assertEquals(expected, result);
78     }
79
80 }