2 * Copyright (c) 2016 Cisco Systems, Inc. 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.yangtools.yang.stmt;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertNotNull;
13 import static org.junit.jupiter.api.Assertions.assertNull;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.Decimal64;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
22 class TypedefConstraintsTest extends AbstractYangTest {
24 void decimalRangeConstraintsTest() {
25 final var context = assertEffectiveModelDir("/stmt-test/constraints");
27 assertNotNull(context);
29 final var typeDefinitions = context.getTypeDefinitions();
30 assertNotNull(typeDefinitions);
31 assertEquals(1, typeDefinitions.size());
33 final var myDecimal = typeDefinitions.iterator().next();
35 final var rangeConstraints = assertInstanceOf(DecimalTypeDefinition.class, myDecimal)
37 .orElseThrow().getAllowedRanges().asRanges();
39 assertNotNull(rangeConstraints);
40 assertEquals(1, rangeConstraints.size());
42 final var dataNode = context.getDataChildByName(QName.create("urn:opendaylight.foo", "2013-10-08",
44 final var leafDecimal = assertInstanceOf(LeafSchemaNode.class, dataNode);
46 final var type = leafDecimal.getType();
48 final var decType = assertInstanceOf(DecimalTypeDefinition.class, type);
49 assertEquals(4, decType.getFractionDigits());
51 final var decRangeConstraints = decType.getRangeConstraint().orElseThrow().getAllowedRanges().asRanges();
53 assertEquals(1, decRangeConstraints.size());
55 final var range = decRangeConstraints.iterator().next();
56 assertEquals(Decimal64.of(4, 15000), range.lowerEndpoint());
57 assertEquals(4, range.lowerEndpoint().scale());
58 assertEquals(Decimal64.of(4, 55000), range.upperEndpoint());
59 assertEquals(4, range.upperEndpoint().scale());
61 assertEquals(TypeDefinitions.DECIMAL64.bindTo(leafDecimal.getQName().getModule()), decType.getQName());
62 assertNull(decType.getBaseType());