Bug 5085: Clean-up test and retest JUnit tests
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / TestModel.java
index 25e651914858f33fcdcf4dffbe50dcbc0e7cf9db..221042ac3c362956631974928de1029f8710f062 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,20 +7,20 @@
  */
 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.Arrays;
 import java.util.Collections;
+
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.impl.TestUtils;
 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 org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
-public final class TestModel {
+public 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");
+    public static final QName TEST_QNAME = QName.create(
+            "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", "test");
     public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list");
     public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list");
     public static final QName OUTER_CHOICE_QNAME = QName.create(TEST_QNAME, "outer-choice");
@@ -30,29 +30,21 @@ public final class TestModel {
     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
 
     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 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");
 
-    private TestModel() {
-        throw new UnsupportedOperationException();
-    }
-
     public static InputStream getDatastoreTestInputStream() {
         return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
     }
 
-    public static SchemaContext createTestContext() {
-        return createTestContext(DATASTORE_TEST_YANG);
+    public static SchemaContext createTestContext() throws ReactorException {
+        return TestUtils.parseYangStreams(Arrays.asList(getDatastoreTestInputStream()));
     }
 
-    public static SchemaContext createTestContext(String resourcePath) {
-        YangParserImpl parser = new YangParserImpl();
-        try {
-            return parser.parseSources(Collections.singleton(Resources.asByteSource(TestModel.class
-                    .getResource(resourcePath))));
-        } catch (IOException | YangSyntaxErrorException e) {
-            throw new IllegalStateException("Failed to create context", e);
-        }
+    public static SchemaContext createTestContext(String resourcePath) throws ReactorException {
+        InputStream yangStream = TestModel.class.getResourceAsStream(resourcePath);
+        return TestUtils.parseYangStreams(Collections.singletonList(yangStream));
     }
 }