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;
14 import com.google.common.collect.Iterables;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
20 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
21 import org.opendaylight.mdsal.binding.model.api.Type;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class Mdsal320Test {
28 public void mdsal320Test() {
29 final SchemaContext context = YangParserTestUtils.parseYangResource("/mdsal320.yang");
31 final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
32 assertNotNull(generateTypes);
33 assertEquals(4, generateTypes.size());
35 final Type fooType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
36 .equals("org.opendaylight.yang.gen.v1.urn.odl.yt320.norev.Foo")).findFirst().get();
37 assertTrue(fooType instanceof GeneratedType);
38 final GeneratedType foo = (GeneratedType) fooType;
40 GeneratedTransferObject bar = null;
41 GeneratedTransferObject bar1 = null;
42 for (GeneratedType enc : foo.getEnclosedTypes()) {
43 switch (enc.getName()) {
45 assertTrue(enc instanceof GeneratedTransferObject);
46 bar = (GeneratedTransferObject) enc;
49 assertTrue(enc instanceof GeneratedTransferObject);
50 bar1 = (GeneratedTransferObject) enc;
53 throw new IllegalStateException("Unexpected type " + enc);
57 assertTrue(bar.isUnionType());
59 assertTrue(bar1.isUnionType());
61 final MethodSignature getBar = Iterables.getOnlyElement(foo.getMethodDefinitions());
62 final Type getBarType = getBar.getReturnType();
63 assertTrue(getBarType instanceof GeneratedTransferObject);
64 final GeneratedTransferObject getBarTO = (GeneratedTransferObject) getBarType;
65 assertTrue(getBarTO.isUnionType());
66 assertEquals(bar, getBarTO);
68 final GeneratedProperty bar1Prop = bar.getProperties().stream().filter(prop -> "bar$1".equals(prop.getName()))
70 final Type bar1PropRet = bar1Prop.getReturnType();
71 assertEquals(bar1, bar1PropRet);