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