package org.opendaylight.controller.md.sal.rest.common;
-import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+
import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyWriter;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
-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;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+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;
import org.w3c.dom.Element;
+import com.google.common.base.Preconditions;
+
/**
* sal-rest-connector
* org.opendaylight.controller.md.sal.rest.common
private static final Logger LOG = LoggerFactory.getLogger(TestRestconfUtils.class);
- private static final YangContextParser parser = new YangParserImpl();
-
private static final DocumentBuilderFactory BUILDERFACTORY;
static {
if (schemaContext == null) {
return loadSchemaContext(yangPath);
} else {
- return addSchemaContext(yangPath, schemaContext);
+ throw new UnsupportedOperationException("Unable to add new yang sources to existing schema context.");
}
}
catch (final Exception e) {
return null;
}
- private static Collection<File> loadFiles(final String resourceDirectory) throws FileNotFoundException {
+ public static Collection<File> loadFiles(final String resourceDirectory) throws FileNotFoundException {
final String path = TestRestconfUtils.class.getResource(resourceDirectory).getPath();
final File testDir = new File(path);
final String[] fileList = testDir.list();
return testFiles;
}
- private static SchemaContext loadSchemaContext(final String resourceDirectory) throws IOException {
- final Collection<File> testFiles = loadFiles(resourceDirectory);
- return parser.parseFiles(testFiles);
+ public static SchemaContext loadSchemaContext(String resourceDirectory)
+ throws SourceException, ReactorException, FileNotFoundException,
+ URISyntaxException {
+ return parseYangSources(loadFiles(resourceDirectory));
}
- private static SchemaContext addSchemaContext(final String resourceDirectory,
- final SchemaContext schemaContext) throws IOException, YangSyntaxErrorException {
- final Collection<File> testFiles = loadFiles(resourceDirectory);
- return parser.parseFiles(testFiles, schemaContext);
+ public static SchemaContext parseYangSources(Collection<File> testFiles)
+ throws SourceException, ReactorException, FileNotFoundException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
+ for (File testFile : testFiles) {
+ reactor.addSource(new YangStatementSourceImpl(
+ new NamedFileInputStream(testFile, testFile.getPath())));
+ }
+
+ return reactor.buildEffective();
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
+
+import java.io.File;
+import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URI;
+import java.util.Collection;
+
import javax.ws.rs.core.MediaType;
+
import org.junit.BeforeClass;
import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.yangtools.yang.common.QName;
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.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
/**
* sal-rest-connector
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
- schemaContext = schemaContextLoader("/modules", schemaContext);
- schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ public static void initialization() throws NoSuchFieldException, SecurityException, FileNotFoundException, SourceException, ReactorException {
+ Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.io.File;
import java.io.InputStream;
+import java.util.Collection;
import javax.ws.rs.core.MediaType;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException,
- SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang",
- schemaContext);
- schemaContext = schemaContextLoader("/modules", schemaContext);
- schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ public static void initialization() throws Exception {
+ Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Collection;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException,
- SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang",
- schemaContext);
- schemaContext = schemaContextLoader("/modules", schemaContext);
- schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ public static void initialization() throws Exception {
+ Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
+
+import java.io.File;
import java.io.InputStream;
import java.net.URI;
+import java.util.Collection;
+
import javax.ws.rs.core.MediaType;
+
import org.junit.BeforeClass;
import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
+
/**
* sal-rest-connector
* org.opendaylight.controller.sal.rest.impl.test.providers
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
- schemaContext = schemaContextLoader("/modules", schemaContext);
- schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ public static void initialization() throws Exception {
+ Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.io.File;
import java.io.InputStream;
+import java.util.Collection;
import javax.ws.rs.core.MediaType;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException,
- SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang",
- schemaContext);
- schemaContext = schemaContextLoader("/modules", schemaContext);
- schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ public static void initialization() throws Exception {
+ Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.OutputStream;
+import java.util.Collection;
import javax.ws.rs.core.MediaType;
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException,
- SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang",
- schemaContext);
- schemaContext = schemaContextLoader("/modules", schemaContext);
- schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
+ public static void initialization() throws Exception {
+ Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
type string;
}
}
-}l
\ No newline at end of file
+}
\ No newline at end of file