2 * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.dom.api;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 public class DOMDataTreeIdentifierTest {
24 private static final String REF_LISTS = "ref-lists";
25 private static final String TEST_LISTS = "test-lists";
26 private static final String COMPARE_FIRST_LISTS = "A-test-lists";
27 private static final String COMPARE_SECOND_LISTS = "B-test-lists";
28 private static final QNameModule TEST_MODULE = QNameModule.create(URI.create(
29 "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"), null);
30 private static final YangInstanceIdentifier REF_YII_IID = YangInstanceIdentifier.create(
31 new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_MODULE, REF_LISTS)));
32 private static final YangInstanceIdentifier TEST_YII_IID = YangInstanceIdentifier.create(
33 new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_MODULE, TEST_LISTS)));
34 private static final DOMDataTreeIdentifier REF_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
36 private static final DOMDataTreeIdentifier TEST_DIFF_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
40 public void constructTest() {
41 assertNotNull("Instantiation", new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, REF_YII_IID));
44 @Test(expected = NullPointerException.class)
45 public void firstArgumentNullTest() throws Exception {
46 new DOMDataTreeIdentifier(null, REF_YII_IID);
49 @Test(expected = NullPointerException.class)
50 public void secondArgumentNullTest() throws Exception {
51 new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, null);
55 public void hashCodeTest() {
56 assertEquals("hashCode", REF_TREE.hashCode(), new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
57 REF_YII_IID).hashCode());
58 assertNotEquals("hashCode", REF_TREE.hashCode(), TEST_DIFF_TREE.hashCode());
62 public void equalsTest() {
63 assertTrue("Equals same", REF_TREE.equals(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
65 assertFalse("Different DataStoreType", REF_TREE.equals(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
67 assertTrue("Equals same instance", REF_TREE.equals(REF_TREE));
68 assertFalse("Different object", REF_TREE.equals(new Object()));
69 assertFalse("Different instance", REF_TREE.equals(TEST_DIFF_TREE));
73 public void compareToTest() {
74 final YangInstanceIdentifier compareFirstIid = YangInstanceIdentifier.create(
75 new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_MODULE, COMPARE_FIRST_LISTS)));
76 final YangInstanceIdentifier compareSecondIid = YangInstanceIdentifier.create(
77 new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_MODULE, COMPARE_SECOND_LISTS)));
79 assertEquals("Compare same to same", REF_TREE.compareTo(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
81 assertNotEquals("Compare same to same with different datastore", REF_TREE.compareTo(new DOMDataTreeIdentifier(
82 LogicalDatastoreType.CONFIGURATION, REF_YII_IID)), 0);
83 assertEquals("Compare same to same with different datastore",
84 new DOMDataTreeIdentifier(
85 LogicalDatastoreType.OPERATIONAL,
86 YangInstanceIdentifier.create(
87 YangInstanceIdentifier.NodeIdentifier.create(QName.create(TEST_MODULE, REF_LISTS)),
88 YangInstanceIdentifier.NodeIdentifier.create(QName.create(TEST_MODULE, TEST_LISTS))))
89 .compareTo(REF_TREE), 1);
90 assertTrue("Compare first to second", new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
91 compareFirstIid).compareTo(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
92 compareSecondIid)) < 0);
93 assertTrue("Compare second to first", new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
94 compareSecondIid).compareTo(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
95 compareFirstIid)) > 0);
99 public void containsTest() {
100 assertTrue("Contains", REF_TREE.contains(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
102 assertEquals("Not contains", false, REF_TREE.contains(TEST_DIFF_TREE));
106 public void toStringTest() {
107 assertTrue("ToString", REF_TREE.toString().contains(REF_TREE.getRootIdentifier().toString()) && REF_TREE
108 .toString().contains(REF_TREE.getDatastoreType().toString()));