2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.mdsal.connector.ops.get;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
14 import java.math.BigDecimal;
15 import java.math.BigInteger;
16 import java.util.HashMap;
18 import org.junit.Test;
19 import org.opendaylight.netconf.api.xml.XmlElement;
20 import org.opendaylight.netconf.api.xml.XmlUtil;
21 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27 import org.w3c.dom.Document;
29 public class Bug8084 {
31 private static final QName BASE = QName.create("urn:dummy:mod-0", "2016-03-01", "mainroot");
34 public void testValidateTypes() throws Exception {
35 final SchemaContext context = YangParserTestUtils.parseYangResources(Bug8084.class,
36 "/yang/filter-validator-test-mod-0.yang", "/yang/filter-validator-test-augment.yang",
37 "/yang/mdsal-netconf-mapping-test.yang");
38 final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
39 doReturn(context).when(currentContext).getCurrentContext();
40 final FilterContentValidator validator = new FilterContentValidator(currentContext);
42 final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class
43 .getResourceAsStream("/filter/bug8084.xml"));
45 final XmlElement xmlElement = XmlElement.fromDomDocument(document);
46 final YangInstanceIdentifier actual = validator.validate(xmlElement);
48 final Map<QName, Object> inputs = new HashMap<>();
49 inputs.put(QName.create(BASE, "id1"), "aaa");
50 inputs.put(QName.create(BASE, "id2"), Byte.valueOf("-9"));
51 inputs.put(QName.create(BASE, "id3"), Short.valueOf("-30000"));
52 inputs.put(QName.create(BASE, "id4"), Integer.valueOf("-2000000000"));
53 inputs.put(QName.create(BASE, "id5"), Long.valueOf("-2000000000000000"));
54 inputs.put(QName.create(BASE, "id6"), Short.valueOf("9"));
55 inputs.put(QName.create(BASE, "id7"), Integer.valueOf("30000"));
56 inputs.put(QName.create(BASE, "id8"), Long.valueOf("2000000000"));
57 inputs.put(QName.create(BASE, "id9"), BigInteger.valueOf(Long.valueOf("2000000000000000")));
58 inputs.put(QName.create(BASE, "id10"), true);
59 inputs.put(QName.create(BASE, "id11"), BigDecimal.valueOf(128.55));
60 inputs.put(QName.create(BASE, "id12"), QName.create(BASE, "foo"));
62 QName.create(BASE, "id13"),
63 QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "foo"));
64 final QName idActual = (QName) ((NodeIdentifierWithPredicates) actual.getLastPathArgument())
65 .getKeyValues().get(QName.create(BASE, "id12"));
67 final YangInstanceIdentifier expected = YangInstanceIdentifier.builder()
69 .node(QName.create(BASE, "multi-key-list2"))
70 .nodeWithKey(QName.create(BASE, "multi-key-list2"), inputs)
72 final QName idExpected = (QName) ((NodeIdentifierWithPredicates) expected.getLastPathArgument())
73 .getKeyValues().get(QName.create(BASE, "id12"));
74 assertEquals(idExpected, idActual);
75 assertEquals(expected, actual);