2 * Copyright (c) 2020 PANTHEON.tech, 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;
12 import java.util.HashSet;
13 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
17 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
18 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
19 import org.opendaylight.mdsal.binding.model.api.Type;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24 public class Mdsal554Test {
26 public void builderTemplateGenerateListenerMethodsTest() {
27 final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/mdsal554.yang");
29 final Set<Module> toGenModules = new HashSet<>();
30 for (final Module module : context.getModules()) {
31 toGenModules.add(module);
34 final List<Type> genTypes = DefaultBindingGenerator.generateFor(context, toGenModules);
36 final GeneratedType type = (GeneratedType) genTypes.get(3);
38 final List<MethodSignature> methods = type.getMethodDefinitions();
40 assertEquals(3, methods.size());
41 assertEquals(methods.get(0).getName(), "onDeprecatedNotification");
42 assertEquals(methods.get(0).isDefault(), false);
43 assertEquals(methods.get(0).getAnnotations().size(), 1);
44 assertEquals(methods.get(0).getAnnotations().get(0).getIdentifier(), JavaTypeName.create(Deprecated.class));
45 assertEquals(methods.get(0).getAnnotations().get(0).getParameters().size(), 0);
47 assertEquals(methods.get(1).getName(), "onObsoleteNotification");
48 assertEquals(methods.get(1).isDefault(), true);
49 assertEquals(methods.get(1).getAnnotations().size(), 1);
50 assertEquals(methods.get(1).getAnnotations().get(0).getIdentifier(), JavaTypeName.create(Deprecated.class));
51 assertEquals(methods.get(1).getAnnotations().get(0).getParameters().size(), 1);
52 assertEquals(methods.get(1).getAnnotations().get(0).getParameters().get(0).getName(), "forRemoval");
53 assertEquals(methods.get(1).getAnnotations().get(0).getParameters().get(0).getValue(), "true");
55 assertEquals(methods.get(2).getName(), "onTestNotification");
56 assertEquals(methods.get(2).isDefault(), false);
57 assertEquals(methods.get(2).getAnnotations().size(), 0);