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 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;
19 import java.util.Collections;
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;
27 public class ModuleMXBeanEntryTemplatesTest {
31 ModuleMXBeanEntry mbe = mockMbe("package");
32 AbstractFactoryTemplate template = TemplateFactory
33 .abstractFactoryTemplateFromMbe(mbe);
34 assertNotNull(template);
37 public static ModuleMXBeanEntry mockMbe(String packageName) {
38 ModuleMXBeanEntry mbe = mock(ModuleMXBeanEntry.class);
39 Map<String, AttributeIfc> a = Maps.newHashMap();
40 JavaAttribute attr = mockJavaAttr();
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();
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();