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 com.google.common.collect.ImmutableMap;
15 import java.math.BigDecimal;
16 import java.math.BigInteger;
17 import org.junit.Test;
18 import org.opendaylight.netconf.api.xml.XmlElement;
19 import org.opendaylight.netconf.api.xml.XmlUtil;
20 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class Bug8084 {
27 private static final QName BASE = QName.create("urn:dummy:mod-0", "2016-03-01", "mainroot");
30 public void testValidateTypes() throws Exception {
31 final var context = YangParserTestUtils.parseYangResources(Bug8084.class,
32 "/yang/filter-validator-test-mod-0.yang", "/yang/filter-validator-test-augment.yang",
33 "/yang/mdsal-netconf-mapping-test.yang");
34 final var currentContext = mock(CurrentSchemaContext.class);
35 doReturn(context).when(currentContext).getCurrentContext();
36 final var validator = new FilterContentValidator(currentContext);
38 final var document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class
39 .getResourceAsStream("/filter/bug8084.xml"));
41 final var xmlElement = XmlElement.fromDomDocument(document);
42 final var actual = validator.validate(xmlElement);
44 final var id12 = QName.create(BASE, "id12");
45 final var idExpected = QName.create(BASE, "foo");
46 final var idActual = (QName) ((NodeIdentifierWithPredicates) actual.getLastPathArgument()).getValue(id12);
47 assertEquals(idExpected, idActual);
49 assertEquals(YangInstanceIdentifier.builder()
51 .node(QName.create(BASE, "multi-key-list2"))
52 .nodeWithKey(QName.create(BASE, "multi-key-list2"), ImmutableMap.<QName, Object>builder()
53 .put(QName.create(BASE, "id1"), "aaa")
54 .put(QName.create(BASE, "id2"), Byte.valueOf("-9"))
55 .put(QName.create(BASE, "id3"), Short.valueOf("-30000"))
56 .put(QName.create(BASE, "id4"), Integer.valueOf("-2000000000"))
57 .put(QName.create(BASE, "id5"), Long.valueOf("-2000000000000000"))
58 .put(QName.create(BASE, "id6"), Short.valueOf("9"))
59 .put(QName.create(BASE, "id7"), Integer.valueOf("30000"))
60 .put(QName.create(BASE, "id8"), Long.valueOf("2000000000"))
61 .put(QName.create(BASE, "id9"), BigInteger.valueOf(Long.parseLong("2000000000000000")))
62 .put(QName.create(BASE, "id10"), true)
63 .put(QName.create(BASE, "id11"), BigDecimal.valueOf(128.55))
64 .put(id12, idExpected)
65 .put(QName.create(BASE, "id13"),
66 QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "foo"))