2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.manager.impl.util;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.collect.ImmutableSet;
13 import com.google.common.collect.Sets;
14 import java.util.Collections;
15 import java.util.HashSet;
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;
26 public class InterfacesHelperTest {
32 interface SuperBMXBean {
36 interface SuperC extends SuperA, SuperBMXBean {
40 class SuperClass implements SuperC {
49 @ServiceInterfaceAnnotation(value = "a", osgiRegistrationType = SuperA.class, namespace = "n", revision = "r", localName = "l")
50 interface Service extends AbstractServiceInterface{}
51 @ServiceInterfaceAnnotation(value = "b", osgiRegistrationType = SuperC.class, namespace = "n", revision = "r", localName = "l")
52 interface SubService extends Service{}
54 abstract class SubClass extends SuperClass implements SubA, Module {
58 abstract class SubClassWithService implements SubService, Module {
63 public void testGetAllInterfaces() {
64 Set<Class<?>> expected = Sets.<Class<?>> newHashSet(SuperA.class, SuperBMXBean.class, SuperC.class,
65 SubA.class, Identifiable.class, Module.class);
66 assertEquals(expected,
67 InterfacesHelper.getAllInterfaces(SubClass.class));
71 public void testGetServiceInterfaces() throws Exception {
72 assertEquals(Collections.<Class<?>>emptySet(), InterfacesHelper.getServiceInterfaces(SubClass.class));
73 assertEquals(Sets.<Class<?>>newHashSet(Service.class, SubService.class), InterfacesHelper.getServiceInterfaces(SubClassWithService.class));
77 public void testGetOsgiRegistrationTypes() throws Exception {
78 assertEquals(Collections.<Class<?>>emptySet(), InterfacesHelper.getOsgiRegistrationTypes(SubClass.class));
79 assertEquals(Sets.<Class<?>>newHashSet(SuperA.class, SuperC.class),
80 InterfacesHelper.getOsgiRegistrationTypes(SubClassWithService.class));
84 public void testGetMXInterfaces() {
85 Set<Class<?>> expected = Sets.<Class<?>> newHashSet(SuperBMXBean.class, SubA.class);
86 assertEquals(expected, InterfacesHelper.getMXInterfaces(SubClass.class));
90 public void testGetAllAbstractServiceInterfaceClasses(){
91 Class<? extends AbstractServiceInterface> clazz = TestingScheduledThreadPoolServiceInterface.class;
92 Set<Class<? extends AbstractServiceInterface>> input = new HashSet<>();
94 Set<Class<? extends AbstractServiceInterface>> result = InterfacesHelper.getAllAbstractServiceInterfaceClasses(input);
96 Set<Class<?>> expected = ImmutableSet.of((Class<?>) TestingScheduledThreadPoolServiceInterface.class,
97 TestingThreadPoolServiceInterface.class
99 assertEquals(expected, result);