ee31351087f44dcb29a9f010a9575fd7ce19188f
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / type / BitImplTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util.type;
9
10 import static java.util.Collections.emptyList;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13
14 import java.net.URI;
15 import java.net.URISyntaxException;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.Status;
21
22 public class BitImplTest {
23
24     @Test
25     // We're testing equals()
26     @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
27     public void test() throws URISyntaxException {
28
29         // hashCode method test
30         final URI uriA1 = new URI("some:uriA1");
31         final URI uriA2 = new URI("some:uriA2");
32         final URI uriB1 = new URI("some:uriB1");
33         final URI uriB2 = new URI("some:uriB2");
34
35         QName qnameA1 = QName.create(uriA1, Revision.valueOf("2000-01-01"), "some nameA1");
36         QName qnameA2 = QName.create(uriA2, Revision.valueOf("2002-01-01"), "some nameA2");
37         SchemaPath schemaPathA = SchemaPath.create(true, qnameA1, qnameA2);
38
39         final QName qnameB1 = QName.create(uriB1, Revision.valueOf("2000-01-01"), "some nameB1");
40         final QName qnameB2 = QName.create(uriB2, Revision.valueOf("2002-01-01"), "some nameB2");
41         final SchemaPath schemaPathB = SchemaPath.create(true, qnameB1, qnameB2);
42
43         BitImpl biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
44
45         assertEquals("biA should equals to itsefl", biA, biA);
46         assertFalse("biA shouldn't equal to null", biA.equals(null));
47         assertFalse("biA shouldn't equal to object of other type", biA.equals("str"));
48
49          // // test schemaPath
50         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
51         BitImpl biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
52         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
53
54         biA = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
55         biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
56         assertEquals("biA should equal to biB", biA, biB);
57
58         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
59         biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
60         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
61
62         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
63         biB = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
64         assertEquals("biA should equal to biB", biA, biB);
65
66         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
67
68         // test of getter methods
69         assertEquals("Incorrect value for qname.", qnameA2, biA.getQName());
70         assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
71         assertEquals("Incorrect value for description.", "description", biA.getDescription());
72         assertEquals("Incorrect value for reference.", "reference", biA.getReference());
73         assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
74         assertEquals("Incorrect value for unknown nodes.", emptyList(), biA.getUnknownSchemaNodes());
75
76         // test of toString method
77         assertEquals("toString method doesn't return correct value", "Bit[name=some nameA2, position=55]",
78                 biA.toString());
79     }
80 }