Mark typedef types as TypeObject
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / Mdsal406TypeObjectTest.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.generator.impl;
9
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;
14
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;
21
22 public class Mdsal406TypeObjectTest {
23
24     @Test
25     public void typeObjectTest() {
26         final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
27                 "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
28
29         final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
30         assertNotNull(generateTypes);
31
32         final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
33             .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBinary")).findFirst().get();
34
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);
41     }
42
43     @Test
44     public void typeObjectForBitsTypedefTest() {
45         final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
46                 "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
47
48         final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
49         assertNotNull(generateTypes);
50
51         final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
52                 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBits")).findFirst().get();
53
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);
60     }
61
62     @Test
63     public void typeObjectForUnionTypedefTest() {
64         final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
65                 "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
66
67         final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
68         assertNotNull(generateTypes);
69
70         final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
71                 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyUnion")).findFirst().get();
72
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);
79     }
80 }