c26a3f298984fed6205157bf5a0a44550dff878b
[mdsal.git] / binding2 / mdsal-binding2-runtime / src / test / java / org / opendaylight / mdsal / binding / javav2 / runtime / context / util / BindingSchemaContextUtilsTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.runtime.context.util;
10
11 import static org.junit.Assert.assertNotNull;
12
13 import java.io.File;
14 import java.io.FileNotFoundException;
15 import java.net.URISyntaxException;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
19 import org.opendaylight.mdsal.gen.javav2.org.test.runtime.rev170710.data.MyCont;
20 import org.opendaylight.mdsal.gen.javav2.org.test.runtime.rev170710.data.my_cont.MyChoice;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26
27 public class BindingSchemaContextUtilsTest {
28
29     private SchemaContext schemaContext;
30     private DataNodeContainer myCont;
31     private ChoiceSchemaNode myChoice;
32
33     private static final InstanceIdentifier<MyCont> MY_CONT_NODE_PATH
34             = InstanceIdentifier.create(MyCont.class);
35
36
37     @Before
38     public void setup() throws URISyntaxException, FileNotFoundException, ReactorException {
39         schemaContext = YangParserTestUtils.parseYangFiles(
40                 new File(getClass().getResource("/yang/test-runtime.yang").toURI()));
41         myCont = (DataNodeContainer) schemaContext.getChildNodes().iterator().next();
42         myChoice = (ChoiceSchemaNode) myCont.getChildNodes().iterator().next();
43     }
44
45     @Test
46     public void utilTest() {
47         assertNotNull(BindingSchemaContextUtils.findDataNodeContainer(schemaContext, MY_CONT_NODE_PATH));
48         assertNotNull(BindingSchemaContextUtils.findInstantiatedChoice(myCont, MyChoice.class));
49         assertNotNull(BindingSchemaContextUtils.findInstantiatedCase(myChoice, myChoice.getCaseNodeByName("one")));
50     }
51 }