076e4e981277ae0da1d1c4621a8ce8b0dc3b90a5
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / test / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ModuleMXBeanEntryTemplatesTest.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.yangjmxgenerator.plugin;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.Matchers.anyString;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14
15 import com.google.common.collect.Maps;
16 import java.util.Collections;
17 import java.util.Map;
18 import org.junit.Test;
19 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
20 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
21 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
22 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractFactoryTemplate;
23 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory;
24 import org.opendaylight.yangtools.sal.binding.model.api.Type;
25
26 public class ModuleMXBeanEntryTemplatesTest {
27
28     @Test
29     public void test() {
30         ModuleMXBeanEntry mbe = mockMbe("package");
31         AbstractFactoryTemplate template = TemplateFactory
32                 .abstractFactoryTemplateFromMbe(mbe);
33         assertNotNull(template);
34     }
35
36     public static ModuleMXBeanEntry mockMbe(String packageName) {
37         ModuleMXBeanEntry mbe = mock(ModuleMXBeanEntry.class);
38         Map<String, AttributeIfc> a = Maps.newHashMap();
39         JavaAttribute attr = mockJavaAttr();
40
41         a.put("attr1", attr);
42         doReturn(a).when(mbe).getAttributes();
43         doReturn(packageName).when(mbe).getPackageName();
44         doReturn(Collections.emptyMap()).when(mbe).getProvidedServices();
45         doReturn("yang-module").when(mbe).getYangModuleName();
46         doReturn("local").when(mbe).getYangModuleLocalname();
47         doReturn("AbstractType").when(mbe).getAbstractFactoryName();
48         doReturn("Module").when(mbe).getStubModuleName();
49         doReturn("fullA").when(mbe).getFullyQualifiedName(anyString());
50         doReturn("uniq").when(mbe).getGloballyUniqueName();
51         return mbe;
52     }
53
54     public static JavaAttribute mockJavaAttr() {
55         JavaAttribute attr = mock(JavaAttribute.class);
56         Type typeA = mock(Type.class);
57         doReturn("package").when(typeA).getName();
58         doReturn("type").when(typeA).getPackageName();
59         doReturn("package.type").when(typeA).getFullyQualifiedName();
60         doReturn(typeA).when(attr).getType();
61         doReturn("Type").when(attr).getUpperCaseCammelCase();
62         doReturn("new Default()").when(attr).getNullableDefault();
63         return attr;
64     }
65
66 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.