Update StmtTestUtils
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / TypedefSubStmtsTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
23
24 public class TypedefSubStmtsTest {
25
26     private static final StatementStreamSource FOOBAR = sourceForResource(
27         "/typedef-substmts-test/typedef-substmts-test.yang");
28
29     @Test
30     public void typedefSubStmtsTest() throws ReactorException {
31         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
32         reactor.addSources(FOOBAR);
33
34         EffectiveSchemaContext result = reactor.buildEffective();
35         assertNotNull(result);
36
37         Set<TypeDefinition<?>> typedefs = result.getTypeDefinitions();
38         assertEquals(1, typedefs.size());
39
40         TypeDefinition<?> typedef = typedefs.iterator().next();
41         assertEquals("time-of-the-day", typedef.getQName().getLocalName());
42         assertEquals("string", typedef.getBaseType().getQName().getLocalName());
43         assertEquals("24-hour-clock", typedef.getUnits());
44         assertEquals("1am", typedef.getDefaultValue().toString());
45     }
46 }