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 com.google.common.base.Optional;
11 import org.junit.Test;
12 import org.mockito.Mock;
13 import org.mockito.MockitoAnnotations;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
19 import java.util.Collections;
20 import java.util.List;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotEquals;
25 public class EnumerationTypeTest {
27 @Mock private EnumTypeDefinition.EnumPair enumPair;
30 public void canCreateEnumerationType(){
31 MockitoAnnotations.initMocks(this);
33 QName qName = QName.create("TestQName");
34 SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
36 List<EnumTypeDefinition.EnumPair> listEnumPair = Collections.singletonList(enumPair);
37 Optional<EnumTypeDefinition.EnumPair> defaultValue = Optional.of(enumPair);
39 EnumerationType enumerationType = EnumerationType.create(schemaPath, listEnumPair, defaultValue);
41 assertNotEquals("Description is not null", null, enumerationType.getDescription());
42 assertEquals("QName", BaseTypes.ENUMERATION_QNAME, enumerationType.getQName());
43 assertEquals("Should be empty string", "", enumerationType.getUnits());
44 assertNotEquals("Description should not be null", null, enumerationType.toString());
45 assertNotEquals("Reference is not null", null, enumerationType.getReference());
46 assertEquals("BaseType should be null", null, enumerationType.getBaseType());
47 assertEquals("Default value should be enumPair", enumPair, enumerationType.getDefaultValue());
48 assertEquals("getPath should equal schemaPath", schemaPath, enumerationType.getPath());
49 assertEquals("Status should be CURRENT", Status.CURRENT, enumerationType.getStatus());
50 assertEquals("Should be empty list", Collections.EMPTY_LIST, enumerationType.getUnknownSchemaNodes());
51 assertEquals("Values should be [enumPair]", listEnumPair, enumerationType.getValues());
53 assertEquals("Hash code of enumerationType should be equal",
54 enumerationType.hashCode(), enumerationType.hashCode());
55 assertNotEquals("EnumerationType shouldn't equal to null", null, enumerationType);
56 assertEquals("EnumerationType should equals to itself", enumerationType, enumerationType);
57 assertNotEquals("EnumerationType shouldn't equal to object of other type", "str", enumerationType);