52871322e1dd4a688112f8c250f8d999bdb50f7d
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / Mdsal269Test.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.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
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.Type;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23
24 public class Mdsal269Test {
25     @Test
26     public void mdsal269Test() {
27         final SchemaContext context = YangParserTestUtils.parseYangResource("/mdsal269.yang");
28
29         final List<Type> generateTypes = DefaultBindingGenerator.generateFor(context);
30         assertNotNull(generateTypes);
31         assertEquals(4, generateTypes.size());
32
33         final Type mplsLabelType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
34             .equals("org.opendaylight.yang.gen.v1.mdsal269.rev180130.MplsLabel")).findFirst().get();
35
36         assertTrue(mplsLabelType instanceof GeneratedTransferObject);
37         final GeneratedTransferObject gto = (GeneratedTransferObject) mplsLabelType;
38         final Iterator<GeneratedProperty> it = gto.getEqualsIdentifiers().iterator();
39         final GeneratedProperty special = it.next();
40         final GeneratedProperty general = it.next();
41         assertFalse(it.hasNext());
42
43         assertEquals("mplsLabelGeneralUse", general.getName());
44         assertEquals("org.opendaylight.yang.gen.v1.mdsal269.rev180130.MplsLabelGeneralUse",
45             general.getReturnType().toString());
46
47         assertEquals("mplsLabelSpecialPurpose", special.getName());
48         assertEquals("Type (java.lang.Class)", special.getReturnType().toString());
49     }
50 }