X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FTestUtils.java;h=23c18f18f581cbad24e9529dff903b159fed6f43;hb=6b2e2722172148449f7c50666543e065a919c790;hp=75cce14d09c197946ea3d9cdfe3b128d3986dca7;hpb=4c0c091813aea131d32dc70c5121a450eb9b7291;p=netconf.git diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java index 75cce14d09..23c18f18f5 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertNotNull; - import com.google.common.base.Preconditions; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -22,9 +21,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.sql.Date; import java.text.ParseException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; @@ -48,8 +45,11 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMa import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; +import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -59,40 +59,27 @@ public final class TestUtils { private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class); - private final static YangContextParser PARSER = new YangParserImpl(); - - private static Set loadModules(final String resourceDirectory) throws FileNotFoundException { - final File testDir = new File(resourceDirectory); - final String[] fileList = testDir.list(); - final List testFiles = new ArrayList(); - if (fileList == null) { - throw new FileNotFoundException(resourceDirectory); - } - for (int i = 0; i < fileList.length; i++) { - final String fileName = fileList[i]; - if (new File(testDir, fileName).isDirectory() == false) { - testFiles.add(new File(testDir, fileName)); + public static SchemaContext loadSchemaContext(final String... yangPath) + throws FileNotFoundException, ReactorException { + final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + + for (int i = 0; i < yangPath.length; i++) { + final String path = yangPath[i]; + final String pathToFile = TestUtils.class.getResource(path).getPath(); + final File testDir = new File(pathToFile); + final String[] fileList = testDir.list(); + if (fileList == null) { + throw new FileNotFoundException(pathToFile); + } + for (int j = 0; j < fileList.length; j++) { + final String fileName = fileList[j]; + final File file = new File(testDir, fileName); + if (file.isDirectory() == false) { + reactor.addSource(new YangStatementSourceImpl(new NamedFileInputStream(file, file.getPath()))); + } } } - return PARSER.parseYangModels(testFiles); - } - - public static Set loadModulesFrom(final String yangPath) { - try { - return TestUtils.loadModules(TestUtils.class.getResource(yangPath).getPath()); - } catch (final FileNotFoundException e) { - LOG.error("Yang files at path: " + yangPath + " weren't loaded."); - } - - return null; - } - - public static SchemaContext loadSchemaContext(final Set modules) { - return PARSER.resolveSchemaContext(modules); - } - - public static SchemaContext loadSchemaContext(final String resourceDirectory) throws FileNotFoundException { - return PARSER.resolveSchemaContext(loadModulesFrom(resourceDirectory)); + return reactor.buildEffective(); } public static Module findModule(final Set modules, final String moduleName) { @@ -242,7 +229,7 @@ public final class TestUtils { public static YangInstanceIdentifier.NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName, final String namespace, final String revision, final String... keysAndValues) throws ParseException { - if (keysAndValues.length % 2 != 0) { + if ((keysAndValues.length % 2) != 0) { new IllegalArgumentException("number of keys argument have to be divisible by 2 (map)"); } final Map predicate = new HashMap<>();