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