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.model.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.Collections;
18 import java.util.Date;
19 import java.util.List;
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.api.Status;
26 public class BitImplTest {
31 // hashCode method test
38 boolean urisInitiallized = false;
40 uriA = new URI("some:uriA");
41 uriA1 = new URI("some:uriA1");
42 uriA2 = new URI("some:uriA2");
43 uriB = new URI("some:uriB");
44 uriB1 = new URI("some:uriB1");
45 uriB2 = new URI("some:uriB2");
46 urisInitiallized = true;
48 } catch (URISyntaxException e) {
50 assertTrue("Not all required uri variables were instantiated.", urisInitiallized);
53 QName qnameA = QName.create(uriA, new Date(5000000), "some name");
55 QName qnameA1 = QName.create(uriA1, new Date(6000000), "some nameA1");
56 QName qnameA2 = QName.create(uriA2, new Date(7000000), "some nameA2");
57 List<QName> qnamesA = new ArrayList<>();
60 SchemaPath schemaPathA = SchemaPath.create(qnamesA, true);
62 QName qnameB = QName.create(uriB, new Date(5000000), "some name");
64 QName qnameB1 = QName.create(uriB1, new Date(6000000), "some nameB1");
65 QName qnameB2 = QName.create(uriB2, new Date(7000000), "some nameB2");
66 List<QName> qnamesB = new ArrayList<>();
69 SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
72 BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
74 assertEquals("biA should equals to itsefl", biA, biA);
75 assertFalse("biA shouldn't equal to null", biA.equals(null));
76 assertFalse("biA shouldn't equal to object of other type", biA.equals(new String("str")));
78 biA = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
79 biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
80 assertEquals("biA should equal to biB", biA, biB);
82 biA = new BitImpl(55L, qnameA, 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));
87 biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
88 biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
89 assertFalse("biA shouldn't equal to biB", biA.equals(biB));
91 biA = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
92 biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
93 assertEquals("biA should equal to biB", biA, biB);
95 biA = new BitImpl(55L, qnameA, schemaPathA, "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, schemaPathA, "description", "reference", Status.CURRENT, null);
100 biB = new BitImpl(55L, qnameA, schemaPathA, "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);
105 // test of getter methods
106 assertEquals("Incorrect value for qname.", qnameA, biA.getQName());
107 assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
108 assertEquals("Incorrect value for description.", "description", biA.getDescription());
109 assertEquals("Incorrect value for reference.", "reference", biA.getReference());
110 assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
111 assertEquals("Incorrect value for unknown nodes.", Collections.emptyList(), biA.getUnknownSchemaNodes());
113 // test of toString method
114 assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());