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.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
22 public class Mdsal406TypeObjectTest {
25 public void typeObjectTest() {
26 final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
27 "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
29 final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
30 assertNotNull(generateTypes);
32 final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
33 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBinary")).findFirst().get();
35 assertTrue(typedefType instanceof GeneratedType);
36 assertNotNull(((GeneratedType) typedefType).getImplements());
37 Type objectType = ((GeneratedType) typedefType).getImplements().stream()
38 .filter(type -> type.getFullyQualifiedName()
39 .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
40 assertEquals(TYPE_OBJECT, objectType);
44 public void typeObjectForBitsTypedefTest() {
45 final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
46 "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
48 final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
49 assertNotNull(generateTypes);
51 final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
52 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBits")).findFirst().get();
54 assertTrue(typedefType instanceof GeneratedType);
55 assertNotNull(((GeneratedType) typedefType).getImplements());
56 Type objectType = ((GeneratedType) typedefType).getImplements().stream()
57 .filter(type -> type.getFullyQualifiedName()
58 .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
59 assertEquals(TYPE_OBJECT, objectType);
63 public void typeObjectForUnionTypedefTest() {
64 final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
65 "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
67 final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
68 assertNotNull(generateTypes);
70 final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
71 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyUnion")).findFirst().get();
73 assertTrue(typedefType instanceof GeneratedType);
74 assertNotNull(((GeneratedType) typedefType).getImplements());
75 Type objectType = ((GeneratedType) typedefType).getImplements().stream()
76 .filter(type -> type.getFullyQualifiedName()
77 .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
78 assertEquals(TYPE_OBJECT, objectType);