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