Search in sources :

Example 1 with CurrentSchemaContext

use of org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext in project netconf by opendaylight.

the class AbstractNetconfOperationTest method setUp.

@Before
public void setUp() {
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    final DOMSchemaService schemaService = new SchemaServiceStub(SCHEMA_CONTEXT);
    final DOMStore operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", schemaService);
    final DOMStore configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", schemaService);
    currentSchemaContext = new CurrentSchemaContext(schemaService, sourceIdentifier -> {
        final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.delegateForByteSource(sourceIdentifier, ByteSource.wrap("module test".getBytes()));
        return Futures.immediateFuture(yangTextSchemaSource);
    });
    final EnumMap<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
    datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
    datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
    final ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(16, 16, "CommitFutures", CopyConfigTest.class);
    final SerializedDOMDataBroker sdb = new SerializedDOMDataBroker(datastores, MoreExecutors.listeningDecorator(listenableFutureExecutor));
    this.transactionProvider = new TransactionProvider(sdb, SESSION_ID_FOR_REPORTING);
}
Also used : YangParserTestUtils.parseYangResources(org.opendaylight.yangtools.yang.test.util.YangParserTestUtils.parseYangResources) Transformer(javax.xml.transform.Transformer) XMLUnit(org.custommonkey.xmlunit.XMLUnit) StreamResult(javax.xml.transform.stream.StreamResult) LoggerFactory(org.slf4j.LoggerFactory) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) GetConfig(org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig) SpecialExecutors(org.opendaylight.yangtools.util.concurrent.SpecialExecutors) Document(org.w3c.dom.Document) Assert.fail(org.junit.Assert.fail) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) NetconfOperation(org.opendaylight.netconf.mapping.api.NetconfOperation) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) XmlUtil(org.opendaylight.netconf.api.xml.XmlUtil) AfterClass(org.junit.AfterClass) XmlFileLoader(org.opendaylight.netconf.util.test.XmlFileLoader) EnumMap(java.util.EnumMap) Get(org.opendaylight.netconf.mdsal.connector.ops.get.Get) Assert.assertFalse(org.junit.Assert.assertFalse) SAXException(org.xml.sax.SAXException) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) InMemoryDOMDataStoreFactory(org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStoreFactory) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) DOMSource(javax.xml.transform.dom.DOMSource) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) TransactionProvider(org.opendaylight.netconf.mdsal.connector.TransactionProvider) NetconfOperationChainedExecution(org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution) NetconfXmlUnitRecursiveQualifier(org.opendaylight.netconf.util.test.NetconfXmlUnitRecursiveQualifier) Node(org.w3c.dom.Node) ByteSource(com.google.common.io.ByteSource) SerializedDOMDataBroker(org.opendaylight.mdsal.dom.broker.SerializedDOMDataBroker) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) StringWriter(java.io.StringWriter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) OutputKeys(javax.xml.transform.OutputKeys) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Futures(com.google.common.util.concurrent.Futures) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) TransformerFactory(javax.xml.transform.TransformerFactory) Assert.assertEquals(org.junit.Assert.assertEquals) Diff(org.custommonkey.xmlunit.Diff) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) TransactionProvider(org.opendaylight.netconf.mdsal.connector.TransactionProvider) ExecutorService(java.util.concurrent.ExecutorService) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) EnumMap(java.util.EnumMap) SerializedDOMDataBroker(org.opendaylight.mdsal.dom.broker.SerializedDOMDataBroker) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) Before(org.junit.Before)

Example 2 with CurrentSchemaContext

use of org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext in project netconf by opendaylight.

the class Netconf506Test method testValidateTypes.

@Test
public void testValidateTypes() throws Exception {
    final SchemaContext context = YangParserTestUtils.parseYangResources(Bug8084.class, "/yang/filter-validator-test-mod-0.yang", "/yang/mdsal-netconf-mapping-test.yang");
    final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
    doReturn(context).when(currentContext).getCurrentContext();
    final FilterContentValidator validator = new FilterContentValidator(currentContext);
    final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class.getResourceAsStream("/filter/netconf506.xml"));
    final XmlElement xmlElement = XmlElement.fromDomDocument(document);
    final YangInstanceIdentifier actual = validator.validate(xmlElement);
    final Map<QName, Object> inputs = new HashMap<>();
    inputs.put(QName.create(BASE, "name"), "foo");
    final YangInstanceIdentifier expected = YangInstanceIdentifier.builder().node(BASE).node(QName.create(BASE, "leafref-key-list")).nodeWithKey(QName.create(BASE, "leafref-key-list"), inputs).build();
    assertEquals(expected, actual);
}
Also used : HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) Document(org.w3c.dom.Document) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 3 with CurrentSchemaContext

use of org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext in project netconf by opendaylight.

the class Bug8084 method testValidateTypes.

