Merge "BUG-981: remove deprecated elements"
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / 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.parser.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.Date;
18 import java.util.List;
19
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.Status;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
26 import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
27
28 public class BitImplTest {
29
30     @Test
31     public void test() {
32
33         // hashCode method test
34         URI uriA = null;
35         URI uriA1 = null;
36         URI uriA2 = null;
37         URI uriB = null;
38         URI uriB1 = null;
39         URI uriB2 = null;
40         boolean urisInitiallized = false;
41         try {
42             uriA = new URI("some:uriA");
43             uriA1 = new URI("some:uriA1");
44             uriA2 = new URI("some:uriA2");
45             uriB = new URI("some:uriB");
46             uriB1 = new URI("some:uriB1");
47             uriB2 = new URI("some:uriB2");
48             urisInitiallized = true;
49
50         } catch (URISyntaxException e) {
51             e.printStackTrace();
52             assertTrue("Not all required uri variables were instantiated.", urisInitiallized);
53
54         }
55         QName qnameA = new QName(uriA, new Date(5000000), "some name");
56
57         QName qnameA1 = new QName(uriA1, new Date(6000000), "some nameA1");
58         QName qnameA2 = new QName(uriA2, new Date(7000000), "some nameA2");
59         List<QName> qnamesA = new ArrayList<>();
60         qnamesA.add(qnameA1);
61         qnamesA.add(qnameA2);
62         SchemaPath schemaPathA = SchemaPath.create(qnamesA, true);
63
64         QName qnameB = new QName(uriB, new Date(5000000), "some name");
65
66         QName qnameB1 = new QName(uriB1, new Date(6000000), "some nameB1");
67         QName qnameB2 = new QName(uriB2, new Date(7000000), "some nameB2");
68         List<QName> qnamesB = new ArrayList<>();
69         qnamesB.add(qnameB1);
70         qnamesB.add(qnameB2);
71         SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
72
73         BitImpl biB = null;
74         BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
75
76         assertEquals("biA should equals to itsefl", biA, biA);
77         assertFalse("biA shouldn't equal to null", biA.equals(null));
78         assertFalse("biA shouldn't equal to object of other type", biA.equals(new String("str")));
79
80         // test of equals method
81         // // test qname
82         biA = new BitImpl(55L, null, 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         biA = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
87         biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
88         assertEquals("biA should equal to biB", biA, biB);
89
90         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
91         biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
92         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
93
94         // // test schemaPath
95         biA = new BitImpl(55L, qnameA, null, "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, schemaPathB, "description", "reference", Status.CURRENT, null);
100         biB = new BitImpl(55L, qnameA, schemaPathB, "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         biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
105         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
106
107         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
108         biB = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
109         assertEquals("biA should equal to biB", biA, biB);
110
111         // test of hashCode method
112         biA = new BitImpl(null, null, null, "description", "reference", Status.CURRENT, null);
113         assertEquals("Incorrect hash code for biA.", 923522, biA.hashCode());
114
115         List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
116         SchemaPath path = org.mockito.Mockito.mock(SchemaPath.class);
117         UnknownSchemaNodeBuilder usnb = new UnknownSchemaNodeBuilder("module", 3, qnameB, path);
118         ModuleBuilder parent = org.mockito.Mockito.mock(ModuleBuilder.class);
119         usnb.setParent(parent);
120
121         unknownNodes.add(usnb.build());
122
123         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, unknownNodes);
124
125         // test of getter methods
126         assertEquals("Incorrect value for qname.", qnameA, biA.getQName());
127         assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
128         assertEquals("Incorrect value for description.", "description", biA.getDescription());
129         assertEquals("Incorrect value for reference.", "reference", biA.getReference());
130         assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
131         assertEquals("Incorrect value for unknown nodes.", unknownNodes, biA.getUnknownSchemaNodes());
132
133         // test of toString method
134         assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());
135
136     }
137 }