BUG 1131: untangling package cyclic dependencies in yang-parser-impl
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / BitImplTest.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.assertTrue;
13
14 import java.net.URI;
15 import java.net.URISyntaxException;
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.Date;
19 import java.util.List;
20
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.Status;
25
26 public class BitImplTest {
27
28     @Test
29     public void test() {
30
31         // hashCode method test
32         URI uriA = null;
33         URI uriA1 = null;
34         URI uriA2 = null;
35         URI uriB = null;
36         URI uriB1 = null;
37         URI uriB2 = null;
38         boolean urisInitiallized = false;
39         try {
40             uriA = new URI("some:uriA");
41             uriA1 = new URI("some:uriA1");
42             uriA2 = new URI("some:uriA2");
43             uriB = new URI("some:uriB");
44             uriB1 = new URI("some:uriB1");
45             uriB2 = new URI("some:uriB2");
46             urisInitiallized = true;
47
48         } catch (URISyntaxException e) {
49             e.printStackTrace();
50             assertTrue("Not all required uri variables were instantiated.", urisInitiallized);
51
52         }
53         QName qnameA = QName.create(uriA, new Date(5000000), "some name");
54
55         QName qnameA1 = QName.create(uriA1, new Date(6000000), "some nameA1");
56         QName qnameA2 = QName.create(uriA2, new Date(7000000), "some nameA2");
57         List<QName> qnamesA = new ArrayList<>();
58         qnamesA.add(qnameA1);
59         qnamesA.add(qnameA2);
60         SchemaPath schemaPathA = SchemaPath.create(qnamesA, true);
61
62         QName qnameB = QName.create(uriB, new Date(5000000), "some name");
63
64         QName qnameB1 = QName.create(uriB1, new Date(6000000), "some nameB1");
65         QName qnameB2 = QName.create(uriB2, new Date(7000000), "some nameB2");
66         List<QName> qnamesB = new ArrayList<>();
67         qnamesB.add(qnameB1);
68         qnamesB.add(qnameB2);
69         SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
70
71         BitImpl biB = null;
72         BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
73
74         assertEquals("biA should equals to itsefl", biA, biA);
75         assertFalse("biA shouldn't equal to null", biA.equals(null));
76         assertFalse("biA shouldn't equal to object of other type", biA.equals(new String("str")));
77
78         biA = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
79         biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
80         assertEquals("biA should equal to biB", biA, biB);
81
82         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
83         biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
84         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
85
86         // // test schemaPath
87         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
88         biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
89         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
90
91         biA = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
92         biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
93         assertEquals("biA should equal to biB", biA, biB);
94
95         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
96         biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
97         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
98
99         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
100         biB = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
101         assertEquals("biA should equal to biB", biA, biB);
102
103         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT,null);
104
105         // test of getter methods
106         assertEquals("Incorrect value for qname.", qnameA, biA.getQName());
107         assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
108         assertEquals("Incorrect value for description.", "description", biA.getDescription());
109         assertEquals("Incorrect value for reference.", "reference", biA.getReference());
110         assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
111         assertEquals("Incorrect value for unknown nodes.", Collections.emptyList(), biA.getUnknownSchemaNodes());
112
113         // test of toString method
114         assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());
115
116     }
117 }