Adjust test suite parser update to conform with API changes
[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
30     @Test
31     public void valid10Test() throws Exception {
32         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6880/foo.yang");
33         assertNotNull(schemaContext);
34
35         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext,
36                 SchemaPath.create(true, QName.create(FOO_NS, "my-leaf-list")));
37         assertTrue(findDataSchemaNode instanceof LeafListSchemaNode);
38         final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
39
40         final Collection<? extends Object> defaults = myLeafList.getDefaults();
41         assertEquals(2, defaults.size());
42         assertTrue(defaults.contains("my-default-value-1") && defaults.contains("my-default-value-2"));
43     }
44
45     @Test
46     public void invalid10Test() throws Exception {
47         try {
48             StmtTestUtils.parseYangSource("/rfc7950/bug6880/invalid10.yang");
49             fail("Test should fail due to invalid Yang 1.0");
50         } catch (final SomeModifiersUnresolvedException e) {
51             assertTrue(e.getCause().getMessage().startsWith("DEFAULT is not valid for LEAF_LIST"));
52         }
53     }
54 }