@Test
public void testValidateTypes() throws Exception {
    final SchemaContext context = YangParserTestUtils.parseYangResources(Bug8084.class, "/yang/filter-validator-test-mod-0.yang", "/yang/filter-validator-test-augment.yang", "/yang/mdsal-netconf-mapping-test.yang");
    final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
    doReturn(context).when(currentContext).getCurrentContext();
    final FilterContentValidator validator = new FilterContentValidator(currentContext);
    final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class.getResourceAsStream("/filter/bug8084.xml"));
    final XmlElement xmlElement = XmlElement.fromDomDocument(document);
    final YangInstanceIdentifier actual = validator.validate(xmlElement);
    final Map<QName, Object> inputs = new HashMap<>();
    inputs.put(QName.create(BASE, "id1"), "aaa");
    inputs.put(QName.create(BASE, "id2"), Byte.valueOf("-9"));
    inputs.put(QName.create(BASE, "id3"), Short.valueOf("-30000"));
    inputs.put(QName.create(BASE, "id4"), Integer.valueOf("-2000000000"));
    inputs.put(QName.create(BASE, "id5"), Long.valueOf("-2000000000000000"));
    inputs.put(QName.create(BASE, "id6"), Short.valueOf("9"));
    inputs.put(QName.create(BASE, "id7"), Integer.valueOf("30000"));
    inputs.put(QName.create(BASE, "id8"), Long.valueOf("2000000000"));
    inputs.put(QName.create(BASE, "id9"), BigInteger.valueOf(Long.valueOf("2000000000000000")));
    inputs.put(QName.create(BASE, "id10"), true);
    inputs.put(QName.create(BASE, "id11"), BigDecimal.valueOf(128.55));
    inputs.put(QName.create(BASE, "id12"), QName.create(BASE, "foo"));
    inputs.put(QName.create(BASE, "id13"), QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "foo"));
    final QName idActual = (QName) ((NodeIdentifierWithPredicates) actual.getLastPathArgument()).getValue(QName.create(BASE, "id12"));
    final YangInstanceIdentifier expected = YangInstanceIdentifier.builder().node(BASE).node(QName.create(BASE, "multi-key-list2")).nodeWithKey(QName.create(BASE, "multi-key-list2"), inputs).build();
    final QName idExpected = (QName) ((NodeIdentifierWithPredicates) expected.getLastPathArgument()).getValue(QName.create(BASE, "id12"));
    assertEquals(idExpected, idActual);
    assertEquals(expected, actual);
}
Also used : HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) Document(org.w3c.dom.Document) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 4 with CurrentSchemaContext

use of org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext in project netconf by opendaylight.

the class FilterContentValidatorTest method setUp.

@Before
public void setUp() throws Exception {
    final SchemaContext context = YangParserTestUtils.parseYangResources(FilterContentValidatorTest.class, "/yang/filter-validator-test-mod-0.yang", "/yang/filter-validator-test-augment.yang", "/yang/mdsal-netconf-mapping-test.yang");
    final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
    doReturn(context).when(currentContext).getCurrentContext();
    validator = new FilterContentValidator(currentContext);
}
Also used : SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) Before(org.junit.Before)

Example 5 with CurrentSchemaContext

use of org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext in project netconf by opendaylight.

the class Netconf538Test method transformNormalizedNodeTest_mapNodeTest.

@Test
public void transformNormalizedNodeTest_mapNodeTest() throws Exception {
    final SchemaContext context = YangParserTestUtils.parseYangResources(Netconf538Test.class, "/yang/simple-list.yang");
    final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
    doReturn(context).when(currentContext).getCurrentContext();
    final GetConfig getConfig = new GetConfig(SESSION_ID_FOR_REPORTING, currentContext, transactionProvider);
    final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class.getResourceAsStream("/filter/netconf538.xml"));
    LeafNode<String> leafNode = Builders.<String>leafBuilder().withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(NAME_QNAME)).withValue(LEAF_VALUE).build();
    MapEntryNode mapEntryNode = Builders.mapEntryBuilder().withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(BASE, NAME_QNAME, LEAF_VALUE)).withChild(leafNode).build();
    MapNode data = Builders.mapBuilder().withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(BASE)).withChild(mapEntryNode).build();
    final YangInstanceIdentifier path = YangInstanceIdentifier.builder().build();
    final Node node = getConfig.transformNormalizedNode(document, data, path);
    Assert.assertNotNull(node);
    Node nodeUser = node.getFirstChild();
    Assert.assertEquals(data.getIdentifier().getNodeType().getLocalName(), nodeUser.getLocalName());
    Node nodeName = nodeUser.getFirstChild();
    Assert.assertEquals(leafNode.getIdentifier().getNodeType().getLocalName(), nodeName.getLocalName());
    Assert.assertEquals(leafNode.body(), nodeName.getFirstChild().getNodeValue());
}
Also used : LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) Node(org.w3c.dom.Node) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) Document(org.w3c.dom.Document) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

CurrentSchemaContext (org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext)6 Document (org.w3c.dom.Document)4 Before (org.junit.Before)3 Test (org.junit.Test)3 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)3 HashMap (java.util.HashMap)2 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 ByteSource (com.google.common.io.ByteSource)1 Futures (com.google.common.util.concurrent.Futures)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 EnumMap (java.util.EnumMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 OutputKeys (javax.xml.transform.OutputKeys)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1