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.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
25 public class TypedefSubStmtsTest {
27 private static final StatementStreamSource FOOBAR = sourceForResource(
28 "/typedef-substmts-test/typedef-substmts-test.yang");
31 public void typedefSubStmtsTest() throws ReactorException {
32 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
33 reactor.addSources(FOOBAR);
35 SchemaContext result = reactor.buildEffective();
36 assertNotNull(result);
38 Set<TypeDefinition<?>> typedefs = result.getTypeDefinitions();
39 assertEquals(1, typedefs.size());
41 TypeDefinition<?> typedef = typedefs.iterator().next();
42 assertEquals("time-of-the-day", typedef.getQName().getLocalName());
43 assertEquals("string", typedef.getBaseType().getQName().getLocalName());
44 assertEquals(Optional.of("24-hour-clock"), typedef.getUnits());
45 assertEquals("1am", typedef.getDefaultValue().map(Object::toString).orElse(null));