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.model.util.MustDefinitionImpl;
25 import org.opendaylight.yangtools.yang.parser.builder.api.RefineBuilder;
26 import org.opendaylight.yangtools.yang.parser.builder.impl.RefineHolderImpl;
27 import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilderImpl;
29 public class RefineHolderTest {
31 private RefineHolderImpl rh;
32 private RefineHolderImpl rh1;
36 rh = new RefineHolderImpl("module", 2104, "name");
37 rh1 = new RefineHolderImpl("module", 2104, "name");
42 public void testRefineEquality() {
43 // hashCode method test
44 assertEquals("rh should equals to itsefl", rh, rh);
45 assertFalse("rh shouldn't equal to null", rh.equals(null));
46 assertFalse("rh shouldn't equal to object of other type", rh.equals(new String("str")));
48 assertEquals("rh1 should equals to rh", rh, rh1);
50 RefineBuilder rh2 = new RefineHolderImpl("module", 2104, null);
51 assertFalse("rh shouldn't equal to rh2", rh2.equals(rh1));
52 rh2 = new RefineHolderImpl("module", 2104, "name2");
53 assertFalse("rh shouldn't equal to rh2", rh.equals(rh2));
55 assertEquals("Wrong hash code", 1557537141, rh.hashCode());
59 public void testConfigurationEqualsBranch() {
60 assertEquals("rh should equal to rh1", rh, rh1);
61 rh1.setConfiguration(false);
62 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
63 rh.setConfiguration(false);
64 assertEquals("rh should equal to rh1", rh, rh1);
65 rh.setConfiguration(true);
66 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
67 rh1.setConfiguration(true);
71 public void testDefaultStrEqualsBranch() {
72 assertEquals("rh should equal to rh1", rh, rh1);
73 rh1.setDefaultStr("default string1");
74 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
75 rh.setDefaultStr("default string1");
76 assertEquals("rh should equal to rh1", rh, rh1);
77 rh.setDefaultStr("default string");
78 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
79 rh1.setDefaultStr("default string");
83 public void testDescriptionEqualsBranch() {
84 assertEquals("rh should equal to rh1", rh, rh1);
85 rh1.setDescription("description1");
86 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
87 rh.setDescription("description1");
88 assertEquals("rh should equal to rh1", rh, rh1);
89 rh.setDescription("description");
90 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
91 rh1.setDescription("description");
95 public void testMandatoryEqualsBranch() {
96 assertEquals("rh should equal to rh1", rh, rh1);
97 rh1.setMandatory(false);
98 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
99 rh.setMandatory(false);
100 assertEquals("rh should equal to rh1", rh, rh1);
101 rh.setMandatory(true);
102 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
103 rh1.setMandatory(true);
107 public void testMaxElementsEqualsBranch() {
108 assertEquals("rh should equal to rh1", rh, rh1);
109 rh1.setMaxElements(5400);
110 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
111 rh.setMaxElements(5400);
112 assertEquals("rh should equal to rh1", rh, rh1);
113 rh.setMaxElements(5435);
114 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
115 rh1.setMaxElements(5435);
119 public void testMinElementsEqualsBranch() {
120 assertEquals("rh should equal to rh1", rh, rh1);
121 rh1.setMinElements(16);
122 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
123 rh.setMinElements(16);
124 assertEquals("rh should equal to rh1", rh, rh1);
125 rh.setMinElements(159);
126 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
127 rh1.setMinElements(159);
131 public void testMustEqualsBranch() {
132 assertEquals("rh should equal to rh1", rh, rh1);
133 rh1.setMust(new MustDefinitionImpl("mustStr1", "description1", "reference1", "errorAppTag1", "errorMessage1"));
134 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
135 rh.setMust(new MustDefinitionImpl("mustStr1", "description1", "reference1", "errorAppTag1", "errorMessage1"));
136 assertEquals("rh should equal to rh1", rh, rh1);
137 rh.setMust(new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage"));
138 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
139 rh1.setMust(new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage"));
143 public void testPresenceEqualsBranch() {
144 assertEquals("rh should equal to rh1", rh, rh1);
145 rh1.setPresence(false);
146 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
147 rh.setPresence(false);
148 assertEquals("rh should equal to rh1", rh, rh1);
149 rh.setPresence(true);
150 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
151 rh1.setPresence(true);
155 public void testReferenceEqualsBranch() {
156 assertEquals("rh should equal to rh1", rh, rh1);
157 rh1.setReference("reference1");
158 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
159 rh.setReference("reference1");
160 assertEquals("rh should equal to rh1", rh, rh1);
161 rh.setReference("reference");
162 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
163 rh1.setReference("reference");
166 private URI getUri(final String uri) {
167 URI simpleUri = null;
168 boolean instantionated = false;
170 simpleUri = new URI(uri);
171 instantionated = true;
172 } catch (URISyntaxException e1) {
173 e1.printStackTrace();
174 assertTrue("Uri instance wasn't created.", instantionated);
180 public void testAddUnknownNodeBuilderEqualsBranch() {
181 URI simpleUri = null;
182 simpleUri = getUri("very:simple:URI");
183 assertNotNull("URI can't be null", simpleUri);
185 URI uriA = getUri("some:uriA");
186 assertNotNull("URI can't be null", simpleUri);
187 QName qnameA = QName.create(uriA, new Date(5000000), "some nameA");
188 QName qnameB = QName.create(uriA, new Date(6000000), "some nameB");
189 List<QName> qnamesA = new ArrayList<>();
190 List<QName> qnamesB = new ArrayList<>();
193 SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
195 UnknownSchemaNodeBuilderImpl usnb = new UnknownSchemaNodeBuilderImpl("usnb", 151, new QName(simpleUri, "tst"), schemaPathB);
196 UnknownSchemaNodeBuilderImpl usnb1 = new UnknownSchemaNodeBuilderImpl("usnb", 151, new QName(simpleUri, "tst"), schemaPathB);
198 assertEquals("rh should equal to rh1", rh, rh1);
199 rh1.addUnknownNodeBuilder(usnb);
200 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
201 rh.addUnknownNodeBuilder(usnb1);
202 assertEquals("rh should equal to rh1", rh, rh1);
206 public void testParentEqualsBranch() {
207 URI simpleUriA = getUri("very:simple:URI:a");
208 URI simpleUriB = getUri("very:simple:URI:b");
210 SchemaPath path = org.mockito.Mockito.mock(SchemaPath.class);
212 UnknownSchemaNodeBuilderImpl usnbA = new UnknownSchemaNodeBuilderImpl("usnbA", 151, new QName(simpleUriA, "tst"), path);
213 UnknownSchemaNodeBuilderImpl usnbB = new UnknownSchemaNodeBuilderImpl("usnbB", 151, new QName(simpleUriB, "tst"), path);
214 UnknownSchemaNodeBuilderImpl usnbAParent = new UnknownSchemaNodeBuilderImpl("usnbAParent", 151, new QName(simpleUriA,
216 usnbA.setParent(usnbAParent);
218 assertEquals("rh should equal to rh1", rh, rh1);
219 rh1.setParent(usnbB);
220 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
222 assertEquals("rh should equal to rh1", rh, rh1);
224 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
225 rh1.setParent(usnbA);
227 assertEquals("rh should equal to rh1", rh, rh1);