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.io.InputStream;
15 import java.math.BigDecimal;
16 import java.math.BigInteger;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
21 import org.junit.Test;
22 import org.opendaylight.controller.config.util.xml.XmlElement;
23 import org.opendaylight.controller.config.util.xml.XmlUtil;
24 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
29 import org.w3c.dom.Document;
31 public class Bug8084 {
33 private static final QName base = QName.create("urn:dummy:mod-0", "2016-03-01", "mainroot");
36 public void testValidateTypes() throws Exception {
37 final List<InputStream> sources = new ArrayList<>();
38 sources.add(getClass().getResourceAsStream("/yang/filter-validator-test-mod-0.yang"));
39 sources.add(getClass().getResourceAsStream("/yang/filter-validator-test-augment.yang"));
40 sources.add(getClass().getResourceAsStream("/yang/mdsal-netconf-mapping-test.yang"));
41 final SchemaContext context = YangParserTestUtils.parseYangStreams(sources);
42 final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
43 doReturn(context).when(currentContext).getCurrentContext();
44 final FilterContentValidator validator = new FilterContentValidator(currentContext);
46 final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class
47 .getResourceAsStream("/filter/bug8084.xml"));
49 final XmlElement xmlElement = XmlElement.fromDomDocument(document);
50 final YangInstanceIdentifier actual = validator.validate(xmlElement);
52 final Map<QName, Object> inputs = new HashMap<>();
53 inputs.put(QName.create(base, "id1"), "aaa");
54 inputs.put(QName.create(base, "id2"), Byte.valueOf("-9"));
55 inputs.put(QName.create(base, "id3"), Short.valueOf("-30000"));
56 inputs.put(QName.create(base, "id4"), Integer.valueOf("-2000000000"));
57 inputs.put(QName.create(base, "id5"), Long.valueOf("-2000000000000000"));
58 inputs.put(QName.create(base, "id6"), Short.valueOf("9"));
59 inputs.put(QName.create(base, "id7"), Integer.valueOf("30000"));
60 inputs.put(QName.create(base, "id8"), Long.valueOf("2000000000"));
61 inputs.put(QName.create(base, "id9"), BigInteger.valueOf(Long.valueOf("2000000000000000")));
62 inputs.put(QName.create(base, "id10"), true);
63 inputs.put(QName.create(base, "id11"), BigDecimal.valueOf(128.55));
64 inputs.put(QName.create(base, "id12"), QName.create(base, "foo"));
65 inputs.put(QName.create(base, "id13"), QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "foo"));
66 final QName idActual = (QName) ((YangInstanceIdentifier.NodeIdentifierWithPredicates) actual.getLastPathArgument()).
67 getKeyValues().get(QName.create(base, "id12"));
70 final YangInstanceIdentifier expected = YangInstanceIdentifier.builder()
72 .node(QName.create(base, "multi-key-list2"))
73 .nodeWithKey(QName.create(base, "multi-key-list2"), inputs)
75 final QName idExpected = (QName) ((YangInstanceIdentifier.NodeIdentifierWithPredicates) expected.getLastPathArgument()).
76 getKeyValues().get(QName.create(base, "id12"));
77 assertEquals(idExpected, idActual);
78 assertEquals(expected, actual);