Remove redundant modifiers
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / TestModel.java
index 5c81b6cba9efd670066ac0b7fe0de917f7098b70..25e651914858f33fcdcf4dffbe50dcbc0e7cf9db 100644 (file)
@@ -7,17 +7,17 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
+import com.google.common.io.Resources;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.Set;
-
-public class TestModel {
+public final class TestModel {
 
     public static final QName TEST_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13",
         "test");
@@ -29,23 +29,30 @@ public class TestModel {
     public static final QName VALUE_QNAME = QName.create(TEST_QNAME, "value");
     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
 
-    public static final InstanceIdentifier TEST_PATH = InstanceIdentifier.of(TEST_QNAME);
-    public static final InstanceIdentifier OUTER_LIST_PATH = InstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
+    public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
+    public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
     public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two");
     public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three");
 
-
-    public static final InputStream getDatastoreTestInputStream() {
-        return getInputStream(DATASTORE_TEST_YANG);
+    private TestModel() {
+        throw new UnsupportedOperationException();
     }
 
-    private static InputStream getInputStream(final String resourceName) {
+    public static InputStream getDatastoreTestInputStream() {
         return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
     }
 
     public static SchemaContext createTestContext() {
+        return createTestContext(DATASTORE_TEST_YANG);
+    }
+
+    public static SchemaContext createTestContext(String resourcePath) {
         YangParserImpl parser = new YangParserImpl();
-        Set<Module> modules = parser.parseYangModelsFromStreams(Collections.singletonList(getDatastoreTestInputStream()));
-        return parser.resolveSchemaContext(modules);
+        try {
+            return parser.parseSources(Collections.singleton(Resources.asByteSource(TestModel.class
+                    .getResource(resourcePath))));
+        } catch (IOException | YangSyntaxErrorException e) {
+            throw new IllegalStateException("Failed to create context", e);
+        }
     }
 }