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.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.Iterator;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
20 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
21 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
22 import org.opendaylight.mdsal.binding.model.api.Type;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class Mdsal320Test {
29 public void mdsal320Test() {
30 final SchemaContext context = YangParserTestUtils.parseYangResource("/mdsal320.yang");
32 final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
33 assertNotNull(generateTypes);
34 assertEquals(4, generateTypes.size());
36 final Type fooType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
37 .equals("org.opendaylight.yang.gen.v1.urn.odl.yt320.norev.Foo")).findFirst().get();
38 assertTrue(fooType instanceof GeneratedType);
39 final GeneratedType foo = (GeneratedType) fooType;
41 GeneratedTransferObject bar = null;
42 GeneratedTransferObject bar1 = null;
43 for (GeneratedType enc : foo.getEnclosedTypes()) {
44 switch (enc.getName()) {
46 assertTrue(enc instanceof GeneratedTransferObject);
47 bar = (GeneratedTransferObject) enc;
50 assertTrue(enc instanceof GeneratedTransferObject);
51 bar1 = (GeneratedTransferObject) enc;
54 throw new IllegalStateException("Unexpected type " + enc);
58 assertTrue(bar.isUnionType());
60 assertTrue(bar1.isUnionType());
62 final Iterator<MethodSignature> it = foo.getMethodDefinitions().iterator();
63 assertTrue(it.hasNext());
64 final MethodSignature getImplIface = it.next();
65 assertEquals("implementedInterface", getImplIface.getName());
66 assertTrue(getImplIface.isDefault());
67 assertTrue(it.hasNext());
69 final MethodSignature getBar = it.next();
70 assertFalse(it.hasNext());
71 final Type getBarType = getBar.getReturnType();
72 assertTrue(getBarType instanceof GeneratedTransferObject);
73 final GeneratedTransferObject getBarTO = (GeneratedTransferObject) getBarType;
74 assertTrue(getBarTO.isUnionType());
75 assertEquals(bar, getBarTO);
77 final GeneratedProperty bar1Prop = bar.getProperties().stream().filter(prop -> "bar$1".equals(prop.getName()))
79 final Type bar1PropRet = bar1Prop.getReturnType();
80 assertEquals(bar1, bar1PropRet);