BUG-4322: Leafref should not have a default value
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / LeafrefTest.java
1 /*
2  * Copyright (c) 2014 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.yangtools.yang.model.util;
9
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.assertNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.Status;
21
22 public class LeafrefTest {
23
24     @Test
25     public void testMethodsOfLeafrefTest() {
26         final SchemaPath schemaPath = SchemaPath.create(false, QName.create("Cont1"), QName.create("List1"));
27         final RevisionAwareXPathImpl revision = new RevisionAwareXPathImpl("/test:Cont1/test:List1", false);
28         final RevisionAwareXPathImpl revision2 = new RevisionAwareXPathImpl("/test:Cont1/test:List2", false);
29
30         final Leafref leafref = Leafref.create(schemaPath, revision);
31         final Leafref leafref2 = Leafref.create(schemaPath, revision2);
32         final Leafref leafref3 = Leafref.create(schemaPath, revision);
33         final Leafref leafref4 = leafref;
34
35         assertNotNull("Object 'leafref' shouldn't be null.", leafref);
36         assertNull("Base type of 'leafref' should be null.", leafref.getBaseType());
37         assertTrue("Units of 'leafref' should be empty.", leafref.getUnits().isEmpty());
38         assertNull("Leafref does not have a default value", leafref.getDefaultValue());
39         assertEquals("QName of 'leafref' is value '(urn:ietf:params:xml:ns:yang:1)leafref'.",
40                 BaseTypes.constructQName("leafref"), leafref.getQName());
41         assertEquals("SchemaPath of 'leafref' is '/Cont1/List1'.", schemaPath, leafref.getPath());
42         assertEquals("Description of 'leafref' is 'The leafref type is used to reference a particular leaf instance in the data tree.'",
43                 "The leafref type is used to reference a particular leaf instance in the data tree.", leafref.getDescription());
44         assertEquals("Reference of 'leafref' is 'https://tools.ietf.org/html/rfc6020#section-9.9'.", "https://tools.ietf.org/html/rfc6020#section-9.9", leafref.getReference());
45         assertEquals("Status of 'leafref' is current.", Status.CURRENT, leafref.getStatus());
46         assertTrue("Object 'leafref' shouldn't have any unknown schema nodes.", leafref.getUnknownSchemaNodes().isEmpty());
47         assertEquals("Revision aware XPath of 'leafref' should be '/test:Cont1/test:List1'.", revision, leafref.getPathStatement());
48         assertNotNull("String representation of 'leafref' shouldn't be null.", leafref.toString());
49         assertNotEquals("Hash codes of two different object of type Leafref shouldn't be equal.", leafref.hashCode(), leafref2.hashCode());
50         assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref3));
51         assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref4));
52         assertFalse("Objects of type Leafref shouldn't be equal.", leafref.equals(leafref2));
53         assertFalse("Objects shouldn't be equal.", leafref.equals(null));
54         assertFalse("Objects shouldn't be equal.", leafref.equals("test"));
55     }
56 }