Initial code drop of yang model driven configuration system
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / test / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / FtlFilePersisterTest.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.ftl;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.Map;
17
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;
24
25 import com.google.common.collect.Lists;
26
27 public class FtlFilePersisterTest {
28     private final FtlFilePersister tested = new FtlFilePersister();
29
30     @Before
31     public void setUp() {
32         MockitoAnnotations.initMocks(this);
33     }
34
35     @Test
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()));
43
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"))));
48
49         GeneralInterfaceTemplate generalInterface = new GeneralInterfaceTemplate(
50                 null, packageName, name, extendedInterfaces, methods);
51
52         Map<FtlTemplate, String> abstractFtlFileStringMap = tested
53                 .serializeFtls(Arrays.asList(generalInterface));
54         String content = FormattingUtil
55                 .cleanUpEmptyLinesAndIndent(abstractFtlFileStringMap.get(generalInterface));
56
57         // skip header
58         content = content.substring(content.indexOf("package"));
59
60         String expected = "package pa.cka.ge;\n"
61                 + "/**\n"
62                 + "*\n"
63                 + "*/\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"
67                 + "}\n";
68
69         assertEquals(expected, content);
70     }
71
72 }