Merge branch 'master' of ../controller
[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 java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.Revision;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.Status;
22
23 public class BitImplTest {
24
25     @Test
26     // We're testing equals()
27     @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
28     public void test() throws URISyntaxException {
29
30         // hashCode method test
31         final URI uriA1 = new URI("some:uriA1");
32         final URI uriA2 = new URI("some:uriA2");
33         final URI uriB1 = new URI("some:uriB1");
34         final URI uriB2 = new URI("some:uriB2");
35
36         QName qnameA1 = QName.create(uriA1, Revision.of("2000-01-01"), "someNameA1");
37         QName qnameA2 = QName.create(uriA2, Revision.of("2002-01-01"), "someNameA2");
38         SchemaPath schemaPathA = SchemaPath.create(true, qnameA1, qnameA2);
39
40         final QName qnameB1 = QName.create(uriB1, Revision.of("2000-01-01"), "someNameB1");
41         final QName qnameB2 = QName.create(uriB2, Revision.of("2002-01-01"), "someNameB2");
42         final SchemaPath schemaPathB = SchemaPath.create(true, qnameB1, qnameB2);
43
44         BitImpl biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
45
46         assertEquals("biA should equals to itsefl", biA, biA);
47         assertFalse("biA shouldn't equal to null", biA.equals(null));
48         assertFalse("biA shouldn't equal to object of other type", biA.equals("str"));
49
50          // // test schemaPath
51         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
52         BitImpl biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
53         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
54
55         biA = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
56         biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
57         assertEquals("biA should equal to biB", biA, biB);
58
59         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
60         biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
61         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
62
63         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
64         biB = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
65         assertEquals("biA should equal to biB", biA, biB);
66
67         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
68
69         // test of getter methods
70         assertEquals("Incorrect value for qname.", qnameA2, biA.getQName());
71         assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
72         assertEquals("Incorrect value for description.", Optional.of("description"), biA.getDescription());
73         assertEquals("Incorrect value for reference.", Optional.of("reference"), biA.getReference());
74         assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
75         assertEquals("Incorrect value for unknown nodes.", emptyList(), biA.getUnknownSchemaNodes());
76
77         // test of toString method
78         assertEquals("toString method doesn't return correct value", "Bit[name=someNameA2, position=55]",
79                 biA.toString());
80     }
81 }