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;
14 import com.google.common.base.Optional;
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;
30 * @deprecated Pre-Beryllium implementation, scheduled for removal.
33 public class RefineHolderTest {
35 private RefineHolderImpl rh;
36 private RefineHolderImpl rh1;
40 rh = new RefineHolderImpl("module", 2104, "name");
41 rh1 = new RefineHolderImpl("module", 2104, "name");
46 public void testRefineEquality() {
47 // hashCode method test
48 assertEquals("rh should equals to itsefl", rh, rh);
49 assertFalse("rh shouldn't equal to null", rh.equals(null));
50 assertFalse("rh shouldn't equal to object of other type", rh.equals(new String("str")));
52 assertEquals("rh1 should equals to rh", rh, rh1);
54 RefineBuilder rh2 = new RefineHolderImpl("module", 2104, null);
55 assertFalse("rh shouldn't equal to rh2", rh2.equals(rh1));
56 rh2 = new RefineHolderImpl("module", 2104, "name2");
57 assertFalse("rh shouldn't equal to rh2", rh.equals(rh2));
59 assertEquals("Wrong hash code", 1557537141, rh.hashCode());
63 public void testConfigurationEqualsBranch() {
64 assertEquals("rh should equal to rh1", rh, rh1);
65 rh1.setConfiguration(false);
66 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
67 rh.setConfiguration(false);
68 assertEquals("rh should equal to rh1", rh, rh1);
69 rh.setConfiguration(true);
70 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
71 rh1.setConfiguration(true);
75 public void testDefaultStrEqualsBranch() {
76 assertEquals("rh should equal to rh1", rh, rh1);
77 rh1.setDefaultStr("default string1");
78 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
79 rh.setDefaultStr("default string1");
80 assertEquals("rh should equal to rh1", rh, rh1);
81 rh.setDefaultStr("default string");
82 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
83 rh1.setDefaultStr("default string");
87 public void testDescriptionEqualsBranch() {
88 assertEquals("rh should equal to rh1", rh, rh1);
89 rh1.setDescription("description1");
90 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
91 rh.setDescription("description1");
92 assertEquals("rh should equal to rh1", rh, rh1);
93 rh.setDescription("description");
94 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
95 rh1.setDescription("description");
99 public void testMandatoryEqualsBranch() {
100 assertEquals("rh should equal to rh1", rh, rh1);
101 rh1.setMandatory(false);
102 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
103 rh.setMandatory(false);
104 assertEquals("rh should equal to rh1", rh, rh1);
105 rh.setMandatory(true);
106 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
107 rh1.setMandatory(true);
111 public void testMaxElementsEqualsBranch() {
112 assertEquals("rh should equal to rh1", rh, rh1);
113 rh1.setMaxElements(5400);
114 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
115 rh.setMaxElements(5400);
116 assertEquals("rh should equal to rh1", rh, rh1);
117 rh.setMaxElements(5435);
118 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
119 rh1.setMaxElements(5435);
123 public void testMinElementsEqualsBranch() {
124 assertEquals("rh should equal to rh1", rh, rh1);
125 rh1.setMinElements(16);
126 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
127 rh.setMinElements(16);
128 assertEquals("rh should equal to rh1", rh, rh1);
129 rh.setMinElements(159);
130 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
131 rh1.setMinElements(159);
135 public void testMustEqualsBranch() {
136 assertEquals("rh should equal to rh1", rh, rh1);
137 rh1.setMust(MustDefinitionImpl.create("mustStr1", Optional.of("description1"), Optional.of("reference1"),
138 Optional.of("errorAppTag1"), Optional.of("errorMessage1")));
139 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
140 rh.setMust(MustDefinitionImpl.create("mustStr1", Optional.of("description1"), Optional.of("reference1"),
141 Optional.of("errorAppTag1"), Optional.of("errorMessage1")));
142 assertEquals("rh should equal to rh1", rh, rh1);
143 rh.setMust(MustDefinitionImpl.create("mustStr", Optional.of("description"), Optional.of("reference"),
144 Optional.of("errorAppTag"), Optional.of("errorMessage")));
145 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
146 rh1.setMust(MustDefinitionImpl.create("mustStr", Optional.of("description"), Optional.of("reference"),
147 Optional.of("errorAppTag"), Optional.of("errorMessage")));
151 public void testPresenceEqualsBranch() {
152 assertEquals("rh should equal to rh1", rh, rh1);
153 rh1.setPresence(false);
154 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
155 rh.setPresence(false);
156 assertEquals("rh should equal to rh1", rh, rh1);
157 rh.setPresence(true);
158 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
159 rh1.setPresence(true);
163 public void testReferenceEqualsBranch() {
164 assertEquals("rh should equal to rh1", rh, rh1);
165 rh1.setReference("reference1");
166 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
167 rh.setReference("reference1");
168 assertEquals("rh should equal to rh1", rh, rh1);
169 rh.setReference("reference");
170 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
171 rh1.setReference("reference");
174 private static URI getUri(final String uri) {
175 URI simpleUri = null;
176 boolean instantionated = false;
178 simpleUri = new URI(uri);
179 instantionated = true;
180 } catch (URISyntaxException e1) {
181 e1.printStackTrace();
182 assertTrue("Uri instance wasn't created.", instantionated);
188 public void testAddUnknownNodeBuilderEqualsBranch() {
189 URI simpleUri = null;
190 simpleUri = getUri("very:simple:URI");
191 assertNotNull("URI can't be null", simpleUri);
193 URI uriA = getUri("some:uriA");
194 assertNotNull("URI can't be null", simpleUri);
195 QName qnameA = QName.create(uriA, new Date(5000000), "some nameA");
196 QName qnameB = QName.create(uriA, new Date(6000000), "some nameB");
197 List<QName> qnamesA = new ArrayList<>();
198 List<QName> qnamesB = new ArrayList<>();
201 SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
203 UnknownSchemaNodeBuilderImpl usnb = new UnknownSchemaNodeBuilderImpl("usnb", 151, new QName(simpleUri, "tst"), schemaPathB);
204 UnknownSchemaNodeBuilderImpl usnb1 = new UnknownSchemaNodeBuilderImpl("usnb", 151, new QName(simpleUri, "tst"), schemaPathB);
206 assertEquals("rh should equal to rh1", rh, rh1);
207 rh1.addUnknownNodeBuilder(usnb);
208 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
209 rh.addUnknownNodeBuilder(usnb1);
210 assertEquals("rh should equal to rh1", rh, rh1);
214 public void testParentEqualsBranch() {
215 URI simpleUriA = getUri("very:simple:URI:a");
216 URI simpleUriB = getUri("very:simple:URI:b");
218 SchemaPath path = org.mockito.Mockito.mock(SchemaPath.class);
220 UnknownSchemaNodeBuilderImpl usnbA = new UnknownSchemaNodeBuilderImpl("usnbA", 151, new QName(simpleUriA, "tst"), path);
221 UnknownSchemaNodeBuilderImpl usnbB = new UnknownSchemaNodeBuilderImpl("usnbB", 151, new QName(simpleUriB, "tst"), path);
222 UnknownSchemaNodeBuilderImpl usnbAParent = new UnknownSchemaNodeBuilderImpl("usnbAParent", 151, new QName(simpleUriA,
224 usnbA.setParent(usnbAParent);
226 assertEquals("rh should equal to rh1", rh, rh1);
227 rh1.setParent(usnbB);
228 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
230 assertEquals("rh should equal to rh1", rh, rh1);
232 assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
233 rh1.setParent(usnbA);
235 assertEquals("rh should equal to rh1", rh, rh1);