2 * Copyright (c) 2014 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.yangtools.yang.parser.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
16 import java.net.URISyntaxException;
17 import java.util.ArrayList;
18 import java.util.Date;
19 import java.util.List;
20 import org.junit.Before;
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.parser.builder.impl.UnknownSchemaNodeBuilder;
26 public class RefineHolderTest {
28 private RefineHolder rh;
29 private RefineHolder rh1;
33 rh = new RefineHolder("module", 2104, "name");
34 rh1 = new RefineHolder("module", 2104, "name");
39 public void testRefineEquality() {
40 // hashCode method test
41 assertEquals("rh should equals to itsefl", rh, rh);
42 assertFalse("rh shouldn't equal to null", rh.equals(null));
43 assertFalse("rh shouldn't equal to object of other type", rh.equals(new String("str")));
45 assertEquals("rh1 should equals to rh", rh, rh1);
47 RefineHolder rh2 = new RefineHolder("module", 2104, null);
48 assertFalse("rh shouldn't equal to rh2", rh2.equals(rh1));
49 rh2 = new RefineHolder("module", 2104, "name2");
50 assertFalse("rh shouldn't equal to rh2", rh.equals(rh2));
52 assertEquals("Wrong hash code", 1557537141, rh.hashCode());
56 public void testConfigurationEqualsBranch() {
57 assertEquals("rh should equal to rh1", rh, rh1);
58 rh1.setConfiguration(false);
59 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
60 rh.setConfiguration(false);
61 assertEquals("rh should equal to rh1", rh, rh1);
62 rh.setConfiguration(true);
63 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
64 rh1.setConfiguration(true);
68 public void testDefaultStrEqualsBranch() {
69 assertEquals("rh should equal to rh1", rh, rh1);
70 rh1.setDefaultStr("default string1");
71 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
72 rh.setDefaultStr("default string1");
73 assertEquals("rh should equal to rh1", rh, rh1);
74 rh.setDefaultStr("default string");
75 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
76 rh1.setDefaultStr("default string");
80 public void testDescriptionEqualsBranch() {
81 assertEquals("rh should equal to rh1", rh, rh1);
82 rh1.setDescription("description1");
83 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
84 rh.setDescription("description1");
85 assertEquals("rh should equal to rh1", rh, rh1);
86 rh.setDescription("description");
87 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
88 rh1.setDescription("description");
92 public void testMandatoryEqualsBranch() {
93 assertEquals("rh should equal to rh1", rh, rh1);
94 rh1.setMandatory(false);
95 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
96 rh.setMandatory(false);
97 assertEquals("rh should equal to rh1", rh, rh1);
98 rh.setMandatory(true);
99 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
100 rh1.setMandatory(true);
104 public void testMaxElementsEqualsBranch() {
105 assertEquals("rh should equal to rh1", rh, rh1);
106 rh1.setMaxElements(5400);
107 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
108 rh.setMaxElements(5400);
109 assertEquals("rh should equal to rh1", rh, rh1);
110 rh.setMaxElements(5435);
111 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
112 rh1.setMaxElements(5435);
116 public void testMinElementsEqualsBranch() {
117 assertEquals("rh should equal to rh1", rh, rh1);
118 rh1.setMinElements(16);
119 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
120 rh.setMinElements(16);
121 assertEquals("rh should equal to rh1", rh, rh1);
122 rh.setMinElements(159);
123 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
124 rh1.setMinElements(159);
128 public void testMustEqualsBranch() {
129 assertEquals("rh should equal to rh1", rh, rh1);
130 rh1.setMust(new MustDefinitionImpl("mustStr1", "description1", "reference1", "errorAppTag1", "errorMessage1"));
131 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
132 rh.setMust(new MustDefinitionImpl("mustStr1", "description1", "reference1", "errorAppTag1", "errorMessage1"));
133 assertEquals("rh should equal to rh1", rh, rh1);
134 rh.setMust(new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage"));
135 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
136 rh1.setMust(new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage"));
140 public void testPresenceEqualsBranch() {
141 assertEquals("rh should equal to rh1", rh, rh1);
142 rh1.setPresence(false);
143 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
144 rh.setPresence(false);
145 assertEquals("rh should equal to rh1", rh, rh1);
146 rh.setPresence(true);
147 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
148 rh1.setPresence(true);
152 public void testReferenceEqualsBranch() {
153 assertEquals("rh should equal to rh1", rh, rh1);
154 rh1.setReference("reference1");
155 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
156 rh.setReference("reference1");
157 assertEquals("rh should equal to rh1", rh, rh1);
158 rh.setReference("reference");
159 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
160 rh1.setReference("reference");
163 private URI getUri(final String uri) {
164 URI simpleUri = null;
165 boolean instantionated = false;
167 simpleUri = new URI(uri);
168 instantionated = true;
169 } catch (URISyntaxException e1) {
170 e1.printStackTrace();
171 assertTrue("Uri instance wasn't created.", instantionated);
177 public void testAddUnknownNodeBuilderEqualsBranch() {
178 URI simpleUri = null;
179 simpleUri = getUri("very:simple:URI");
180 assertNotNull("URI can't be null", simpleUri);
182 URI uriA = getUri("some:uriA");
183 assertNotNull("URI can't be null", simpleUri);
184 QName qnameA = QName.create(uriA, new Date(5000000), "some nameA");
185 QName qnameB = QName.create(uriA, new Date(6000000), "some nameB");
186 List<QName> qnamesA = new ArrayList<>();
187 List<QName> qnamesB = new ArrayList<>();
190 SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
192 UnknownSchemaNodeBuilder usnb = new UnknownSchemaNodeBuilder("usnb", 151, new QName(simpleUri, "tst"), schemaPathB);
193 UnknownSchemaNodeBuilder usnb1 = new UnknownSchemaNodeBuilder("usnb", 151, new QName(simpleUri, "tst"), schemaPathB);
195 assertEquals("rh should equal to rh1", rh, rh1);
196 rh1.addUnknownNodeBuilder(usnb);
197 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
198 rh.addUnknownNodeBuilder(usnb1);
199 assertEquals("rh should equal to rh1", rh, rh1);
203 public void testParentEqualsBranch() {
204 URI simpleUriA = getUri("very:simple:URI:a");
205 URI simpleUriB = getUri("very:simple:URI:b");
207 SchemaPath path = org.mockito.Mockito.mock(SchemaPath.class);
209 UnknownSchemaNodeBuilder usnbA = new UnknownSchemaNodeBuilder("usnbA", 151, new QName(simpleUriA, "tst"), path);
210 UnknownSchemaNodeBuilder usnbB = new UnknownSchemaNodeBuilder("usnbB", 151, new QName(simpleUriB, "tst"), path);
211 UnknownSchemaNodeBuilder usnbAParent = new UnknownSchemaNodeBuilder("usnbAParent", 151, new QName(simpleUriA,
213 usnbA.setParent(usnbAParent);
215 assertEquals("rh should equal to rh1", rh, rh1);
216 rh1.setParent(usnbB);
217 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
219 assertEquals("rh should equal to rh1", rh, rh1);
221 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
222 rh1.setParent(usnbA);
224 assertEquals("rh should equal to rh1", rh, rh1);