Initial code drop of yang model driven configuration system
[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 java.util.Collections;
16 import java.util.Map;
17
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 import com.google.common.collect.Maps;
27
28 public class ModuleMXBeanEntryTemplatesTest {
29
30     @Test
31     public void test() {
32         ModuleMXBeanEntry mbe = mockMbe("package");
33         AbstractFactoryTemplate template = TemplateFactory
34                 .abstractFactoryTemplateFromMbe(mbe);
35         assertNotNull(template);
36     }
37
38     private ModuleMXBeanEntry mockMbe(String packageName) {
39         ModuleMXBeanEntry mbe = mock(ModuleMXBeanEntry.class);
40         Map<String, AttributeIfc> a = Maps.newHashMap();
41         JavaAttribute attr = mockJavaAttr();
42
43         a.put("attr1", attr);
44         doReturn(a).when(mbe).getAttributes();
45         doReturn(packageName).when(mbe).getPackageName();
46         doReturn(Collections.emptyMap()).when(mbe).getProvidedServices();
47         doReturn("yang-module").when(mbe).getYangModuleName();
48         doReturn("local").when(mbe).getYangModuleLocalname();
49         doReturn("AbstractType").when(mbe).getAbstractFactoryName();
50         doReturn("Module").when(mbe).getStubModuleName();
51         doReturn("fullA").when(mbe).getFullyQualifiedName(anyString());
52         doReturn("uniq").when(mbe).getGloballyUniqueName();
53         return mbe;
54     }
55
56     private JavaAttribute mockJavaAttr() {
57         JavaAttribute attr = mock(JavaAttribute.class);
58         Type typeA = mock(Type.class);
59         doReturn("package").when(typeA).getName();
60         doReturn("type").when(typeA).getPackageName();
61         doReturn("package.type").when(typeA).getFullyQualifiedName();
62         doReturn(typeA).when(attr).getType();
63         doReturn("Type").when(attr).getUpperCaseCammelCase();
64         return attr;
65     }
66
67 }