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;
14 import com.google.common.collect.Maps;
15 import java.util.Collections;
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;
25 public class ModuleMXBeanEntryTemplatesTest {
29 final ModuleMXBeanEntry mbe = mockMbe("package");
30 final AbstractFactoryTemplate template = TemplateFactory
31 .abstractFactoryTemplateFromMbe(mbe);
32 assertNotNull(template);
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();
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();
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();