Bug 6134: Introducing of DataTreeConfiguration concept
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / ExtendedTypeTest.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 static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import com.google.common.base.Optional;
14 import java.util.Collections;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.Status;
19 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
21 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
22
23 public class ExtendedTypeTest {
24     @Test
25     public void canCreateExtendedType() {
26         String namespace = "TestType";
27         String revision = "2014-08-26";
28         String localName = "testType";
29         QName testType = QName.create(namespace, revision, localName);
30         IntegerTypeDefinition int32 = BaseTypes.int32Type();
31         String description = "This type is used for testing purpose";
32         Optional<String> desc = Optional.of(description);
33         String reference = "Test Reference";
34         Optional<String> ref = Optional.of(reference);
35
36         ExtendedType.Builder extendedTypeBuilder = ExtendedType.builder(testType, int32, desc, ref, SchemaPath.ROOT);
37
38         int defValue = 12;
39         extendedTypeBuilder.defaultValue(defValue);
40
41         extendedTypeBuilder.status(Status.OBSOLETE);
42         extendedTypeBuilder.addedByUses(false);
43
44         int digits = 2;
45         extendedTypeBuilder.fractionDigits(digits);
46
47         String units = "KiloTest";
48         extendedTypeBuilder.units(units);
49
50         Number min = 3;
51         Number max = 15;
52         LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, desc, ref);
53         extendedTypeBuilder.lengths(Collections.singletonList(lengthCons));
54
55         ExtendedType extendedType = extendedTypeBuilder.build();
56
57         assertEquals("BaseType is int32", int32, extendedType.getBaseType());
58         assertEquals("Description", description, extendedType.getDescription());
59         assertEquals("Reference", reference, extendedType.getReference());
60         assertEquals("Path", SchemaPath.ROOT, extendedType.getPath());
61         assertEquals("Default Value is 12", defValue, extendedType.getDefaultValue());
62         assertEquals("Status is OBSOLETE", Status.OBSOLETE, extendedType.getStatus());
63         assertFalse("AddedByUses", extendedType.isAddedByUses());
64         assertTrue("should be 2", digits == extendedType.getFractionDigits());
65         assertTrue("Should contain description", extendedType.toString().contains(description));
66         assertEquals("Units", units, extendedType.getUnits());
67         assertEquals("Length Constraints", Collections.singletonList(lengthCons), extendedType.getLengthConstraints());
68         assertTrue("Should contain name of type", extendedType.getQName().toString().contains(localName));
69
70         assertEquals("extendedType should equals to itself",extendedType, extendedType);
71         assertFalse("extendedType shouldn't equal to null", extendedType.equals(null));
72         assertTrue("Hash code of unionType should be equal to itself",
73                 extendedType.hashCode() == extendedType.hashCode());
74
75     }
76
77 }