2 * Copyright (c) 2013 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 com.google.common.base.Optional;
11 import org.junit.Test;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.Status;
15 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
17 import java.util.Collections;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.assertFalse;
23 public class ExtendedTypeTest {
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 Int32 int32 = Int32.getInstance();
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);
36 ExtendedType.Builder extendedTypeBuilder = ExtendedType.builder(testType, int32, desc, ref, SchemaPath.ROOT);
39 extendedTypeBuilder.defaultValue(defValue);
41 extendedTypeBuilder.status(Status.OBSOLETE);
42 extendedTypeBuilder.addedByUses(false);
45 extendedTypeBuilder.fractionDigits(digits);
47 String units = "KiloTest";
48 extendedTypeBuilder.units(units);
52 LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, desc, ref);
53 extendedTypeBuilder.lengths(Collections.singletonList(lengthCons));
55 ExtendedType extendedType = extendedTypeBuilder.build();
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));
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());