2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.mdsal.binding.java.api.generator;
10 import static org.junit.Assert.assertNotNull;
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;
20 public class Mdsal732Test extends BaseCompilationTest {
21 private File sourcesOutputDir;
22 private File compiledOutputDir;
25 public void before() throws IOException, URISyntaxException {
26 sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal732");
27 compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal732");
32 CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
36 public void testIdentityrefLeafrefSpecialization() throws IOException, URISyntaxException {
37 generateTestSources("/compilation/mdsal732", sourcesOutputDir);
38 final var xyzzyBuilder = FileSearchUtil.getFiles(sourcesOutputDir).get("XyzzyBuilder.java");
39 assertNotNull(xyzzyBuilder);
41 final var content = Files.readString(xyzzyBuilder.toPath());
42 FileSearchUtil.assertFileContainsConsecutiveLines(xyzzyBuilder, content,
43 " public XyzzyBuilder(Grp arg) {",
44 " this._foo = CodeHelpers.checkFieldCastIdentity(Foo.class, \"foo\", arg.getFoo());",
45 " this._bar = CodeHelpers.checkSetFieldCastIdentity(Foo.class, \"bar\", arg.getBar());",
46 " this._baz = CodeHelpers.checkListFieldCastIdentity(Foo.class, \"baz\", arg.getBaz());",
48 FileSearchUtil.assertFileContainsConsecutiveLines(xyzzyBuilder, content,
49 " public void fieldsFrom(DataObject arg) {",
50 " boolean isValidArg = false;",
51 " if (arg instanceof Grp) {",
52 " this._foo = CodeHelpers.checkFieldCastIdentity(Foo.class, \"foo\", ((Grp)arg).getFoo());",
53 " this._bar = CodeHelpers.checkSetFieldCastIdentity(Foo.class, \"bar\", ((Grp)arg).getBar());",
54 " this._baz = CodeHelpers.checkListFieldCastIdentity(Foo.class, \"baz\", ((Grp)arg).getBaz());",
55 " isValidArg = true;",
57 " CodeHelpers.validValue(isValidArg, arg, \"[Grp]\");",
60 CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);