--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
+import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+public class IdentityrefTypeTest {
+
+ private static List<File> testModels = null;
+
+ @Before
+ public void loadTestResources() {
+ String folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").getPath();
+ File folderFile = new File(folderPath);
+ testModels = new ArrayList<File>();
+
+ if (folderFile.isFile()) {
+ testModels.add(folderFile);
+ } else {
+ for (File file : folderFile.listFiles()) {
+ if (file.isFile()) {
+ testModels.add(file);
+ }
+ }
+ }
+ }
+
+ /**
+ * Test mainly for the method
+ * {@link TypeProviderImpl#provideTypeForIdentityref()
+ * provideTypeForIdentityref}
+ */
+ @Test
+ public void testIdentityrefYangBuiltInType() {
+ loadTestResources();
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = parser.parseYangModels(testModels);
+ final SchemaContext context = parser.resolveSchemaContext(modules);
+
+ assertNotNull(context);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+
+ GeneratedType moduleGenType = null;
+ for (Type type : genTypes) {
+ if (type.getName().equals("ModuleIdentityrefData")) {
+ if (type instanceof GeneratedType) {
+ moduleGenType = (GeneratedType) type;
+ }
+ }
+ }
+
+ assertNotNull("Generated type for whole module wasn't found", moduleGenType);
+
+ String typeName = null;
+ String actualTypeName = "";
+ int numOfActualTypes = 0;
+ List<MethodSignature> methodSignatures = moduleGenType.getMethodDefinitions();
+ for (MethodSignature methodSignature : methodSignatures) {
+ if (methodSignature.getName().equals("getLf")) {
+ Type returnType = methodSignature.getReturnType();
+ if (returnType instanceof ParameterizedType) {
+ typeName = returnType.getName();
+ Type[] actualTypes = ((ParameterizedType) returnType).getActualTypeArguments();
+ numOfActualTypes = actualTypes.length;
+ actualTypeName = actualTypes[0].getName();
+ }
+ }
+ }
+ assertNotNull("The method 'getLf' wasn't found", typeName);
+ assertEquals("Return type has incorrect name", "Class", typeName);
+ assertEquals("Incorrect number of type parameters", 1, numOfActualTypes);
+ assertEquals("Return type has incorrect actual parameter", "SomeIdentity", actualTypeName);
+
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.sal.binding.yang.types;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class NodeWrappedTypeTest {
+
+ @Test
+ public void test() {
+ NodeWrappedType nwt1 = new NodeWrappedType("obj1");
+ NodeWrappedType nwt2 = new NodeWrappedType("obj2");
+ NodeWrappedType nwt3 = new NodeWrappedType("obj1");
+ String str = "obj3";
+
+ assertTrue("Node nwt1 should equal to itself.", nwt1.equals(nwt1));
+ assertFalse("It can't be possible to compare nwt with string.", nwt1.equals(str));
+ assertFalse("nwt1 shouldn't equal to nwt2.", nwt1.equals(nwt2));
+ assertTrue("Node nwt1 should equal to nwt3.", nwt1.equals(nwt3));
+
+ assertEquals("toString method is returning incorrect value.", "NodeWrappedType{wrappedType=obj1}",
+ nwt1.toString());
+ }
+}
--- /dev/null
+module module-identityref {
+
+ namespace "urn:identityref:module";
+ prefix "sbd";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-11-09 {
+ }
+
+ identity some-identity {
+ }
+
+ leaf lf {
+ type identityref {
+ base "some-identity";
+ }
+ }
+}
\ No newline at end of file
this.qname = qname;\r
}\r
\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = super.hashCode();\r
+ result = prime * result + ((parent == null) ? 0 : parent.hashCode());\r
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj) {\r
+ return true;\r
+ }\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ if (getClass() != obj.getClass()) {\r
+ return false;\r
+ }\r
+ if (!super.equals(obj)) {\r
+ return false;\r
+ }\r
+ AbstractSchemaNodeBuilder other = (AbstractSchemaNodeBuilder) obj;\r
+ if (parent == null) {\r
+ if (other.parent != null) {\r
+ return false;\r
+ }\r
+ } else if (!parent.equals(other.parent)) {\r
+ return false;\r
+ }\r
+ if (schemaPath == null) {\r
+ if (other.schemaPath != null) {\r
+ return false;\r
+ }\r
+ } else if (!schemaPath.equals(other.schemaPath)) {\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
public QName getQName() {\r
return qname;\r
}\r
return "grouping " + qname.getLocalName();
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ final GroupingBuilderImpl other = (GroupingBuilderImpl) obj;
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (!parent.equals(other.parent)) {
+ return false;
+ }
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ return true;
+ }
+
+
private final class GroupingDefinitionImpl implements GroupingDefinition {
private final QName qname;
private SchemaPath path;
// identifier namespace.
for (DataSchemaNodeBuilder childNode : addedChildNodes) {
if (childNode.getQName().getLocalName().equals(childName)) {
- raiseYangParserException("'"+child+"'", "node", childName, lineNum, childNode.getLine());
+ raiseYangParserException("'" + child + "'", "node", childName, lineNum, childNode.getLine());
}
}
for (RpcDefinitionBuilder rpc : addedRpcs) {
if (rpc.getQName().getLocalName().equals(childName)) {
- raiseYangParserException("'"+child+"'", "rpc", childName, lineNum, rpc.getLine());
+ raiseYangParserException("'" + child + "'", "rpc", childName, lineNum, rpc.getLine());
}
}
for (NotificationBuilder notification : addedNotifications) {
if (notification.getQName().getLocalName().equals(childName)) {
- raiseYangParserException("'"+child+"'", "notification", childName, lineNum, notification.getLine());
+ raiseYangParserException("'" + child + "'", "notification", childName, lineNum, notification.getLine());
}
}
addedChildNodes.add(child);
DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
for (DataSchemaNodeBuilder childNode : parentNode.getChildNodeBuilders()) {
if (childNode.getQName().getLocalName().equals(childName)) {
- raiseYangParserException("'"+child+"'", "node", childName, lineNum, childNode.getLine());
+ raiseYangParserException("'" + child + "'", "node", childName, lineNum, childNode.getLine());
}
}
parentNode.addChildNode(child);
ChoiceBuilder parentNode = (ChoiceBuilder) parent;
for (ChoiceCaseBuilder caseBuilder : parentNode.getCases()) {
if (caseBuilder.getQName().getLocalName().equals(childName)) {
- raiseYangParserException("'"+child+"'", "node", childName, lineNum, caseBuilder.getLine());
+ raiseYangParserException("'" + child + "'", "node", childName, lineNum, caseBuilder.getLine());
}
}
parentNode.addCase(child);
duplicateLine);
throw new YangParseException(moduleName, currentLine, msg);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+ result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+ result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ModuleBuilder other = (ModuleBuilder) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (namespace == null) {
+ if (other.namespace != null) {
+ return false;
+ }
+ } else if (!namespace.equals(other.namespace)) {
+ return false;
+ }
+ if (prefix == null) {
+ if (other.prefix != null) {
+ return false;
+ }
+ } else if (!prefix.equals(other.prefix)) {
+ return false;
+ }
+ if (revision == null) {
+ if (other.revision != null) {
+ return false;
+ }
+ } else if (!revision.equals(other.revision)) {
+ return false;
+ }
+ return true;
+ }
+
}
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.UnknownType;
+import org.opendaylight.yangtools.yang.parser.builder.api.AbstractBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.AbstractTypeAwareBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.yangtools.yang.parser.util.Comparators;
return "typedef " + qname.getLocalName();
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ TypeDefinitionBuilderImpl other = (TypeDefinitionBuilderImpl) obj;
+
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+
+ return true;
+ }
+
}
instance = new UnknownSchemaNodeImpl(qname);
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
+ result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ UnknownSchemaNodeBuilder other = (UnknownSchemaNodeBuilder) obj;
+ if (qname == null) {
+ if (other.qname != null) {
+ return false;
+ }
+ } else if (!qname.equals(other.qname)) {
+ return false;
+ }
+ if (schemaPath == null) {
+ if (other.schemaPath != null) {
+ return false;
+ }
+ } else if (!schemaPath.equals(other.schemaPath)) {
+ return false;
+ }
+ if (nodeType == null) {
+ if (other.nodeType != null) {
+ return false;
+ }
+ } else if (!nodeType.equals(other.nodeType)) {
+ return false;
+ }
+ if (nodeParameter == null) {
+ if (other.nodeParameter != null) {
+ return false;
+ }
+ } else if (!nodeParameter.equals(other.nodeParameter)) {
+ return false;
+ }
+ return true;
+ }
+
@Override
public UnknownSchemaNode build() {
if (!isBuilt) {
sb.append(nodeParameter);
return sb.toString();
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
+ result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ UnknownSchemaNodeImpl other = (UnknownSchemaNodeImpl) obj;
+ if (qname == null) {
+ if (other.qname != null) {
+ return false;
+ }
+ } else if (!qname.equals(other.qname)) {
+ return false;
+ }
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ if (nodeType == null) {
+ if (other.nodeType != null) {
+ return false;
+ }
+ } else if (!nodeType.equals(other.nodeType)) {
+ return false;
+ }
+ if (nodeParameter == null) {
+ if (other.nodeParameter != null) {
+ return false;
+ }
+ } else if (!nodeParameter.equals(other.nodeParameter)) {
+ return false;
+ }
+ return true;
+ }
+
}
}
private final Status status;
private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
- BitImpl(final Long position, final QName qname,
- final SchemaPath schemaPath, final String description,
- final String reference, final Status status,
- final List<UnknownSchemaNode> unknownNodes) {
+ BitImpl(final Long position, final QName qname, final SchemaPath schemaPath, final String description,
+ final String reference, final Status status, final List<UnknownSchemaNode> unknownNodes) {
this.position = position;
this.qname = qname;
this.schemaPath = schemaPath;
this.description = description;
this.reference = reference;
this.status = status;
- if(unknownNodes != null) {
+ if (unknownNodes != null) {
this.unknownNodes = unknownNodes;
}
}
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((qname == null) ? 0 : qname.hashCode());
- result = prime * result
- + ((schemaPath == null) ? 0 : schemaPath.hashCode());
- result = prime * result
- + ((position == null) ? 0 : position.hashCode());
- result = prime
- * result
- + ((unknownNodes == null) ? 0 : unknownNodes.hashCode());
+ result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ result = prime * result + ((position == null) ? 0 : position.hashCode());
+ result = prime * result + ((unknownNodes == null) ? 0 : unknownNodes.hashCode());
return result;
}
@Override
public String toString() {
- return Bit.class.getSimpleName() + "[name="
- + qname.getLocalName() + ", position=" + position + "]";
+ return Bit.class.getSimpleName() + "[name=" + qname.getLocalName() + ", position=" + position + "]";
}
}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.util;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+
+public class BitImplTest {
+
+ @Test
+ public void test() {
+
+ // hashCode method test
+ URI uriA = null;
+ URI uriA1 = null;
+ URI uriA2 = null;
+ URI uriB = null;
+ URI uriB1 = null;
+ URI uriB2 = null;
+ boolean urisInitiallized = false;
+ try {
+ uriA = new URI("some:uriA");
+ uriA1 = new URI("some:uriA1");
+ uriA2 = new URI("some:uriA2");
+ uriB = new URI("some:uriB");
+ uriB1 = new URI("some:uriB1");
+ uriB2 = new URI("some:uriB2");
+ urisInitiallized = true;
+
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ assertTrue("Not all required uri variables were instantiated.", urisInitiallized);
+
+ }
+ QName qnameA = new QName(uriA, new Date(5000000), "some name");
+
+ QName qnameA1 = new QName(uriA1, new Date(6000000), "some nameA1");
+ QName qnameA2 = new QName(uriA2, new Date(7000000), "some nameA2");
+ List<QName> qnamesA = new ArrayList<>();
+ qnamesA.add(qnameA1);
+ qnamesA.add(qnameA2);
+ SchemaPath schemaPathA = new SchemaPath(qnamesA, true);
+
+ QName qnameB = new QName(uriB, new Date(5000000), "some name");
+
+ QName qnameB1 = new QName(uriB1, new Date(6000000), "some nameB1");
+ QName qnameB2 = new QName(uriB2, new Date(7000000), "some nameB2");
+ List<QName> qnamesB = new ArrayList<>();
+ qnamesB.add(qnameB1);
+ qnamesB.add(qnameB2);
+ SchemaPath schemaPathB = new SchemaPath(qnamesB, true);
+
+ BitImpl biB = null;
+ BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
+
+ assertEquals("biA should equals to itsefl", biA, biA);
+ assertFalse("biA shouldn't equal to null", biA.equals(null));
+ assertFalse("biA shouldn't equal to object of other type", biA.equals(new String("str")));
+
+ // test of equals method
+ // // test qname
+ biA = new BitImpl(55L, null, schemaPathA, "description", "reference", Status.CURRENT, null);
+ biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
+ assertFalse("biA shouldn't equal to biB", biA.equals(biB));
+
+ biA = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
+ biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
+ assertEquals("biA should equal to biB", biA, biB);
+
+ biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
+ biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
+ assertFalse("biA shouldn't equal to biB", biA.equals(biB));
+
+ // // test schemaPath
+ biA = new BitImpl(55L, qnameA, null, "description", "reference", Status.CURRENT, null);
+ biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
+ assertFalse("biA shouldn't equal to biB", biA.equals(biB));
+
+ biA = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
+ biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
+ assertEquals("biA should equal to biB", biA, biB);
+
+ biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
+ biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
+ assertFalse("biA shouldn't equal to biB", biA.equals(biB));
+
+ biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
+ biB = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
+ assertEquals("biA should equal to biB", biA, biB);
+
+ // test of hashCode method
+ biA = new BitImpl(null, null, null, "description", "reference", Status.CURRENT, null);
+ assertEquals("Incorrect hash code for biA.", 923522, biA.hashCode());
+
+ List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
+ UnknownSchemaNodeBuilder usnb = new UnknownSchemaNodeBuilder("module", 3, qnameB);
+ unknownNodes.add(usnb.build());
+
+ biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, unknownNodes);
+
+ // test of getter methods
+ assertEquals("Incorrect value for qname.", qnameA, biA.getQName());
+ assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
+ assertEquals("Incorrect value for description.", "description", biA.getDescription());
+ assertEquals("Incorrect value for reference.", "reference", biA.getReference());
+ assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
+ assertEquals("Incorrect value for unknown nodes.", unknownNodes, biA.getUnknownSchemaNodes());
+
+ // test of toString method
+ assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());
+
+ }
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+public class MustDefinitionImplTest {
+
+ @Test
+ public void test() {
+ MustDefinitionImpl mdiA;
+ MustDefinitionImpl mdiB;
+ mdiA = new MustDefinitionImpl("mustStrA", "descriptionA", "referenceA", "errorAppTagA", "errorMessageA");
+
+ assertEquals("mdiA should equals to itsefl", mdiA, mdiA);
+ assertFalse("mdiA shouldn't equal to null", mdiA.equals(null));
+ assertFalse("mdiA shouldn't equal to object of other type", mdiA.equals(new String("str")));
+
+ // test of equals method
+
+ // //confirmation of equality
+ mdiA = new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage");
+ mdiB = new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage");
+ assertEquals("mdiA should equal to mdiB", mdiA, mdiB);
+
+ // // mustStr
+ mdiA = new MustDefinitionImpl(null, "description", "reference", "errorAppTag", "errorMessage");
+ mdiB = new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage");
+ assertFalse("mdiA shouldn't equal to mdiB", mdiA.equals(mdiB));
+
+ mdiA = new MustDefinitionImpl("mustStrA", "description", "reference", "errorAppTag", "errorMessage");
+ mdiB = new MustDefinitionImpl("mustStrB", "description", "reference", "errorAppTag", "errorMessage");
+ assertFalse("mdiA shouldn't equal to mdiB", mdiA.equals(mdiB));
+
+ // //description
+ mdiA = new MustDefinitionImpl("mustStr", null, "reference", "errorAppTag", "errorMessage");
+ mdiB = new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage");
+ assertFalse("mdiA shouldn't equal to mdiB", mdiA.equals(mdiB));
+
+ mdiA = new MustDefinitionImpl("mustStr", "descriptionA", "reference", "errorAppTag", "errorMessage");
+ mdiB = new MustDefinitionImpl("mustStr", "descriptionB", "reference", "errorAppTag", "errorMessage");
+ assertFalse("mdiA shouldn't equal to mdiB", mdiA.equals(mdiB));
+
+ // //reference
+ mdiA = new MustDefinitionImpl("mustStr", "description", null, "errorAppTag", "errorMessage");
+ mdiB = new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage");
+ assertFalse("mdiA shouldn't equal to mdiB", mdiA.equals(mdiB));
+
+ mdiA = new MustDefinitionImpl("mustStr", "description", "referenceA", "errorAppTag", "errorMessage");
+ mdiB = new MustDefinitionImpl("mustStr", "description", "referenceB", "errorAppTag", "errorMessage");
+ assertFalse("mdiA shouldn't equal to mdiB", mdiA.equals(mdiB));
+
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.util;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+
+public class RefineHolderTest {
+
+ private RefineHolder rh;
+ private RefineHolder rh1;
+
+ @Before
+ public void init() {
+ rh = new RefineHolder("module", 2104, "name");
+ rh1 = new RefineHolder("module", 2104, "name");
+ }
+
+
+
+ @Test
+ public void testRefineEquality() {
+ // hashCode method test
+ assertEquals("rh should equals to itsefl", rh, rh);
+ assertFalse("rh shouldn't equal to null", rh.equals(null));
+ assertFalse("rh shouldn't equal to object of other type", rh.equals(new String("str")));
+
+ assertEquals("rh1 should equals to rh", rh, rh1);
+
+ RefineHolder rh2 = new RefineHolder("module", 2104, null);
+ assertFalse("rh shouldn't equal to rh2", rh2.equals(rh1));
+ rh2 = new RefineHolder("module", 2104, "name2");
+ assertFalse("rh shouldn't equal to rh2", rh.equals(rh2));
+
+ assertEquals("Wrong hash code", 1557537141, rh.hashCode());
+ }
+
+ @Test
+ public void testConfigurationEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setConfiguration(false);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setConfiguration(false);
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setConfiguration(true);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setConfiguration(true);
+ }
+
+ @Test
+ public void testDefaultStrEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setDefaultStr("default string1");
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setDefaultStr("default string1");
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setDefaultStr("default string");
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setDefaultStr("default string");
+ }
+
+ @Test
+ public void testDescriptionEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setDescription("description1");
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setDescription("description1");
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setDescription("description");
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setDescription("description");
+ }
+
+ @Test
+ public void testMandatoryEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setMandatory(false);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setMandatory(false);
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setMandatory(true);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setMandatory(true);
+ }
+
+ @Test
+ public void testMaxElementsEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setMaxElements(5400);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setMaxElements(5400);
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setMaxElements(5435);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setMaxElements(5435);
+ }
+
+ @Test
+ public void testMinElementsEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setMinElements(16);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setMinElements(16);
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setMinElements(159);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setMinElements(159);
+ }
+
+ @Test
+ public void testMustEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setMust(new MustDefinitionImpl("mustStr1", "description1", "reference1", "errorAppTag1", "errorMessage1"));
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setMust(new MustDefinitionImpl("mustStr1", "description1", "reference1", "errorAppTag1", "errorMessage1"));
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setMust(new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage"));
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setMust(new MustDefinitionImpl("mustStr", "description", "reference", "errorAppTag", "errorMessage"));
+ }
+
+ @Test
+ public void testPresenceEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setPresence(false);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setPresence(false);
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setPresence(true);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setPresence(true);
+ }
+
+ @Test
+ public void testReferenceEqualsBranch() {
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setReference("reference1");
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setReference("reference1");
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setReference("reference");
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setReference("reference");
+ }
+
+ private URI getUri(String uri) {
+ URI simpleUri = null;
+ boolean instantionated = false;
+ try {
+ simpleUri = new URI(uri);
+ instantionated = true;
+ } catch (URISyntaxException e1) {
+ e1.printStackTrace();
+ assertTrue("Uri instance wasn't created.", instantionated);
+ }
+ return simpleUri;
+ }
+
+ @Test
+ public void testAddUnknownNodeBuilderEqualsBranch() {
+ URI simpleUri = null;
+ simpleUri = getUri("very:simple:URI");
+ assertNotNull("URI can't be null", simpleUri);
+
+ UnknownSchemaNodeBuilder usnb = new UnknownSchemaNodeBuilder("usnb", 151, new QName(simpleUri, "tst"));
+ UnknownSchemaNodeBuilder usnb1 = new UnknownSchemaNodeBuilder("usnb", 151, new QName(simpleUri, "tst"));
+
+ URI uriA = getUri("some:uriA");
+ assertNotNull("URI can't be null", simpleUri);
+ QName qnameA = new QName(uriA, new Date(5000000), "some nameA");
+ QName qnameB = new QName(uriA, new Date(6000000), "some nameB");
+ List<QName> qnamesA = new ArrayList<>();
+ List<QName> qnamesB = new ArrayList<>();
+ qnamesA.add(qnameA);
+ qnamesB.add(qnameB);
+ SchemaPath schemaPathA = new SchemaPath(qnamesA, true);
+ SchemaPath schemaPathB = new SchemaPath(qnamesB, true);
+
+ usnb.setPath(schemaPathB);
+ usnb1.setPath(schemaPathB);
+
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.addUnknownNodeBuilder(usnb);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.addUnknownNodeBuilder(usnb1);
+ assertEquals("rh should equal to rh1", rh, rh1);
+ usnb.setPath(schemaPathA);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ usnb1.setPath(schemaPathA);
+ }
+
+ @Test
+ public void testParentEqualsBranch() {
+ URI simpleUriA = getUri("very:simple:URI:a");
+ URI simpleUriB = getUri("very:simple:URI:b");
+
+ UnknownSchemaNodeBuilder usnbA = new UnknownSchemaNodeBuilder("usnbA", 151, new QName(simpleUriA, "tst"));
+ UnknownSchemaNodeBuilder usnbB = new UnknownSchemaNodeBuilder("usnbB", 151, new QName(simpleUriB, "tst"));
+ UnknownSchemaNodeBuilder usnbAParent = new UnknownSchemaNodeBuilder("usnbAParent", 151, new QName(simpleUriA,
+ "tst"));
+ usnbA.setParent(usnbAParent);
+
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh1.setParent(usnbB);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh.setParent(usnbB);
+ assertEquals("rh should equal to rh1", rh, rh1);
+ rh.setParent(usnbA);
+ assertFalse("rh shouldn't equal to rh1", rh.equals(rh1));
+ rh1.setParent(usnbA);
+
+ assertEquals("rh should equal to rh1", rh, rh1);
+ }
+
+}