8adc1802d6a9da9b36a672fbad060520cab05405
[mdsal.git] / dom / mdsal-dom-api / src / test / java / org / opendaylight / mdsal / dom / api / DOMRpcIdentifierTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.api;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertNotEquals;
13
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.common.XMLNamespace;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 class DOMRpcIdentifierTest {
21     private static final QNameModule TEST_MODULE = QNameModule.create(XMLNamespace.of(
22             "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"));
23     private static final QName LOCAL_QNAME = QName.create(TEST_MODULE, "local");
24     private static final DOMRpcIdentifier GLOBAL = DOMRpcIdentifier.create(LOCAL_QNAME, null);
25     private static final DOMRpcIdentifier LOCAL = DOMRpcIdentifier.create(LOCAL_QNAME,
26             YangInstanceIdentifier.of(LOCAL_QNAME));
27
28     @Test
29     void createTest() {
30         assertInstanceOf(DOMRpcIdentifier.Global.class, GLOBAL);
31         assertInstanceOf(DOMRpcIdentifier.Local.class, LOCAL);
32     }
33
34     @Test
35     void hashCodeTest() {
36         assertEquals(GLOBAL.hashCode(), DOMRpcIdentifier.create(LOCAL_QNAME).hashCode());
37         assertNotEquals(GLOBAL.hashCode(), LOCAL.hashCode());
38     }
39
40     @Test
41     void equalsTest() {
42         assertEquals(GLOBAL, DOMRpcIdentifier.create(LOCAL_QNAME));
43         assertEquals(GLOBAL, GLOBAL);
44         assertNotEquals(GLOBAL, new Object());
45         assertNotEquals(GLOBAL, LOCAL);
46     }
47
48     @Test
49     void toStringTest() {
50         assertEquals("Global{type=(urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store)local, "
51             + "contextReference=/}", GLOBAL.toString());
52         assertEquals("Local{type=(urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store)local, "
53             + "contextReference=/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store)local}",
54             LOCAL.toString());
55     }
56 }