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.assertTrue;
15 import java.net.URISyntaxException;
16 import java.util.ArrayList;
17 import java.util.Date;
18 import java.util.List;
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;
28 public class BitImplTest {
33 // hashCode method test
40 boolean urisInitiallized = false;
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;
50 } catch (URISyntaxException e) {
52 assertTrue("Not all required uri variables were instantiated.", urisInitiallized);
55 QName qnameA = new QName(uriA, new Date(5000000), "some name");
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<>();
62 SchemaPath schemaPathA = SchemaPath.create(qnamesA, true);
64 QName qnameB = new QName(uriB, new Date(5000000), "some name");
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<>();
71 SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
74 BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
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")));
80 // test of equals method
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));
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);
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));
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));
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);
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));
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);
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());
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);
121 unknownNodes.add(usnb.build());
123 biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, unknownNodes);
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());
133 // test of toString method
134 assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());