2 * Copyright (c) 2021 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.generator.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
13 import java.util.List;
14 import org.junit.Test;
15 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
16 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
17 import org.opendaylight.mdsal.binding.model.ri.Types;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
19 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
21 public class LeafrefResolutionTest {
23 public void testLeafRefRelativeSelfReference() {
24 final EffectiveModelContext schemaContext =
25 YangParserTestUtils.parseYangResource("/leafref-relative-invalid.yang");
26 final IllegalArgumentException iae = assertThrows(IllegalArgumentException.class,
27 () -> DefaultBindingGenerator.generateFor(schemaContext));
29 "Effective model contains self-referencing leaf (urn:xml:ns:yang:lrr?revision=2015-02-25)neighbor-id",
34 public void testLeafRefAbsoluteSelfReference() {
35 final EffectiveModelContext schemaContext =
36 YangParserTestUtils.parseYangResource("/leafref-absolute-invalid.yang");
37 final IllegalArgumentException iae = assertThrows(IllegalArgumentException.class,
38 () -> DefaultBindingGenerator.generateFor(schemaContext));
40 "Effective model contains self-referencing leaf (urn:xml:ns:yang:lra?revision=2015-02-25)neighbor-id",
45 public void testLeafRefRelativeAndAbsoluteValidReference() {
46 final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
47 YangParserTestUtils.parseYangResource("/leafref-valid.yang"));
48 assertEquals(2, types.size());
50 final List<MethodSignature> neighborMethods = types.stream()
51 .filter(type -> type.getName().equals("Neighbor"))
54 .getMethodDefinitions();
55 assertEquals(10, neighborMethods.size());
57 final MethodSignature getNeighborId = neighborMethods.stream()
58 .filter(method -> method.getName().equals("getNeighborId"))
61 assertEquals(Types.STRING, getNeighborId.getReturnType());
63 final MethodSignature getNeighbor2Id = neighborMethods.stream()
64 .filter(method -> method.getName().equals("getNeighbor2Id"))
67 assertEquals(Types.STRING, getNeighbor2Id.getReturnType());