Fix typedef/bits code generation
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / Mdsal807Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.mdsal.binding.java.api.generator;
9
10 import static org.junit.Assert.assertNotNull;
11
12 import java.io.File;
13 import java.io.IOException;
14 import java.net.URISyntaxException;
15 import java.nio.file.Files;
16 import org.junit.After;
17 import org.junit.Before;
18 import org.junit.Test;
19
20 public class Mdsal807Test extends BaseCompilationTest {
21     private File sourcesOutputDir;
22     private File compiledOutputDir;
23
24     @Before
25     public void before() throws IOException, URISyntaxException {
26         sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal807");
27         compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal807");
28     }
29
30     @After
31     public void after() {
32         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
33     }
34
35     @Test
36     public void testBitsTypedef() throws IOException, URISyntaxException {
37         generateTestSources("/compilation/mdsal807", sourcesOutputDir);
38         final var pmDataType = FileSearchUtil.getFiles(sourcesOutputDir).get("TableConfig.java");
39         assertNotNull(pmDataType);
40
41         FileSearchUtil.assertFileContainsConsecutiveLines(pmDataType, Files.readString(pmDataType.toPath()),
42             "    public static TableConfig getDefaultInstance(final String defaultValue) {",
43             "        List<String> properties = Lists.newArrayList(\"oFPTCDEPRECATEDMASK\"",
44             "        );",
45             "        if (!properties.contains(defaultValue)) {",
46             "            throw new IllegalArgumentException(\"invalid default parameter\");",
47             "        }",
48             "        int i = 0;",
49             "        return new TableConfig(",
50             "        properties.get(i++).equals(defaultValue) ? true : false",
51             "        );",
52             "    }"
53         );
54         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
55     }
56 }