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;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
14 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
17 import org.opendaylight.mdsal.binding.model.api.AnnotationType.Parameter;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
19 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
20 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class Mdsal554Test {
25 public void builderTemplateGenerateListenerMethodsTest() {
26 final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(
27 YangParserTestUtils.parseYangResource("/mdsal554.yang"));
28 assertEquals(4, genTypes.size());
30 final List<MethodSignature> methods = genTypes.get(3).getMethodDefinitions();
31 assertEquals(3, methods.size());
34 final MethodSignature deprecated = methods.get(0);
35 assertEquals("onDeprecatedNotification", deprecated.getName());
36 assertFalse(deprecated.isDefault());
38 final List<AnnotationType> deprecatedAnnotations = deprecated.getAnnotations();
39 assertEquals(1, deprecatedAnnotations.size());
41 AnnotationType annotation = deprecatedAnnotations.get(0);
42 assertEquals(JavaTypeName.create(Deprecated.class), annotation.getIdentifier());
43 assertEquals(List.of(), annotation.getParameters());
46 final MethodSignature obsolete = methods.get(1);
47 assertEquals("onObsoleteNotification", obsolete.getName());
48 assertTrue(obsolete.isDefault());
50 final List<AnnotationType> obsoleteAnnotations = obsolete.getAnnotations();
51 assertEquals(1, obsoleteAnnotations.size());
53 annotation = obsoleteAnnotations.get(0);
54 assertEquals(JavaTypeName.create(Deprecated.class), annotation.getIdentifier());
56 final List<Parameter> annotationParameters = annotation.getParameters();
57 assertEquals(1, annotationParameters.size());
59 assertEquals("forRemoval", annotationParameters.get(0).getName());
60 assertEquals("true", annotationParameters.get(0).getValue());
63 final MethodSignature current = methods.get(2);
64 assertEquals("onTestNotification", current.getName());
65 assertFalse(current.isDefault());
66 assertEquals(List.of(), current.getAnnotations());