Adjust test suite parser update to conform with API changes
[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.Optional;
16 import java.util.Set;
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;
22
23 public class TypedefSubStmtsTest {
24
25     @Test
26     public void typedefSubStmtsTest() throws ReactorException {
27         SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
28                 .addSource(sourceForResource("/typedef-substmts-test/typedef-substmts-test.yang"))
29                 .buildEffective();
30         assertNotNull(result);
31
32         Set<TypeDefinition<?>> typedefs = result.getTypeDefinitions();
33         assertEquals(1, typedefs.size());
34
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));
40     }
41 }