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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
14 import com.google.common.collect.ImmutableRangeSet;
15 import com.google.common.collect.Range;
16 import com.google.common.collect.RangeSet;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
20 import org.opendaylight.mdsal.binding.model.api.Type;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class Bug1862Test {
25 public void restrictedTypedefTransformationTest() {
26 final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(Bug1862Test.class,
27 "/base-yang-types.yang", "/test-type-provider.yang"));
28 assertEquals(35, types.size());
29 final MethodSignature fooGetter = types.stream()
30 .filter(type -> type.getFullyQualifiedName().equals(
31 "org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.Foo"))
32 .findFirst().orElseThrow()
33 .getMethodDefinitions().stream()
34 .filter(method -> method.getName().equals("getBug1862RestrictedTypedef"))
35 .findFirst().orElseThrow();
37 final Type returnType = fooGetter.getReturnType();
38 assertThat(returnType, instanceOf(GeneratedTransferObject.class));
39 final RangeSet<?> range = ((GeneratedTransferObject) returnType).getRestrictions().getRangeConstraint()
40 .orElseThrow().getAllowedRanges();
41 assertEquals(ImmutableRangeSet.of(Range.closed((byte) 1, (byte) 100)), range);