90dd72fd57404307e061e8fb4eab1c251ee4264f
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / BinaryTypeTest.java
1 /*
2  * Copyright (c) 2013 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;
9
10 import org.junit.Test;
11 import org.opendaylight.yangtools.yang.model.api.Status;
12 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
13 import java.util.Collections;
14 import java.util.List;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertTrue;
18 import static org.junit.Assert.assertFalse;
19
20 public class BinaryTypeTest {
21
22     @Test
23     public void canCreateBinaryType() {
24         BinaryType binType = BinaryType.getInstance();
25         BinaryType binType1 = BinaryType.getInstance();
26         String stringBinType = binType.toString();
27
28
29         List<LengthConstraint> lengthConstraints = binType.getLengthConstraints();
30         assertTrue(lengthConstraints.toString().contains("max=9223372036854775807"));
31         assertTrue(lengthConstraints.toString().contains("min=0"));
32
33         assertEquals("Default value is []", Collections.EMPTY_LIST, binType.getDefaultValue());
34         assertEquals("CURRENT", Status.CURRENT, binType.getStatus());
35         assertEquals("Base type is null", null, binType.getBaseType());
36         assertEquals("getQName gives BINARY_QNAME", BaseTypes.BINARY_QNAME, binType.getQName());
37         assertEquals("empty string", "", binType.getUnits());
38         assertEquals("getPath gives List of BINARY_QNAME",
39                 Collections.singletonList(BaseTypes.BINARY_QNAME), binType.getPath().getPathFromRoot());
40
41         assertTrue("BinType.toString should contain Description", stringBinType.contains(binType.getDescription()));
42         assertTrue("BinType.toString should contain Reference", stringBinType.contains(binType.getReference()));
43
44         assertTrue("binType1 should equal to binType",
45                 binType.equals(binType1) && binType1.equals(binType));
46         assertTrue("Hash code of binType and binType1 should be equal",
47                 binType.hashCode() == binType1.hashCode());
48         assertEquals("binType should equals to itself", binType, binType);
49         assertFalse("binType shouldn't equal to null", binType.equals(null));
50         assertFalse("binType shouldn't equal to object of other type", binType.equals("str"));
51     }
52
53 }