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"));
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
37 TEST_DIFF_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,TEST_YII_IID);
40 public void constructTest() {
41 assertNotNull("Instantiation", new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, REF_YII_IID));
45 public void hashCodeTest() {
46 assertEquals("hashCode", REF_TREE.hashCode(), new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
47 REF_YII_IID).hashCode());
48 assertNotEquals("hashCode", REF_TREE.hashCode(), TEST_DIFF_TREE.hashCode());
52 public void equalsTest() {
53 assertTrue("Equals same", REF_TREE.equals(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
55 assertFalse("Different DataStoreType", REF_TREE.equals(
56 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
58 assertTrue("Equals same instance", REF_TREE.equals(REF_TREE));
59 assertFalse("Different object", REF_TREE.equals(new Object()));
60 assertFalse("Different instance", REF_TREE.equals(TEST_DIFF_TREE));
64 public void compareToTest() {
65 final YangInstanceIdentifier compareFirstIid = YangInstanceIdentifier.create(
66 new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_MODULE, COMPARE_FIRST_LISTS)));
67 final YangInstanceIdentifier compareSecondIid = YangInstanceIdentifier.create(
68 new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_MODULE, COMPARE_SECOND_LISTS)));
70 assertEquals("Compare same to same", REF_TREE.compareTo(
71 new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
73 assertNotEquals("Compare same to same with different datastore", REF_TREE.compareTo(new DOMDataTreeIdentifier(
74 LogicalDatastoreType.CONFIGURATION, REF_YII_IID)), 0);
75 assertEquals("Compare same to same with different datastore",
76 new DOMDataTreeIdentifier(
77 LogicalDatastoreType.OPERATIONAL,
78 YangInstanceIdentifier.create(
79 YangInstanceIdentifier.NodeIdentifier.create(QName.create(TEST_MODULE, REF_LISTS)),
80 YangInstanceIdentifier.NodeIdentifier.create(QName.create(TEST_MODULE, TEST_LISTS))))
81 .compareTo(REF_TREE), 1);
82 assertTrue("Compare first to second", new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
83 compareFirstIid).compareTo(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
84 compareSecondIid)) < 0);
85 assertTrue("Compare second to first", new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
86 compareSecondIid).compareTo(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
87 compareFirstIid)) > 0);
91 public void containsTest() {
92 assertTrue("Contains", REF_TREE.contains(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
94 assertEquals("Not contains", false, REF_TREE.contains(TEST_DIFF_TREE));
98 public void toStringTest() {
99 assertTrue("ToString", REF_TREE.toString().contains(REF_TREE.getRootIdentifier().toString()) && REF_TREE
100 .toString().contains(REF_TREE.getDatastoreType().toString()));