Fix mdsal-dom-spi dependencies
[mdsal.git] / binding / mdsal-binding-generator / src / test / java / org / opendaylight / mdsal / binding / generator / impl / Mdsal824Test.java
1 /*
2  * Copyright (c) 2023 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.generator.impl;
9
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
17 import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
18 import org.opendaylight.mdsal.binding.runtime.api.ContainerRuntimeType;
19 import org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType;
20 import org.opendaylight.mdsal.binding.runtime.api.ListRuntimeType;
21 import org.opendaylight.mdsal.binding.runtime.api.OutputRuntimeType;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 public class Mdsal824Test {
27     private static EffectiveModelContext CONTEXT;
28
29     @BeforeClass
30     public static void beforeClass() {
31         CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/mdsal824");
32     }
33
34     @Test
35     public void testCompileTimeTypes() {
36         assertEquals(13, DefaultBindingGenerator.generateFor(CONTEXT).size());
37     }
38
39     @Test
40     public void testRunTimeTypes() {
41         final var types = BindingRuntimeTypesFactory.createTypes(CONTEXT);
42         final var barTop = types.schemaTreeChild(QName.create("bar", "bar-top"));
43         assertThat(barTop, instanceOf(ContainerRuntimeType.class));
44         final var barList = ((ContainerRuntimeType) barTop).schemaTreeChild(QName.create("bar", "bar-list"));
45         assertThat(barList, instanceOf(ListRuntimeType.class));
46         final var barAction = ((ListRuntimeType) barList).schemaTreeChild(QName.create("bar", "foo"));
47         assertThat(barAction, instanceOf(ActionRuntimeType.class));
48
49         final var barInput = ((ActionRuntimeType) barAction).schemaTreeChild(QName.create("bar", "input"));
50         assertThat(barInput, instanceOf(InputRuntimeType.class));
51         assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.foo.norev.act.grp", "FooInput"),
52             barInput.javaType().getIdentifier());
53
54         final var barOutput = ((ActionRuntimeType) barAction).schemaTreeChild(QName.create("bar", "output"));
55         assertThat(barOutput, instanceOf(OutputRuntimeType.class));
56         assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.foo.norev.act.grp", "FooOutput"),
57             barOutput.javaType().getIdentifier());
58     }
59 }