X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fcluster%2Fdatastore%2Fmodel%2FSchemaContextHelper.java;h=fd011d2cde708e6d3f0de4ca5c3bfff9da0fd5f6;hb=refs%2Fchanges%2F83%2F47483%2F3;hp=d09e4b96909e176ad9afd18613a012e2536d8d6c;hpb=085b076786d299c235ab5561c9fa678fd6b8d726;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java index d09e4b9690..fd011d2cde 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java @@ -8,13 +8,19 @@ package org.opendaylight.controller.md.cluster.datastore.model; +import com.google.common.io.ByteSource; +import com.google.common.io.Resources; +import java.io.File; +import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import java.util.Set; -import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -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; public class SchemaContextHelper { @@ -23,23 +29,49 @@ public class SchemaContextHelper { public static final String CARS_YANG = "/cars.yang"; public static InputStream getInputStream(final String yangFileName) { - return TestModel.class.getResourceAsStream(yangFileName); + return SchemaContextHelper.class.getResourceAsStream(yangFileName); } - public static SchemaContext full(){ + public static SchemaContext full() { return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG); } - public static SchemaContext select(String... schemaFiles){ - YangParserImpl parser = new YangParserImpl(); + public static SchemaContext select(String... schemaFiles) { + final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + final SchemaContext schemaContext; List streams = new ArrayList<>(); - for(String schemaFile : schemaFiles){ + for (String schemaFile : schemaFiles) { streams.add(getInputStream(schemaFile)); } - Set modules = parser.parseYangModelsFromStreams(streams); - return parser.resolveSchemaContext(modules); + try { + schemaContext = reactor.buildEffective(streams); + } catch (ReactorException e) { + throw new RuntimeException("Unable to build schema context from " + streams, e); + } + + return schemaContext; } + public static SchemaContext entityOwners() { + final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + final SchemaContext schemaContext; + File file = null; + + try { + file = new File("src/main/yang/entity-owners.yang"); + final List sources = Arrays.asList(Resources.asByteSource(file.toURI().toURL())); + try { + schemaContext = reactor.buildEffective(sources); + } catch (IOException e1) { + throw new ExceptionInInitializerError(e1); + } catch (ReactorException e2) { + throw new RuntimeException("Unable to build schema context from " + sources, e2); + } + return schemaContext; + } catch (MalformedURLException e3) { + throw new RuntimeException("Malformed URL detected in " + file, e3); + } + } }