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 org.junit.Test;
11 import org.opendaylight.yangtools.yang.model.api.Status;
12 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.ArrayList;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.assertFalse;
23 public class UnionTypeTest {
26 public void canCreateUnion() {
27 List<TypeDefinition<?>> listTypes = new ArrayList<>();
28 Int32 int32 = Int32.getInstance();
30 UnionType unionType = UnionType.create(listTypes);
32 assertEquals("GetUnits should be null", null, unionType.getUnits());
33 assertTrue("String should contain int32", unionType.toString().contains("int32"));
34 assertEquals("Should be empty list", Collections.EMPTY_LIST, unionType.getUnknownSchemaNodes());
35 assertNotEquals("Description should not be null", null, unionType.getDescription());
36 assertNotEquals("Ref should not be null", null, unionType.getReference());
37 assertEquals("Should be CURRENT", Status.CURRENT, unionType.getStatus());
38 assertEquals("Should be int32 in list", Collections.singletonList(int32), unionType.getTypes());
39 assertEquals("Base type should be null", null, unionType.getBaseType());
40 assertEquals("Default value should be null", null, unionType.getDefaultValue());
41 assertEquals("Should be same as list of BaseTypes",
42 Collections.singletonList(BaseTypes.UNION_QNAME), unionType.getPath().getPathFromRoot());
43 assertEquals("Should be BaseTypes", BaseTypes.UNION_QNAME, unionType.getQName());
45 assertEquals("unionType should equals to itself", unionType, unionType);
46 assertFalse("unionType shouldn't equal to null", unionType.equals(null));
47 assertTrue("Hash code of unionType should be equal to itself",
48 unionType.hashCode() == unionType.hashCode());