2 * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.sal.binding.generator.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
20 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
21 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
22 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
23 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
24 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
26 public class AnnotationBuilderTest {
29 public void generatedTypeAnnotationTest() {
30 GeneratedTypeBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
31 "org.opendaylight.controller", "AnnotInterface");
33 genTypeBuilder.addAnnotation("javax.management", "MXBean");
34 final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation(
35 "javax.management", "Description");
36 annotDesc.addParameter("description", "some sort of interface");
38 final GeneratedType genType = genTypeBuilder.toInstance();
40 assertNotNull(genType);
41 assertNotNull(genType.getAnnotations());
42 assertEquals(2, genType.getAnnotations().size());
45 for (final AnnotationType annotation : genType.getAnnotations()) {
46 if (annotation.getPackageName().equals("javax.management")
47 && annotation.getName().equals("MXBean")) {
49 assertEquals(0, annotation.getParameters().size());
51 if (annotation.getPackageName().equals("javax.management")
52 && annotation.getName().equals("Description")) {
54 assertEquals(1, annotation.getParameters().size());
55 AnnotationType.Parameter param = annotation.getParameter("description");
57 assertEquals("description", param.getName());
58 assertNotNull(param.getValue());
59 assertEquals("some sort of interface", param.getValue());
60 assertNotNull(param.getValues());
61 assertTrue(param.getValues().isEmpty());
64 assertEquals(2, annotCount);
68 public void methodSignatureAnnotationTest() {
69 //TODO add test for method annotations
73 public void generatedPropertyAnnotationTest() {
74 //TODO add test for property annotations
78 public void generatedTransfeObjectAnnotationTest() {
79 final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
80 "org.opendaylight.controller", "AnnotClassCache");
82 genTypeBuilder.addAnnotation("javax.management", "MBean");
83 final AnnotationTypeBuilder annotNotify = genTypeBuilder.addAnnotation(
84 "javax.management", "NotificationInfo");
86 final List<String> notifyList = new ArrayList<String>();
87 notifyList.add("\"my.notif.type\"");
88 annotNotify.addParameters("types", notifyList);
89 annotNotify.addParameter("description",
90 "@Description(\"my notification\")");
92 GeneratedTransferObject genTO = genTypeBuilder.toInstance();
95 assertNotNull(genTO.getAnnotations());
96 assertEquals(2, genTO.getAnnotations().size());
99 for (final AnnotationType annotation : genTO.getAnnotations()) {
100 if (annotation.getPackageName().equals("javax.management")
101 && annotation.getName().equals("MBean")) {
103 assertEquals(0, annotation.getParameters().size());
105 if (annotation.getPackageName().equals("javax.management")
106 && annotation.getName().equals("NotificationInfo")) {
108 assertEquals(2, annotation.getParameters().size());
109 AnnotationType.Parameter param = annotation.getParameter("types");
110 assertNotNull(param);
111 assertEquals("types", param.getName());
112 assertNull(param.getValue());
113 assertNotNull(param.getValues());
114 assertEquals(1, param.getValues().size());
115 assertEquals("\"my.notif.type\"", param.getValues().get(0));
117 param = annotation.getParameter("description");
118 assertNotNull(param);
119 assertEquals("description", param.getName());
120 assertNotNull(param.getValue());
121 assertEquals("@Description(\"my notification\")", param.getValue());
124 assertEquals(2, annotCount);