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.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14 import java.util.Collection;
15 import java.util.Optional;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 public class TypedefSubStmtsTest {
25 public void typedefSubStmtsTest() throws ReactorException {
26 SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
27 .addSource(sourceForResource("/typedef-substmts-test/typedef-substmts-test.yang"))
29 assertNotNull(result);
31 Collection<? extends TypeDefinition<?>> typedefs = result.getTypeDefinitions();
32 assertEquals(1, typedefs.size());
34 TypeDefinition<?> typedef = typedefs.iterator().next();
35 assertEquals("time-of-the-day", typedef.getQName().getLocalName());
36 assertEquals("string", typedef.getBaseType().getQName().getLocalName());
37 assertEquals(Optional.of("24-hour-clock"), typedef.getUnits());
38 assertEquals("1am", typedef.getDefaultValue().map(Object::toString).orElse(null));