2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.mdsal.binding.generator.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.opendaylight.mdsal.binding.model.util.BindingTypes.TYPE_OBJECT;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.mdsal.binding.model.util.BindingTypes;
20 import org.opendaylight.mdsal.binding.model.util.Types;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class Mdsal406TypeObjectTest {
25 public void typeObjectTest() {
26 final List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
27 ExtendedTypedefTest.class, "/type-provider/test.yang", "/ietf/ietf-inet-types.yang"));
28 assertNotNull(generateTypes);
30 final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
31 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBinary")).findFirst().get();
33 assertTrue(typedefType instanceof GeneratedType);
34 assertNotNull(((GeneratedType) typedefType).getImplements());
35 Type objectType = ((GeneratedType) typedefType).getImplements().stream()
36 .filter(type -> type.getFullyQualifiedName()
37 .equals("org.opendaylight.yangtools.yang.binding.ScalarTypeObject")).findAny().get();
38 assertEquals(BindingTypes.scalarTypeObject(Types.BYTE_ARRAY), objectType);
42 public void typeObjectForBitsTypedefTest() {
43 final List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
44 ExtendedTypedefTest.class, "/type-provider/test.yang", "/ietf/ietf-inet-types.yang"));
45 assertNotNull(generateTypes);
47 final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
48 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBits")).findFirst().get();
50 assertTrue(typedefType instanceof GeneratedType);
51 assertNotNull(((GeneratedType) typedefType).getImplements());
52 Type objectType = ((GeneratedType) typedefType).getImplements().stream()
53 .filter(type -> type.getFullyQualifiedName()
54 .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
55 assertEquals(TYPE_OBJECT, objectType);
59 public void typeObjectForUnionTypedefTest() {
60 final List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
61 ExtendedTypedefTest.class, "/type-provider/test.yang", "/ietf/ietf-inet-types.yang"));
62 assertNotNull(generateTypes);
64 final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
65 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyUnion")).findFirst().get();
67 assertTrue(typedefType instanceof GeneratedType);
68 assertNotNull(((GeneratedType) typedefType).getImplements());
69 Type objectType = ((GeneratedType) typedefType).getImplements().stream()
70 .filter(type -> type.getFullyQualifiedName()
71 .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
72 assertEquals(TYPE_OBJECT, objectType);