<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-parser-impl</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-test-util</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>ietf-restconf</artifactId>
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.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.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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
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
+ * sal-rest-connector org.opendaylight.controller.md.sal.rest.common
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
- * Created: Mar 7, 2015
+ * Created: Mar 7, 2015
*/
public class TestRestconfUtils {
BUILDERFACTORY = factory;
}
- private TestRestconfUtils () {
+ private TestRestconfUtils() {
throw new UnsupportedOperationException("Test utility class");
}
public static SchemaContext loadSchemaContext(final String yangPath, final SchemaContext schemaContext) {
try {
Preconditions.checkArgument(yangPath != null, "Path can not be null.");
- Preconditions.checkArgument(( ! yangPath.isEmpty()), "Path can not be empty.");
+ Preconditions.checkArgument((!yangPath.isEmpty()), "Path can not be empty.");
if (schemaContext == null) {
- return loadSchemaContext(yangPath);
+ return YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(yangPath));
} else {
throw new UnsupportedOperationException("Unable to add new yang sources to existing schema context.");
}
- }
- catch (final Exception e) {
+ } catch (final Exception e) {
LOG.error("Yang files at path: " + yangPath + " weren't loaded.");
}
return schemaContext;
throw new AbstractMethodError("Not implemented yet");
}
- public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile, final String uri) {
+ public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile,
+ final String uri) {
final InstanceIdentifierContext<?> iiContext = ControllerContext.getInstance().toInstanceIdentifier(uri);
final InputStream inputStream = TestJsonBodyWriter.class.getResourceAsStream(pathToInputFile);
try {
final Document doc = dBuilder.parse(inputStream);
final NormalizedNode<?, ?> nn = parse(iiContext, doc);
return new NormalizedNodeContext(iiContext, nn);
- }
- catch (final Exception e) {
+ } catch (final Exception e) {
LOG.error("Load xml file " + pathToInputFile + " fail.", e);
}
return null;
}
}
}
- final DomToNormalizedNodeParserFactory parserFactory =
- DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, iiContext.getSchemaContext());
+ final DomToNormalizedNodeParserFactory parserFactory = DomToNormalizedNodeParserFactory
+ .getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, iiContext.getSchemaContext());
- if(schemaNode instanceof ContainerSchemaNode) {
- return parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()), (ContainerSchemaNode) schemaNode);
- } else if(schemaNode instanceof ListSchemaNode) {
+ if (schemaNode instanceof ContainerSchemaNode) {
+ return parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()),
+ (ContainerSchemaNode) schemaNode);
+ } else if (schemaNode instanceof ListSchemaNode) {
final ListSchemaNode casted = (ListSchemaNode) schemaNode;
return parserFactory.getMapEntryNodeParser().parse(elements, casted);
} // FIXME : add another DataSchemaNode extensions e.g. LeafSchemaNode
}
return testFiles;
}
-
- public static SchemaContext loadSchemaContext(String resourceDirectory)
- throws SourceException, ReactorException, FileNotFoundException,
- URISyntaxException {
- return parseYangSources(loadFiles(resourceDirectory));
- }
-
- 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 org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class InstanceIdentifierTypeLeafTest {
@Test
public void stringToInstanceIdentifierTest() throws Exception {
- final SchemaContext schemaContext = TestRestconfUtils.loadSchemaContext("/instanceidentifier");
+ final SchemaContext schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/instanceidentifier"));
ControllerContext.getInstance().setGlobalSchema(schemaContext);
final InstanceIdentifierContext<?> instanceIdentifier =
ControllerContext.getInstance().toInstanceIdentifier(
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 org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* sal-rest-connector
public TestJsonBodyReader () throws NoSuchFieldException, SecurityException {
super();
- jsonBodyReader = new JsonNormalizedNodeBodyReader();
+ this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, false);
+ mockBodyReader(uri, this.jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/jsondata.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
final String uri = "instance-identifier-module:cont/cont1";
- mockBodyReader(uri, jsonBodyReader, false);
+ mockBodyReader(uri, this.jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
}
final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
.node(augII).node(contAugmentQName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_augment_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
.node(augChoice1II).node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName)
.node(containerQName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_augment_choice_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
@Test
public void rpcModuleInputTest() throws Exception {
final String uri = "invoke-rpc-module:rpc-test";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/invoke-rpc/json/rpc-input.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode inputNode = (ContainerNode) returnValue.getData();
final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
public TestJsonBodyReaderMountPoint() throws NoSuchFieldException,
SecurityException {
super();
- jsonBodyReader = new JsonNormalizedNodeBodyReader();
+ this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, false);
+ mockBodyReader(uri, this.jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/jsondata.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
- mockBodyReader(uri, jsonBodyReader, false);
+ mockBodyReader(uri, this.jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
QName.create(dataSchemaNode.getQName(), "cont1"));
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void rpcModuleInputTest() throws Exception {
final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/invoke-rpc/json/rpc-input.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode inputNode = (ContainerNode) returnValue.getData();
final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName
.getSchemaContext().getDataChildByName(
dataSchemaNode.getQName());
assertNotNull(mountDataSchemaNode);
- if (qName != null && dataSchemaNode instanceof DataNodeContainer) {
+ if ((qName != null) && (dataSchemaNode instanceof DataNodeContainer)) {
final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
.getDataChildByName(qName);
dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
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.NormalizedNodeJsonBodyWriter;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
public TestJsonBodyWriter() throws NoSuchFieldException, SecurityException {
super();
- jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
- jsonBodyReader = new JsonNormalizedNodeBodyReader();
+ this.jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
+ this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
@BeforeClass
public static void initialization() throws Exception {
- Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
@Test
public void rpcModuleInputTest() throws Exception {
final String uri = "invoke-rpc-module:rpc-test";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyWriter.class
.getResourceAsStream("/invoke-rpc/json/rpc-output.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
final OutputStream output = new ByteArrayOutputStream();
- jsonBodyWriter.writeTo(returnValue, null, null, null, mediaType, null,
+ this.jsonBodyWriter.writeTo(returnValue, null, null, null, this.mediaType, null,
output);
assertTrue(output.toString().contains("lf-test"));
}
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.test.util.YangParserTestUtils;
/**
* sal-rest-connector
public TestXmlBodyReader () throws NoSuchFieldException, SecurityException {
super();
- xmlBodyReader = new XmlNormalizedNodeBodyReader();
+ this.xmlBodyReader = new XmlNormalizedNodeBodyReader();
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, false);
+ mockBodyReader(uri, this.xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
final String uri = "instance-identifier-module:cont/cont1";
- mockBodyReader(uri, xmlBodyReader, false);
+ mockBodyReader(uri, this.xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
}
final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockBodyReader(uri, this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
.node(augII).node(contAugmentQName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockBodyReader(uri, this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_augment_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
.node(augChoice1II).node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName)
.node(containerQName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockBodyReader(uri, this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_augment_choice_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
@Test
public void rpcModuleInputTest() throws Exception {
final String uri = "invoke-rpc-module:rpc-test";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockBodyReader(uri, this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "cont"));
*/
@Test
public void findFooContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("", xmlBodyReader, true);
+ mockBodyReader("", this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
// check return value
checkNormalizedNodeContext(returnValue);
*/
@Test
public void findBarContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("", xmlBodyReader, true);
+ mockBodyReader("", this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
// check return value
checkNormalizedNodeContext(returnValue);
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
public TestXmlBodyReaderMountPoint() throws NoSuchFieldException,
SecurityException {
super();
- xmlBodyReader = new XmlNormalizedNodeBodyReader();
+ this.xmlBodyReader = new XmlNormalizedNodeBodyReader();
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, false);
+ mockBodyReader(uri, this.xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
- mockBodyReader(uri, xmlBodyReader, false);
+ mockBodyReader(uri, this.xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
QName.create(dataSchemaNode.getQName(), "cont1"));
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockBodyReader(uri, this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void rpcModuleInputTest() throws Exception {
final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockBodyReader(uri, this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
+ null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "cont"));
.getSchemaContext().getDataChildByName(
dataSchemaNode.getQName());
assertNotNull(mountDataSchemaNode);
- if (qName != null && dataSchemaNode instanceof DataNodeContainer) {
+ if ((qName != null) && (dataSchemaNode instanceof DataNodeContainer)) {
final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
.getDataChildByName(qName);
dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
*/
@Test
public void findFooContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
+ mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
// check return value
checkMountPointNormalizedNodeContext(returnValue);
*/
@Test
public void findBarContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
+ mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = this.xmlBodyReader
+ .readFrom(null, null, null, this.mediaType, null, inputStream);
// check return value
checkMountPointNormalizedNodeContext(returnValue);
import java.io.File;
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.NormalizedNodeXmlBodyWriter;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
super();
- xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
+ this.xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
}
@Override
@BeforeClass
public static void initialization() throws Exception {
- Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
}
final NormalizedNodeContext nnContext = TestRestconfUtils
.loadNormalizedContextFromXmlFile(pathToInputFile, uri);
final OutputStream output = new ByteArrayOutputStream();
- xmlBodyWriter.writeTo(nnContext, null, null, null, mediaType, null,
+ this.xmlBodyWriter.writeTo(nnContext, null, null, null, this.mediaType, null,
output);
assertTrue(output.toString().contains("lf-test"));
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-/**
- *
- */
package org.opendaylight.controller.sal.restconf.impl.test;
import java.lang.reflect.Field;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class RestconfImplNotificationSubscribingTest {
this.broker.setDomDataBroker(this.domDataBroker);
RestconfImpl.getInstance().setBroker(this.broker);
- ControllerContext.getInstance().setGlobalSchema(TestRestconfUtils.loadSchemaContext("/notifications"));
+ ControllerContext.getInstance()
+ .setGlobalSchema(YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications")));
final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-14-12", "localName"));
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;
import java.nio.charset.StandardCharsets;
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;
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.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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
public static SchemaContext loadSchemaContext(final String... yangPath)
throws FileNotFoundException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-
+ final List<InputStream> files = new ArrayList<>();
for (int i = 0; i < yangPath.length; i++) {
final String path = yangPath[i];
final String pathToFile = TestUtils.class.getResource(path).getPath();
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())));
+ files.add(new NamedFileInputStream(file, file.getPath()));
}
}
}
- return reactor.buildEffective();
+ return YangParserTestUtils.parseYangStreams(files);
}
public static Module findModule(final Set<Module> modules, final String moduleName) {
StandardCharsets.UTF_8)));
final byte[] charData = out.toByteArray();
return new String(charData, StandardCharsets.UTF_8);
- } catch (TransformerException e) {
+ } catch (final TransformerException e) {
final String msg = "Error during transformation of Document into String";
LOG.error(msg, e);
return msg;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.opendaylight.netconf.sal.restconf.impl.RestCodec.InstanceIdentifierCodecImpl;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.netconf.sal.restconf.impl.RestCodec.InstanceIdentifierCodecImpl;
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class InstanceIdentifierCodecImplTest {
@Before
public void setUp() throws Exception {
- schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser/deserializer");
- instanceIdentifierDTO = new InstanceIdentifierCodecImpl(null);
- ControllerContext.getInstance().setGlobalSchema(schemaContext);
+ this.schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser/deserializer"));
+ this.instanceIdentifierDTO = new InstanceIdentifierCodecImpl(null);
+ ControllerContext.getInstance().setGlobalSchema(this.schemaContext);
final QName baseQName = QName.create("deserializer:test", "2016-06-06", "deserializer-test");
final QName contA = QName.create(baseQName, "contA");
final QName leafList = QName.create(baseQName, "leaf-list-A");
- instanceIdentifierOKLeafList = YangInstanceIdentifier.builder()
+ this.instanceIdentifierOKLeafList = YangInstanceIdentifier.builder()
.node(contA)
.node(new YangInstanceIdentifier.NodeWithValue<>(leafList, "instance"))
.build();
- instanceIdentifierOKList = YangInstanceIdentifier.builder()
+ this.instanceIdentifierOKList = YangInstanceIdentifier.builder()
.node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
QName.create(baseQName, "list-one-key"),
QName.create(QName.create(baseQName, "list-one-key"), "name"), "value"))
.build();
- instanceIdentifierBadNamespace = YangInstanceIdentifier.builder()
+ this.instanceIdentifierBadNamespace = YangInstanceIdentifier.builder()
.nodeWithKey(QName.create("nonexistent:module", "2016-10-17", "nonexistent-1"),
QName.create("nonexistent:module", "2016-10-17", "nonexistent"),
"value")
@Test
public void testSerializeDeserializeList() throws Exception {
final IdentityValuesDTO valuesDTO =
- instanceIdentifierDTO.serialize(instanceIdentifierOKList);
+ this.instanceIdentifierDTO.serialize(this.instanceIdentifierOKList);
final YangInstanceIdentifier deserializedIdentifier =
- instanceIdentifierDTO.deserialize(valuesDTO);
- assertEquals(instanceIdentifierOKList, deserializedIdentifier);
+ this.instanceIdentifierDTO.deserialize(valuesDTO);
+ assertEquals(this.instanceIdentifierOKList, deserializedIdentifier);
}
@Test
public void testSerializeDeserializeLeafList() throws Exception {
final IdentityValuesDTO valuesDTO =
- instanceIdentifierDTO.serialize(instanceIdentifierOKLeafList);
+ this.instanceIdentifierDTO.serialize(this.instanceIdentifierOKLeafList);
final YangInstanceIdentifier deserializedIdentifier =
- instanceIdentifierDTO.deserialize(valuesDTO);
- assertEquals(instanceIdentifierOKLeafList, deserializedIdentifier);
+ this.instanceIdentifierDTO.deserialize(valuesDTO);
+ assertEquals(this.instanceIdentifierOKLeafList, deserializedIdentifier);
}
@Test
public void testSerializeDeserializeBadModuleNamespace() throws Exception {
final IdentityValuesDTO valuesDTO =
- instanceIdentifierDTO.serialize(instanceIdentifierBadNamespace);
+ this.instanceIdentifierDTO.serialize(this.instanceIdentifierBadNamespace);
assertEquals("nonexistent-1", valuesDTO.getValuesWithNamespaces().get(0).getValue());
assertEquals("nonexistent:module", valuesDTO.getValuesWithNamespaces().get(0).getNamespace());
final YangInstanceIdentifier deserializedIdentifier =
- instanceIdentifierDTO.deserialize(valuesDTO);
+ this.instanceIdentifierDTO.deserialize(valuesDTO);
assertNull(deserializedIdentifier);
}
}
\ No newline at end of file
import org.opendaylight.restconf.handlers.TransactionChainHandler;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class RestconfImplTest {
@Test
public void RestImplTest() throws Exception {
- final SchemaContext schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/impl");
+ final SchemaContext schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/impl"));
final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.CheckedFuture;
import java.net.URI;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.base.services.impl.RestconfOperationsServiceImpl;
import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.handlers.TransactionChainHandler;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class RestconfOperationsServiceTest {
@Before
public void init() throws Exception {
MockitoAnnotations.initMocks(this);
- this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules");
+ this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules"));
final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
+
import com.google.common.collect.ImmutableClassToInstanceMap;
import java.util.HashMap;
import org.junit.Before;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
import org.opendaylight.restconf.base.services.api.RestconfSchemaService;
-import org.opendaylight.restconf.base.services.impl.RestconfSchemaServiceImpl;
import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Unit tests for {@code RestconfSchemaService}
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
- this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules");
- this.schemaContextBehindMountPoint = TestRestconfUtils.loadSchemaContext("/modules/modules-behind-mount-point");
- this.schemaContextWithMountPoints = TestRestconfUtils.loadSchemaContext("/modules/mount-points");
+ this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules"));
+ this.schemaContextBehindMountPoint = YangParserTestUtils
+ .parseYangSources(TestRestconfUtils.loadFiles("/modules/modules-behind-mount-point"));
+ this.schemaContextWithMountPoints =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules/mount-points"));
// create and register mount points
this.mountPoint = SimpleDOMMountPoint.create(
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+
import com.google.common.util.concurrent.CheckedFuture;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Tests for handling {@link SchemaContext}
Mockito.when(checked.checkedGet()).thenReturn(value);
this.schemaContextHandler = new SchemaContextHandler(txHandler);
- this.schemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_ACTUAL_SCHEMA_CONTEXT);
+ this.schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_ACTUAL_SCHEMA_CONTEXT));
this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
}
@Test
public void onGlobalContextUpdateTest() throws Exception {
// create new SchemaContext and update SchemaContextHandler
- final SchemaContext newSchemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT);
+ final SchemaContext newSchemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
this.schemaContextHandler.onGlobalContextUpdated(newSchemaContext);
assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext",
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 org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class JsonBodyReaderTest extends AbstractBodyReaderTest {
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class));
}
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.test.util.YangParserTestUtils;
public class XmlBodyReaderTest extends AbstractBodyReaderTest {
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
- schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ schemaContext = YangParserTestUtils.parseYangSources(testFiles);
controllerContext.setSchemas(schemaContext);
when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class));
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Unit tests for {@link IdentifierCodec} mostly according to examples from draft-ietf-netconf-restconf-13
private static final String URI_WITH_LIST_AND_LEAF =
"list-test:top/list1=%2C%27" + '"' + "%3A" + '"' + "%20%2F,,foo/list2=a,b/result";
- private static final String URI_WITH_LEAF_LIST = "list-test:top/Y=x%3Ay";
private static final String URI_WITH_INT_VAL_LEAF_LIST = "list-test:top/Y=4";
private SchemaContext schemaContext;
@Before
public void init() throws Exception {
- this.schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser");
+ this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser"));
}
/**
@Test
public void codecListAndLeafTest() {
final YangInstanceIdentifier dataYangII = IdentifierCodec.deserialize(
- this.URI_WITH_LIST_AND_LEAF, this.schemaContext);
+ IdentifierCodecTest.URI_WITH_LIST_AND_LEAF, this.schemaContext);
final String serializedDataYangII = IdentifierCodec.serialize(dataYangII, this.schemaContext);
assertEquals("Failed codec deserialization and serialization test",
- this.URI_WITH_LIST_AND_LEAF, serializedDataYangII);
+ IdentifierCodecTest.URI_WITH_LIST_AND_LEAF, serializedDataYangII);
}
/**
@Test
public void codecLeafListTest() {
final YangInstanceIdentifier dataYangII = IdentifierCodec.deserialize(
- this.URI_WITH_INT_VAL_LEAF_LIST, this.schemaContext);
+ IdentifierCodecTest.URI_WITH_INT_VAL_LEAF_LIST, this.schemaContext);
final String serializedDataYangII = IdentifierCodec.serialize(dataYangII, this.schemaContext);
assertEquals("Failed codec deserialization and serialization test",
- this.URI_WITH_INT_VAL_LEAF_LIST, serializedDataYangII);
+ IdentifierCodecTest.URI_WITH_INT_VAL_LEAF_LIST, serializedDataYangII);
}
/**
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import java.util.Iterator;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Unit tests for {@link YangInstanceIdentifierDeserializer}
@Before
public void init() throws Exception {
- this.schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser/deserializer");
+ this.schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser/deserializer"));
}
/**
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Unit tests for {@link YangInstanceIdentifierSerializer}
@Before
public void init() throws Exception {
- schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser/serializer");
+ this.schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser/serializer"));
}
/**
.node(QName.create("serializer:test", "2016-06-06", "contA"))
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful",
"serializer-test:contA", result);
}
.node(QName.create("serializer:test", "2016-06-06", "leaf-A"))
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:contA/leaf-A", result);
}
.node(new NodeWithValue(leafList, "instance"))
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful",
"serializer-test:contA/list-A=100/leaf-list-AA=instance",
result);
.nodeWithKey(QName.create("serializer:test", "2016-06-06", "list-no-key"), Maps.newHashMap())
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:list-no-key", result);
}
QName.create("serializer:test", "2016-06-06", "list-one-key"), "value")
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:list-one-key=value", result);
}
final YangInstanceIdentifier data = YangInstanceIdentifier.builder()
.node(list).nodeWithKey(list, values).build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:list-multiple-keys=value-1,2,true", result);
}
.node(QName.create("serializer:test", "2016-06-06", "leaf-0"))
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:leaf-0", result);
}
.node(new NodeWithValue(QName.create("serializer:test", "2016-06-06", "leaf-list-0"), "instance"))
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:leaf-list-0=instance", result);
}
*/
@Test
public void serializeNullSchemaContextNegativeTest() {
- thrown.expect(NullPointerException.class);
+ this.thrown.expect(NullPointerException.class);
YangInstanceIdentifierSerializer.create(null, YangInstanceIdentifier.EMPTY);
}
*/
@Test
public void serializeNullDataNegativeTest() {
- thrown.expect(NullPointerException.class);
- YangInstanceIdentifierSerializer.create(schemaContext, null);
+ this.thrown.expect(NullPointerException.class);
+ YangInstanceIdentifierSerializer.create(this.schemaContext, null);
}
/**
*/
@Test
public void serializeEmptyDataTest() {
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, YangInstanceIdentifier.EMPTY);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, YangInstanceIdentifier.EMPTY);
assertTrue("Empty identifier is expected", result.isEmpty());
}
.node(QName.create("serializer:test", "2016-06-06", "not-existing-leaf"))
.build();
- thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierSerializer.create(schemaContext, data);
+ this.thrown.expect(IllegalArgumentException.class);
+ YangInstanceIdentifierSerializer.create(this.schemaContext, data);
}
/**
QName.create("serializer:test", "2016-06-06", "list-one-key"), value)
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:list-one-key=" + encoded, result);
}
QName.create("serializer:test", "2016-06-06", "list-one-key"), value)
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful", "serializer-test:list-one-key=" + value, result);
}
.node(child)
.build();
- final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
+ final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data);
assertEquals("Serialization not successful",
"serializer-test-included:augmented-list=100/serializer-test:augmented-leaf", result);
.node(child)
.build();
- thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierSerializer.create(schemaContext, data);
+ this.thrown.expect(IllegalArgumentException.class);
+ YangInstanceIdentifierSerializer.create(this.schemaContext, data);
}
}
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class RestconfDataServiceImplTest {
.node(this.baseQName)
.build();
- this.contextRef = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ this.contextRef = new SchemaContextRef(
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
this.schemaNode = DataSchemaContextTree.from(this.contextRef.get()).getChild(this.iidBase).getDataSchemaNode();
final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class RestconfInvokeOperationsServiceImplTest {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
- final SchemaContextRef contextRef = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ final SchemaContextRef contextRef = new SchemaContextRef(
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
Mockito.when(txHandler.get()).thenReturn(domTx);
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.lang.reflect.Field;
import org.opendaylight.restconf.parser.IdentifierCodec;
import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class RestconfStreamsSubscriptionServiceImplTest {
final Set<Entry<String, List<String>>> set = new HashSet<>();
Mockito.when(map.entrySet()).thenReturn(set);
Mockito.when(this.uriInfo.getQueryParameters()).thenReturn(map);
- this.schemaHandler.onGlobalContextUpdated(TestRestconfUtils.loadSchemaContext("/notifications"));
+ this.schemaHandler.onGlobalContextUpdated(
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications")));
}
@BeforeClass
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+
import java.util.Collections;
import java.util.Set;
import org.junit.Before;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class CreateStreamUtilTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- this.refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ this.refSchemaCtx = new SchemaContextRef(
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
}
@Test
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class PatchDataTransactionUtilTest {
PatchDataTransactionUtilTest.broker.setAccessible(true);
PatchDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
- refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ this.refSchemaCtx = new SchemaContextRef(
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
final QName containerPlayerQName = QName.create(baseQName, "player");
final QName leafGapQName = QName.create(baseQName, "gap");
new YangInstanceIdentifier.NodeIdentifierWithPredicates(listArtistQName, leafNameQName, "name of artist");
/** instance identifier for accessing leaf node "gap" */
- iIDCreateAndDelete = YangInstanceIdentifier.builder()
+ this.iIDCreateAndDelete = YangInstanceIdentifier.builder()
.node(baseQName)
.node(containerPlayerQName)
.node(leafGapQName)
.withChild(buildGapLeaf)
.build();
- buildBaseContainerForTests = Builders.containerBuilder()
+ this.buildBaseContainerForTests = Builders.containerBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(baseQName))
.withChild(buildPlayerContainer)
.build();
- targetNodeForCreateAndDelete = YangInstanceIdentifier.builder(iIDCreateAndDelete)
+ this.targetNodeForCreateAndDelete = YangInstanceIdentifier.builder(this.iIDCreateAndDelete)
.node(containerPlayerQName)
.node(leafGapQName)
.build();
/** instance identifier for accessing leaf node "name" in list "artist" */
- iIDMerge = YangInstanceIdentifier.builder()
+ this.iIDMerge = YangInstanceIdentifier.builder()
.node(baseQName)
.node(containerLibraryQName)
.node(listArtistQName)
.withChild(contentDescription)
.build();
- buildArtistList = Builders.mapBuilder()
+ this.buildArtistList = Builders.mapBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listArtistQName))
.withChild(mapEntryNode)
.build();
- targetNodeMerge = YangInstanceIdentifier.builder()
+ this.targetNodeMerge = YangInstanceIdentifier.builder()
.node(baseQName)
.node(containerLibraryQName)
.node(listArtistQName)
.build();
/** Mocks */
- doReturn(rWTransaction).when(transactionChain).newReadWriteTransaction();
- doReturn(Futures.immediateCheckedFuture(null)).when(rWTransaction).submit();
+ doReturn(this.rWTransaction).when(this.transactionChain).newReadWriteTransaction();
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.rWTransaction).submit();
}
@Test
public void testPatchDataReplaceMergeAndRemove() {
doReturn(Futures.immediateCheckedFuture(false)).doReturn(Futures.immediateCheckedFuture(true))
- .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeMerge);
+ .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeMerge);
- final PATCHEntity entityReplace = new PATCHEntity("edit1", "REPLACE", targetNodeMerge, buildArtistList);
- final PATCHEntity entityMerge = new PATCHEntity("edit2", "MERGE", targetNodeMerge, buildArtistList);
- final PATCHEntity entityRemove = new PATCHEntity("edit3", "REMOVE", targetNodeMerge);
+ final PATCHEntity entityReplace = new PATCHEntity("edit1", "REPLACE", this.targetNodeMerge, this.buildArtistList);
+ final PATCHEntity entityMerge = new PATCHEntity("edit2", "MERGE", this.targetNodeMerge, this.buildArtistList);
+ final PATCHEntity entityRemove = new PATCHEntity("edit3", "REMOVE", this.targetNodeMerge);
final List<PATCHEntity> entities = new ArrayList<>();
entities.add(entityReplace);
entities.add(entityRemove);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
- new InstanceIdentifierContext<>(iIDMerge, null, null, refSchemaCtx.get());
+ new InstanceIdentifierContext<>(this.iIDMerge, null, null, this.refSchemaCtx.get());
final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchRMRm");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
final PATCHStatusContext patchStatusContext =
- PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx);
+ PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
- for (PATCHStatusEntity entity : patchStatusContext.getEditCollection()) {
+ for (final PATCHStatusEntity entity : patchStatusContext.getEditCollection()) {
assertTrue(entity.isOk());
}
assertTrue(patchStatusContext.isOk());
@Test
public void testPatchDataCreateAndDelete() throws Exception {
doReturn(Futures.immediateCheckedFuture(false)).doReturn(Futures.immediateCheckedFuture(true))
- .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeForCreateAndDelete);
+ .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete);
final PATCHEntity entityCreate =
- new PATCHEntity("edit1", "CREATE", targetNodeForCreateAndDelete, buildBaseContainerForTests);
+ new PATCHEntity("edit1", "CREATE", this.targetNodeForCreateAndDelete, this.buildBaseContainerForTests);
final PATCHEntity entityDelete =
- new PATCHEntity("edit2", "DELETE", targetNodeForCreateAndDelete);
+ new PATCHEntity("edit2", "DELETE", this.targetNodeForCreateAndDelete);
final List<PATCHEntity> entities = new ArrayList<>();
entities.add(entityCreate);
entities.add(entityDelete);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
- new InstanceIdentifierContext<>(iIDCreateAndDelete, null, null, refSchemaCtx.get());
+ new InstanceIdentifierContext<>(this.iIDCreateAndDelete, null, null, this.refSchemaCtx.get());
final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchCD");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain);
- final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
- for (PATCHStatusEntity entity : patchStatusContext.getEditCollection()) {
+ for (final PATCHStatusEntity entity : patchStatusContext.getEditCollection()) {
assertTrue(entity.isOk());
}
assertTrue(patchStatusContext.isOk());
@Test
public void deleteNonexistentDataTest() {
doReturn(Futures.immediateCheckedFuture(false))
- .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeForCreateAndDelete);
+ .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete);
final PATCHEntity entityDelete =
- new PATCHEntity("edit", "DELETE", targetNodeForCreateAndDelete);
+ new PATCHEntity("edit", "DELETE", this.targetNodeForCreateAndDelete);
final List<PATCHEntity> entities = new ArrayList<>();
entities.add(entityDelete);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
- new InstanceIdentifierContext<>(iIDCreateAndDelete, null, null, refSchemaCtx.get());
+ new InstanceIdentifierContext<>(this.iIDCreateAndDelete, null, null, this.refSchemaCtx.get());
final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchD");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain);
- final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
assertFalse(patchStatusContext.isOk());
assertEquals(RestconfError.ErrorType.PROTOCOL,
@Test
public void testPatchMergePutContainer() throws Exception {
doReturn(Futures.immediateCheckedFuture(false)).doReturn(Futures.immediateCheckedFuture(true))
- .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeForCreateAndDelete);
+ .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete);
final PATCHEntity entityMerge =
- new PATCHEntity("edit1", "MERGE", targetNodeForCreateAndDelete, buildBaseContainerForTests);
+ new PATCHEntity("edit1", "MERGE", this.targetNodeForCreateAndDelete, this.buildBaseContainerForTests);
final List<PATCHEntity> entities = new ArrayList<>();
entities.add(entityMerge);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
- new InstanceIdentifierContext<>(iIDCreateAndDelete, null, null, refSchemaCtx.get());
+ new InstanceIdentifierContext<>(this.iIDCreateAndDelete, null, null, this.refSchemaCtx.get());
final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchM");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain);
- final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
- for (PATCHStatusEntity entity : patchStatusContext.getEditCollection()) {
+ for (final PATCHStatusEntity entity : patchStatusContext.getEditCollection()) {
assertTrue(entity.isOk());
}
assertTrue(patchStatusContext.isOk());
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
+
import com.google.common.util.concurrent.Futures;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.DOMException;
public class PostDataTransactionUtilTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- this.refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ this.refSchemaCtx = new SchemaContextRef(
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
this.schema = this.refSchemaCtx.get();
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.Futures;
import org.junit.Before;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class PutDataTransactionUtilTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- this.refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ this.refSchemaCtx = new SchemaContextRef(
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
this.schema = this.refSchemaCtx.get();
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
+
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Unit tests for {@link RestconfMappingNodeUtil}
@BeforeClass
public static void loadTestSchemaContextAndModules() throws Exception {
- schemaContext = TestRestconfUtils.loadSchemaContext(
- "/modules/restconf-module-testing");
- schemaContextMonitoring = TestRestconfUtils.loadSchemaContext("/modules");
+ schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules/restconf-module-testing"));
+ schemaContextMonitoring = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules"));
modules = schemaContextMonitoring.getModules();
- modulesRest = TestRestconfUtils.loadSchemaContext("/modules/restconf-module-testing").getModules();
+ modulesRest = YangParserTestUtils
+ .parseYangSources(TestRestconfUtils.loadFiles("/modules/restconf-module-testing")).getModules();
}
@Before
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Unit test for {@link ParserFieldsParameter}
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- final SchemaContext schemaContext = TestRestconfUtils.loadSchemaContext("/jukebox");
+ final SchemaContext schemaContext =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/jukebox"));
final QNameModule qNameModule = QNameModule.create(URI.create("http://example.com/ns/example-jukebox"),
new SimpleDateFormat("yyyy-MM-dd").parse("2015-04-04"));
- jukeboxQName = QName.create(qNameModule, "jukebox");
- playerQName = QName.create(qNameModule, "player");
- libraryQName = QName.create(qNameModule, "library");
- augmentedLibraryQName = QName.create(
+ this.jukeboxQName = QName.create(qNameModule, "jukebox");
+ this.playerQName = QName.create(qNameModule, "player");
+ this.libraryQName = QName.create(qNameModule, "library");
+ this.augmentedLibraryQName = QName.create(
QNameModule.create(
URI.create("http://example.com/ns/augmented-jukebox"),
new SimpleDateFormat("yyyy-MM-dd").parse("2016-05-05")),
"augmented-library");
- albumQName = QName.create(qNameModule, "album");
- nameQName = QName.create(qNameModule, "name");
+ this.albumQName = QName.create(qNameModule, "album");
+ this.nameQName = QName.create(qNameModule, "name");
- Mockito.when(identifierContext.getSchemaContext()).thenReturn(schemaContext);
- Mockito.when(containerJukebox.getQName()).thenReturn(jukeboxQName);
- Mockito.when(identifierContext.getSchemaNode()).thenReturn(containerJukebox);
+ Mockito.when(this.identifierContext.getSchemaContext()).thenReturn(schemaContext);
+ Mockito.when(this.containerJukebox.getQName()).thenReturn(this.jukeboxQName);
+ Mockito.when(this.identifierContext.getSchemaNode()).thenReturn(this.containerJukebox);
- Mockito.when(containerLibrary.getQName()).thenReturn(libraryQName);
- Mockito.when(containerJukebox.getDataChildByName(libraryQName)).thenReturn(containerLibrary);
+ Mockito.when(this.containerLibrary.getQName()).thenReturn(this.libraryQName);
+ Mockito.when(this.containerJukebox.getDataChildByName(this.libraryQName)).thenReturn(this.containerLibrary);
- Mockito.when(augmentedContainerLibrary.getQName()).thenReturn(augmentedLibraryQName);
- Mockito.when(containerJukebox.getDataChildByName(augmentedLibraryQName)).thenReturn(augmentedContainerLibrary);
+ Mockito.when(this.augmentedContainerLibrary.getQName()).thenReturn(this.augmentedLibraryQName);
+ Mockito.when(this.containerJukebox.getDataChildByName(this.augmentedLibraryQName)).thenReturn(this.augmentedContainerLibrary);
- Mockito.when(containerPlayer.getQName()).thenReturn(playerQName);
- Mockito.when(containerJukebox.getDataChildByName(playerQName)).thenReturn(containerPlayer);
+ Mockito.when(this.containerPlayer.getQName()).thenReturn(this.playerQName);
+ Mockito.when(this.containerJukebox.getDataChildByName(this.playerQName)).thenReturn(this.containerPlayer);
- Mockito.when(listAlbum.getQName()).thenReturn(albumQName);
- Mockito.when(containerLibrary.getDataChildByName(albumQName)).thenReturn(listAlbum);
+ Mockito.when(this.listAlbum.getQName()).thenReturn(this.albumQName);
+ Mockito.when(this.containerLibrary.getDataChildByName(this.albumQName)).thenReturn(this.listAlbum);
- Mockito.when(leafName.getQName()).thenReturn(nameQName);
- Mockito.when(listAlbum.getDataChildByName(nameQName)).thenReturn(leafName);
+ Mockito.when(this.leafName.getQName()).thenReturn(this.nameQName);
+ Mockito.when(this.listAlbum.getDataChildByName(this.nameQName)).thenReturn(this.leafName);
}
/**
@Test
public void parseFieldsParameterSimplePathTest() {
final String input = "library";
- final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
assertNotNull(parsedFields);
assertEquals(1, parsedFields.size());
assertEquals(1, parsedFields.get(0).size());
- assertTrue(parsedFields.get(0).contains(libraryQName));
+ assertTrue(parsedFields.get(0).contains(this.libraryQName));
}
/**
@Test
public void parseFieldsParameterDoublePathTest() {
final String input = "library;player";
- final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
assertNotNull(parsedFields);
assertEquals(1, parsedFields.size());
assertEquals(2, parsedFields.get(0).size());
- assertTrue(parsedFields.get(0).contains(libraryQName));
- assertTrue(parsedFields.get(0).contains(playerQName));
+ assertTrue(parsedFields.get(0).contains(this.libraryQName));
+ assertTrue(parsedFields.get(0).contains(this.playerQName));
}
/**
@Test
public void parseFieldsParameterSubPathTest() {
final String input = "library/album/name";
- final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
assertNotNull(parsedFields);
assertEquals(3, parsedFields.size());
assertEquals(1, parsedFields.get(0).size());
- assertTrue(parsedFields.get(0).contains(libraryQName));
+ assertTrue(parsedFields.get(0).contains(this.libraryQName));
assertEquals(1, parsedFields.get(1).size());
- assertTrue(parsedFields.get(1).contains(albumQName));
+ assertTrue(parsedFields.get(1).contains(this.albumQName));
assertEquals(1, parsedFields.get(2).size());
- assertTrue(parsedFields.get(2).contains(nameQName));
+ assertTrue(parsedFields.get(2).contains(this.nameQName));
}
/**
@Test
public void parseFieldsParameterChildrenPathTest() {
final String input = "library(album(name))";
- final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
assertNotNull(parsedFields);
assertEquals(3, parsedFields.size());
assertEquals(1, parsedFields.get(0).size());
- assertTrue(parsedFields.get(0).contains(libraryQName));
+ assertTrue(parsedFields.get(0).contains(this.libraryQName));
assertEquals(1, parsedFields.get(1).size());
- assertTrue(parsedFields.get(1).contains(albumQName));
+ assertTrue(parsedFields.get(1).contains(this.albumQName));
assertEquals(1, parsedFields.get(2).size());
- assertTrue(parsedFields.get(2).contains(nameQName));
+ assertTrue(parsedFields.get(2).contains(this.nameQName));
}
/**
@Test
public void parseFieldsParameterNamespaceTest() {
final String input = "augmented-jukebox:augmented-library";
- final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
assertNotNull(parsedFields);
assertEquals(1, parsedFields.size());
assertEquals(1, parsedFields.get(0).size());
- assertTrue(parsedFields.get(0).contains(augmentedLibraryQName));
+ assertTrue(parsedFields.get(0).contains(this.augmentedLibraryQName));
}
/**
final String input = "*";
try {
- ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
fail("Test should fail due to not expected character used in parameter input value");
} catch (final RestconfDocumentedException e) {
// Bad request
final String input = "library(";
try {
- ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
fail("Test should fail due to missing closing parenthesis");
} catch (final RestconfDocumentedException e) {
// Bad request
final String input = "library(not-existing)";
try {
- ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
fail("Test should fail due to missing child node in parent node");
} catch (final RestconfDocumentedException e) {
// Bad request
final String input = "library(album);";
try {
- ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
fail("Test should fail due to unexpected character after parenthesis");
} catch (final RestconfDocumentedException e) {
// Bad request
final String input = "library(album)player";
try {
- ParserFieldsParameter.parseFieldsParameter(identifierContext, input);
+ ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input);
fail("Test should fail due to missing semicolon after parenthesis");
} catch (final RestconfDocumentedException e) {
// Bad request
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Unit tests for {@link ParserIdentifier}
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
- schemaContext = TestRestconfUtils.loadSchemaContext("/parser-identifier");
- schemaContextOnMountPoint = TestRestconfUtils.loadSchemaContext("/parser-identifier");
+ this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
+ this.schemaContextOnMountPoint =
+ YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
// create and register mount point
- mountPoint = SimpleDOMMountPoint.create(
+ this.mountPoint = SimpleDOMMountPoint.create(
YangInstanceIdentifier.builder()
.node(QName.create("mount:point", "2016-06-02", "mount-container"))
.node(QName.create("mount:point", "2016-06-02", "point-number"))
.build(),
ImmutableClassToInstanceMap.copyOf(Maps.newHashMap()),
- schemaContextOnMountPoint
+ this.schemaContextOnMountPoint
);
- mountPointService = new DOMMountPointServiceImpl();
- ((DOMMountPointServiceImpl) mountPointService).registerMountPoint(mountPoint);
+ this.mountPointService = new DOMMountPointServiceImpl();
+ ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
// register mount point with null schema context
- when(mockMountPoint.getSchemaContext()).thenReturn(null);
- when(mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.of(mockMountPoint));
+ when(this.mockMountPoint.getSchemaContext()).thenReturn(null);
+ when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.of(this.mockMountPoint));
}
/**
@Test
public void toInstanceIdentifierTest() {
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- TEST_IDENT, schemaContext, Optional.absent());
+ TEST_IDENT, this.schemaContext, Optional.absent());
assertEquals("Returned not expected identifier",
TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
@Test
public void toInstanceIdentifierOtherModulesTest() {
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- TEST_IDENT_OTHERS, schemaContext, Optional.absent());
+ TEST_IDENT_OTHERS, this.schemaContext, Optional.absent());
assertEquals("Returned not expected identifier",
TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
@Test
public void toInstanceIdentifierMountPointTest() {
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- MOUNT_POINT_IDENT + "/" + TEST_IDENT, schemaContext, Optional.of(mountPointService));
+ MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService));
assertEquals("Returned not expected identifier",
TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
assertEquals("Mount point not found",
- mountPoint, context.getMountPoint());
+ this.mountPoint, context.getMountPoint());
assertEquals("Schema context from mount point expected",
- schemaContextOnMountPoint, context.getSchemaContext());
+ this.schemaContextOnMountPoint, context.getSchemaContext());
}
/**
@Test
public void toInstanceIdentifierNullIdentifierTest() {
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- null, schemaContext, Optional.absent());
+ null, this.schemaContext, Optional.absent());
assertEquals("Returned not expected identifier",
YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
}
*/
@Test
public void toInstanceIdentifierNullSchemaContextNegativeTest() {
- thrown.expect(NullPointerException.class);
+ this.thrown.expect(NullPointerException.class);
ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.absent());
}
@Test
public void toInstanceIdentifierEmptyIdentifierTest() {
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- "", schemaContext, Optional.absent());
+ "", this.schemaContext, Optional.absent());
assertEquals("Returned not expected identifier",
YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
}
*/
@Test
public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
- thrown.expect(IllegalArgumentException.class);
- ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, schemaContext, Optional.absent());
+ this.thrown.expect(IllegalArgumentException.class);
+ ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.absent());
}
/**
*/
@Test
public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
- thrown.expect(IllegalArgumentException.class);
- ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, schemaContext, Optional.of(mountPointService));
+ this.thrown.expect(IllegalArgumentException.class);
+ ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
}
/**
public void toInstanceIdentifierMissingMountPointNegativeTest() {
try {
ParserIdentifier.toInstanceIdentifier(
- "" + "/" + RestconfConstants.MOUNT, schemaContext, Optional.of(mountPointService));
+ "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService));
fail("Test should fail due to missing mount point");
} catch (final RestconfDocumentedException e) {
assertEquals("Not expected error type",
@Test
public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
try {
- ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, schemaContext, Optional.absent());
+ ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.absent());
fail("Test should fail due to absent mount point service");
} catch (final RestconfDocumentedException e) {
assertEquals("Not expected error type",
*/
@Test
public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
- thrown.expect(NullPointerException.class);
+ this.thrown.expect(NullPointerException.class);
ParserIdentifier.makeQNameFromIdentifier(null);
}
@Test
public void toSchemaExportContextFromIdentifierTest() {
final SchemaExportContext exportContext = ParserIdentifier.
- toSchemaExportContextFromIdentifier(schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
+ toSchemaExportContextFromIdentifier(this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
assertNotNull("Export context should be parsed", exportContext);
@Test
public void toSchemaExportContextFromIdentifierNotFoundTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext,
+ this.schemaContext,
"not-existing-module" + "/" + "2016-01-01",
null);
public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
try {
ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null);
+ this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null);
fail("Test should fail due to invalid identifier supplied");
} catch (final RestconfDocumentedException e) {
assertEquals("Not expected error type",
@Test
public void toSchemaExportContextFromIdentifierMountPointTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext,
+ this.schemaContext,
MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
- mountPointService);
+ this.mountPointService);
final Module module = exportContext.getModule();
assertNotNull("Export context should contains test module", module);
@Test
public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext,
+ this.schemaContext,
MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
- mountPointService);
+ this.mountPointService);
assertNotNull("Export context should be parsed", exportContext);
assertNull("Not-existing module should be null", exportContext.getModule());
public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
try {
ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext,
+ this.schemaContext,
MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
- mountPointService);
+ this.mountPointService);
fail("Test should fail due to invalid identifier supplied");
} catch (final RestconfDocumentedException e) {
*/
@Test
public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
- thrown.expect(NullPointerException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContext, null, null);
+ this.thrown.expect(NullPointerException.class);
+ ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null);
}
/**
*/
@Test
public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
- thrown.expect(NullPointerException.class);
+ this.thrown.expect(NullPointerException.class);
ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
}
*/
@Test
public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
- thrown.expect(NullPointerException.class);
+ this.thrown.expect(NullPointerException.class);
ParserIdentifier.toSchemaExportContextFromIdentifier(
null,
MOUNT_POINT_IDENT
+ TEST_MODULE_NAME
+ "/"
+ TEST_MODULE_REVISION,
- mountPointService);
+ this.mountPointService);
}
/**
*/
@Test
public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
- thrown.expect(NullPointerException.class);
+ this.thrown.expect(NullPointerException.class);
ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext,
+ this.schemaContext,
MOUNT_POINT_IDENT
+ "/"
+ TEST_MODULE_NAME
*/
@Test
public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
- thrown.expect(NullPointerException.class);
+ this.thrown.expect(NullPointerException.class);
ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext,
+ this.schemaContext,
"/"
+ RestconfConstants.MOUNT
+ "/"
+ TEST_MODULE_NAME
+ "/"
+ TEST_MODULE_REVISION,
- mockMountPointService);
+ this.mockMountPointService);
}
}
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-parser-api</artifactId>
</dependency>
-
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-parser-impl</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-test-util</artifactId>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
+import java.util.List;
import java.util.Set;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
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.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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class DocGenTestHelper {
private SchemaContext schemaContext;
public Set<Module> loadModules(final String resourceDirectory)
- throws FileNotFoundException,
- URISyntaxException, ReactorException {
+ throws URISyntaxException, FileNotFoundException, ReactorException {
final URI resourceDirUri = getClass().getResource(resourceDirectory).toURI();
final File testDir = new File(resourceDirUri);
if (fileList == null) {
throw new FileNotFoundException(resourceDirectory.toString());
}
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ final List<File> files = new ArrayList<>();
for (final String fileName : fileList) {
- final File file = new File(testDir, fileName);
- reactor.addSource(new YangStatementSourceImpl(new NamedFileInputStream(file, file.getPath())));
+ files.add(new File(testDir, fileName));
}
- this.schemaContext = reactor.buildEffective();
+ this.schemaContext = YangParserTestUtils.parseYangSources(files);
return this.schemaContext.getModules();
}