Update StmtTestUtils
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6880Test.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.parser.stmt.rfc7950;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15
16 import java.util.Collection;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
25 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
26
27 public class Bug6880Test {
28     private static final String FOO_NS = "foo";
29     private static final String FOO_REV = "1970-01-01";
30
31     @Test
32     public void valid10Test() throws Exception {
33         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6880/foo.yang");
34         assertNotNull(schemaContext);
35
36         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext,
37                 SchemaPath.create(true, QName.create(FOO_NS, FOO_REV, "my-leaf-list")));
38         assertTrue(findDataSchemaNode instanceof LeafListSchemaNode);
39         final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
40
41         final Collection<String> defaults = myLeafList.getDefaults();
42         assertEquals(2, defaults.size());
43         assertTrue(defaults.contains("my-default-value-1") && defaults.contains("my-default-value-2"));
44     }
45
46     @Test
47     public void invalid10Test() throws Exception {
48         try {
49             StmtTestUtils.parseYangSource("/rfc7950/bug6880/invalid10.yang");
50             fail("Test should fail due to invalid Yang 1.0");
51         } catch (final SomeModifiersUnresolvedException e) {
52             assertTrue(e.getCause().getMessage().startsWith("DEFAULT is not valid for LEAF_LIST"));
53         }
54     }
55 }