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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations