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.yangjmxgenerator.plugin;
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;
15 import com.google.common.collect.Maps;
16 import java.util.Collections;
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;
26 public class ModuleMXBeanEntryTemplatesTest {
30 ModuleMXBeanEntry mbe = mockMbe("package");
31 AbstractFactoryTemplate template = TemplateFactory
32 .abstractFactoryTemplateFromMbe(mbe);
33 assertNotNull(template);
36 public static ModuleMXBeanEntry mockMbe(String packageName) {
37 ModuleMXBeanEntry mbe = mock(ModuleMXBeanEntry.class);
38 Map<String, AttributeIfc> a = Maps.newHashMap();
39 JavaAttribute attr = mockJavaAttr();
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();
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();