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.ftl;
10 import static org.junit.Assert.assertEquals;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.List;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
22 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration;
23 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FormattingUtil;
25 import com.google.common.collect.Lists;
27 public class FtlFilePersisterTest {
28 private final FtlFilePersister tested = new FtlFilePersister();
32 MockitoAnnotations.initMocks(this);
36 public void testGeneralInterface() {
37 String packageName = "pa.cka.ge";
38 String name = "GeneralClassImpl";
39 List<String> extendedInterfaces = Arrays.asList("List", "Set");
40 List<MethodDeclaration> methods = new ArrayList<>();
41 methods.add(new MethodDeclaration("String", "executeOperation",
42 Collections.<Field> emptyList()));
44 List<String> mods = Lists.newArrayList();
45 List<String> mods2 = Lists.newArrayList("final");
46 methods.add(new MethodDeclaration("String", "executeOperation", Arrays
47 .asList(new Field(mods, "int", "param1"), new Field(mods2, "long", "param2"))));
49 GeneralInterfaceTemplate generalInterface = new GeneralInterfaceTemplate(
50 null, packageName, name, extendedInterfaces, methods);
52 Map<FtlTemplate, String> abstractFtlFileStringMap = tested
53 .serializeFtls(Arrays.asList(generalInterface));
54 String content = FormattingUtil
55 .cleanUpEmptyLinesAndIndent(abstractFtlFileStringMap.get(generalInterface));
58 content = content.substring(content.indexOf("package"));
60 String expected = "package pa.cka.ge;\n"
64 + "public interface GeneralClassImpl extends List, Set\n{\n"
65 + "public String executeOperation();\n"
66 + "public String executeOperation(int param1, final long param2);\n"
69 assertEquals(expected, content);