6e9e85af52e115924bb80e711ef3031b42d88c50
[mdsal.git] / code-generator / binding-generator-util / src / test / java / org / opendaylight / yangtools / binding / generator / util / generated / type / builder / AnnotationBuilderTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.yangtools.binding.generator.util.generated.type.builder;
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.assertNull;
14 import static org.junit.Assert.assertTrue;
15
16 import java.util.ArrayList;
17 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.binding.generator.util.Types;
20 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
21 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType.Parameter;
22 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
24 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
25 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
26 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
27 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
28 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
29
30 public class AnnotationBuilderTest {
31
32     @Test
33     public void generatedTypeAnnotationTest() {
34         final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl("org.opendaylight.controller",
35                 "AnnotInterface");
36
37         genTypeBuilder.addAnnotation("javax.management", "MXBean");
38         final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation("javax.management", "Description");
39         annotDesc.addParameter("description", "some sort of interface");
40
41         final GeneratedType genType = genTypeBuilder.toInstance();
42
43         assertNotNull(genType);
44         assertNotNull(genType.getAnnotations());
45         assertEquals(2, genType.getAnnotations().size());
46
47         int annotCount = 0;
48         for (final AnnotationType annotation : genType.getAnnotations()) {
49             if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("MXBean")) {
50                 annotCount++;
51                 assertEquals(0, annotation.getParameters().size());
52             }
53             if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("Description")) {
54                 annotCount++;
55                 assertEquals(1, annotation.getParameters().size());
56                 AnnotationType.Parameter param = annotation.getParameter("description");
57                 assertNotNull(param);
58                 assertEquals("description", param.getName());
59                 assertNotNull(param.getValue());
60                 assertEquals("some sort of interface", param.getValue());
61                 assertNotNull(param.getValues());
62                 assertTrue(param.getValues().isEmpty());
63             }
64         }
65         assertEquals(2, annotCount);
66     }
67
68     @Test
69     public void methodSignatureAnnotationTest() {
70         final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl("org.opendaylight.controller",
71                 "TransferObject");
72
73         final MethodSignatureBuilder methodBuilder = genTypeBuilder.addMethod("simpleMethod");
74         methodBuilder.setReturnType(Types.typeForClass(Integer.class));
75         final AnnotationTypeBuilder annotManAttr = methodBuilder.addAnnotation(
76                 "org.springframework.jmx.export.annotation", "ManagedAttribute");
77
78         annotManAttr.addParameter("description", "\"The Name Attribute\"");
79         annotManAttr.addParameter("currencyTimeLimit", "20");
80         annotManAttr.addParameter("defaultValue", "\"bar\"");
81         annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
82
83         final AnnotationTypeBuilder annotManProp = methodBuilder.addAnnotation(
84                 "org.springframework.jmx.export.annotation", "ManagedOperation");
85
86         final List<String> typeValues = new ArrayList<String>();
87         typeValues.add("\"val1\"");
88         typeValues.add("\"val2\"");
89         typeValues.add("\"val3\"");
90         annotManProp.addParameters("types", typeValues);
91
92         final GeneratedType genType = genTypeBuilder.toInstance();
93
94         assertNotNull(genType);
95         assertNotNull(genType.getAnnotations());
96         assertNotNull(genType.getMethodDefinitions());
97         assertNotNull(genType.getMethodDefinitions().get(0));
98         assertNotNull(genType.getMethodDefinitions().get(0).getAnnotations());
99         final List<AnnotationType> annotations = genType.getMethodDefinitions().get(0).getAnnotations();
100         assertEquals(2, annotations.size());
101
102         int annotCount = 0;
103         for (final AnnotationType annotation : annotations) {
104             if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
105                     && annotation.getName().equals("ManagedAttribute")) {
106                 annotCount++;
107                 assertEquals(4, annotation.getParameters().size());
108
109                 assertNotNull(annotation.getParameter("description"));
110                 assertNotNull(annotation.getParameter("currencyTimeLimit"));
111                 assertNotNull(annotation.getParameter("defaultValue"));
112                 assertNotNull(annotation.getParameter("persistPolicy"));
113                 assertEquals("\"The Name Attribute\"", annotation.getParameter("description").getValue());
114                 assertEquals("20", annotation.getParameter("currencyTimeLimit").getValue());
115                 assertEquals("\"bar\"", annotation.getParameter("defaultValue").getValue());
116                 assertEquals("\"OnUpdate\"", annotation.getParameter("persistPolicy").getValue());
117             }
118             if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
119                     && annotation.getName().equals("ManagedOperation")) {
120                 annotCount++;
121
122                 assertEquals(1, annotation.getParameters().size());
123                 assertNotNull(annotation.getParameter("types"));
124                 assertEquals(3, annotation.getParameter("types").getValues().size());
125             }
126         }
127         assertEquals(2, annotCount);
128     }
129
130     @Test
131     public void generatedPropertyAnnotationTest() {
132         final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.controller",
133                 "AnnotInterface");
134
135         final GeneratedPropertyBuilder propertyBuilder = genTOBuilder.addProperty("simpleProperty");
136         propertyBuilder.setReturnType(Types.typeForClass(Integer.class));
137         final AnnotationTypeBuilder annotManAttr = propertyBuilder.addAnnotation(
138                 "org.springframework.jmx.export.annotation", "ManagedAttribute");
139
140         annotManAttr.addParameter("description", "\"The Name Attribute\"");
141         annotManAttr.addParameter("currencyTimeLimit", "20");
142         annotManAttr.addParameter("defaultValue", "\"bar\"");
143         annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
144
145         final AnnotationTypeBuilder annotManProp = propertyBuilder.addAnnotation(
146                 "org.springframework.jmx.export.annotation", "ManagedOperation");
147
148         final List<String> typeValues = new ArrayList<String>();
149         typeValues.add("\"val1\"");
150         typeValues.add("\"val2\"");
151         typeValues.add("\"val3\"");
152         annotManProp.addParameters("types", typeValues);
153
154         final GeneratedTransferObject genTransObj = genTOBuilder.toInstance();
155
156         assertNotNull(genTransObj);
157         assertNotNull(genTransObj.getAnnotations());
158         assertNotNull(genTransObj.getProperties());
159         assertNotNull(genTransObj.getProperties().get(0));
160         assertNotNull(genTransObj.getProperties().get(0).getAnnotations());
161         final List<AnnotationType> annotations = genTransObj.getProperties().get(0).getAnnotations();
162         assertEquals(2, annotations.size());
163
164         int annotCount = 0;
165         for (final AnnotationType annotation : annotations) {
166             if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
167                     && annotation.getName().equals("ManagedAttribute")) {
168                 annotCount++;
169                 assertEquals(4, annotation.getParameters().size());
170
171                 assertNotNull(annotation.getParameter("description"));
172                 assertNotNull(annotation.getParameter("currencyTimeLimit"));
173                 assertNotNull(annotation.getParameter("defaultValue"));
174                 assertNotNull(annotation.getParameter("persistPolicy"));
175                 assertEquals("\"The Name Attribute\"", annotation.getParameter("description").getValue());
176                 assertEquals("20", annotation.getParameter("currencyTimeLimit").getValue());
177                 assertEquals("\"bar\"", annotation.getParameter("defaultValue").getValue());
178                 assertEquals("\"OnUpdate\"", annotation.getParameter("persistPolicy").getValue());
179             }
180             if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
181                     && annotation.getName().equals("ManagedOperation")) {
182                 annotCount++;
183
184                 assertEquals(1, annotation.getParameters().size());
185                 assertNotNull(annotation.getParameter("types"));
186                 assertEquals(3, annotation.getParameter("types").getValues().size());
187             }
188         }
189         assertEquals(2, annotCount);
190     }
191
192     @Test
193     public void generatedTransfeObjectAnnotationTest() {
194         final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl("org.opendaylight.controller",
195                 "AnnotClassCache");
196
197         genTypeBuilder.addAnnotation("javax.management", "MBean");
198         final AnnotationTypeBuilder annotNotify = genTypeBuilder.addAnnotation("javax.management", "NotificationInfo");
199
200         final List<String> notifyList = new ArrayList<String>();
201         notifyList.add("\"my.notif.type\"");
202         annotNotify.addParameters("types", notifyList);
203         annotNotify.addParameter("description", "@Description(\"my notification\")");
204
205         GeneratedTransferObject genTO = genTypeBuilder.toInstance();
206
207         assertNotNull(genTO);
208         assertNotNull(genTO.getAnnotations());
209         assertEquals(2, genTO.getAnnotations().size());
210
211         int annotCount = 0;
212         for (final AnnotationType annotation : genTO.getAnnotations()) {
213             if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("MBean")) {
214                 annotCount++;
215                 assertEquals(0, annotation.getParameters().size());
216             }
217             if (annotation.getPackageName().equals("javax.management")
218                     && annotation.getName().equals("NotificationInfo")) {
219                 annotCount++;
220                 assertEquals(2, annotation.getParameters().size());
221                 AnnotationType.Parameter param = annotation.getParameter("types");
222                 assertNotNull(param);
223                 assertEquals("types", param.getName());
224                 assertNull(param.getValue());
225                 assertNotNull(param.getValues());
226                 assertEquals(1, param.getValues().size());
227                 assertEquals("\"my.notif.type\"", param.getValues().get(0));
228
229                 param = annotation.getParameter("description");
230                 assertNotNull(param);
231                 assertEquals("description", param.getName());
232                 assertNotNull(param.getValue());
233                 assertEquals("@Description(\"my notification\")", param.getValue());
234             }
235         }
236         assertEquals(2, annotCount);
237     }
238
239     @Test
240     public void annotationTypeBuilderAddAnnotationTest() {
241         AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
242
243         assertNull(annotationTypeBuilder.addAnnotation("my.package", null));
244         assertNull(annotationTypeBuilder.addAnnotation(null, "MyName"));
245
246         assertNotNull(annotationTypeBuilder.addAnnotation("", ""));
247
248         assertNotNull(annotationTypeBuilder.addAnnotation("my.package2", "MyName2"));
249         assertNull(annotationTypeBuilder.addAnnotation("my.package2", "MyName2"));
250
251         AnnotationType annotationTypeInstance = annotationTypeBuilder.toInstance();
252
253         assertEquals(2, annotationTypeInstance.getAnnotations().size());
254
255         assertEquals("my.package", annotationTypeInstance.getPackageName());
256         assertEquals("MyName", annotationTypeInstance.getName());
257
258     }
259
260     @Test
261     public void annotationTypeBuilderEqualsTest() {
262         AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
263         AnnotationTypeBuilder annotationTypeBuilder2 = new AnnotationTypeBuilderImpl("my.package2", "MyName");
264         AnnotationTypeBuilder annotationTypeBuilder3 = new AnnotationTypeBuilderImpl("my.package", "MyName2");
265         AnnotationTypeBuilder annotationTypeBuilder4 = new AnnotationTypeBuilderImpl("my.package", "MyName");
266
267         assertFalse(annotationTypeBuilder.equals(null));
268         assertFalse(annotationTypeBuilder.equals(new Object()));
269
270         assertTrue(annotationTypeBuilder.equals(annotationTypeBuilder));
271
272         assertTrue(annotationTypeBuilder.equals(annotationTypeBuilder4));
273         assertFalse(annotationTypeBuilder.equals(annotationTypeBuilder2));
274         assertFalse(annotationTypeBuilder.equals(annotationTypeBuilder3));
275
276         AnnotationType instance = annotationTypeBuilder.toInstance();
277         AnnotationType instance2 = annotationTypeBuilder2.toInstance();
278         AnnotationType instance3 = annotationTypeBuilder3.toInstance();
279         AnnotationType instance4 = annotationTypeBuilder4.toInstance();
280
281         assertFalse(instance.equals(null));
282         assertFalse(instance.equals(new Object()));
283         assertTrue(instance.equals(instance));
284
285         assertFalse(instance.equals(instance2));
286         assertFalse(instance.equals(instance3));
287         assertTrue(instance.equals(instance4));
288
289         annotationTypeBuilder.addParameter("myName", "myValue1");
290         annotationTypeBuilder.addParameter("myName2", "myValue2");
291         annotationTypeBuilder2.addParameter("myName", "myValue3");
292
293         instance = annotationTypeBuilder.toInstance();
294         instance2 = annotationTypeBuilder2.toInstance();
295
296         Parameter parameter = instance.getParameter("myName");
297         Parameter parameter2 = instance.getParameter("myName2");
298         Parameter parameter3 = instance2.getParameter("myName");
299
300         assertFalse(parameter.equals(null));
301         assertFalse(parameter.equals(new Object()));
302         assertTrue(parameter.equals(parameter));
303         assertTrue(parameter.equals(parameter3));
304         assertFalse(parameter.equals(parameter2));
305     }
306
307     @Test
308     public void annotationTypeBuilderHashCodeTest() {
309         AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
310         AnnotationTypeBuilder annotationTypeBuilder2 = new AnnotationTypeBuilderImpl("my.package2", "MyName");
311         AnnotationTypeBuilder annotationTypeBuilder3 = new AnnotationTypeBuilderImpl("my.package", "MyName2");
312         AnnotationTypeBuilder annotationTypeBuilder4 = new AnnotationTypeBuilderImpl("my.package", "MyName");
313
314         assertFalse(annotationTypeBuilder.hashCode() == annotationTypeBuilder2.hashCode());
315         assertFalse(annotationTypeBuilder.hashCode() == annotationTypeBuilder3.hashCode());
316
317         assertTrue(annotationTypeBuilder.hashCode() == annotationTypeBuilder4.hashCode());
318         assertTrue(annotationTypeBuilder.hashCode() == annotationTypeBuilder.hashCode());
319
320         AnnotationType instance = annotationTypeBuilder.toInstance();
321         AnnotationType instance2 = annotationTypeBuilder2.toInstance();
322         AnnotationType instance3 = annotationTypeBuilder3.toInstance();
323         AnnotationType instance4 = annotationTypeBuilder4.toInstance();
324
325         assertFalse(instance.hashCode() == instance2.hashCode());
326         assertFalse(instance.hashCode() == instance3.hashCode());
327
328         assertTrue(instance.hashCode() == instance4.hashCode());
329         assertTrue(instance.hashCode() == instance.hashCode());
330
331         annotationTypeBuilder.addParameter("myName", "myValue1");
332         annotationTypeBuilder.addParameter("myName2", "myValue2");
333         annotationTypeBuilder2.addParameter("myName", "myValue3");
334
335         instance = annotationTypeBuilder.toInstance();
336         instance2 = annotationTypeBuilder2.toInstance();
337
338         Parameter parameter = instance.getParameter("myName");
339         Parameter parameter2 = instance.getParameter("myName2");
340         Parameter parameter3 = instance2.getParameter("myName");
341
342         assertTrue(parameter.hashCode() == parameter.hashCode());
343         assertTrue(parameter.hashCode() == parameter3.hashCode());
344         assertFalse(parameter.hashCode() == parameter2.hashCode());
345
346     }
347
348     @Test
349     public void annotationTypeBuilderAddParameterTest() {
350         AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
351
352         assertFalse(annotationTypeBuilder.addParameter(null, "myValue"));
353         assertFalse(annotationTypeBuilder.addParameter("myName", null));
354
355         assertFalse(annotationTypeBuilder.addParameters(null, new ArrayList<String>()));
356         assertFalse(annotationTypeBuilder.addParameters("myName", null));
357
358         assertTrue(annotationTypeBuilder.addParameter("myName", "myValue"));
359         assertFalse(annotationTypeBuilder.addParameter("myName", "myValue"));
360         assertFalse(annotationTypeBuilder.addParameters("myName", new ArrayList<String>()));
361
362         ArrayList<String> values = new ArrayList<String>();
363         values.add("myValue");
364         assertTrue(annotationTypeBuilder.addParameters("myName2", values));
365
366         AnnotationType annotationTypeInstance = annotationTypeBuilder.toInstance();
367         assertTrue(annotationTypeInstance.containsParameters());
368         assertEquals(2, annotationTypeInstance.getParameters().size());
369         assertEquals(2, annotationTypeInstance.getParameterNames().size());
370         assertTrue(annotationTypeInstance.getParameterNames().contains("myName"));
371         assertTrue(annotationTypeInstance.getParameterNames().contains("myName2"));
372         assertFalse(annotationTypeInstance.getParameterNames().contains("myName3"));
373
374         Parameter parameter = annotationTypeInstance.getParameter("myName");
375         Parameter parameter2 = annotationTypeInstance.getParameter("myName2");
376         Parameter parameter3 = annotationTypeInstance.getParameter("myName3");
377
378         assertNotNull(parameter);
379         assertNotNull(parameter2);
380         assertNull(parameter3);
381
382         assertEquals(parameter.getValue(), "myValue");
383         assertTrue(parameter.getValues().isEmpty());
384
385         assertEquals(1, parameter2.getValues().size());
386         assertTrue(parameter2.getValues().contains("myValue"));
387
388     }
389
390     @Test
391     public void annotationTypeBuilderToStringTest() {
392         AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyAnnotationName");
393         annotationTypeBuilder.addAnnotation("my.package", "MySubAnnotationName");
394         annotationTypeBuilder.addParameter("MyParameter", "myValue");
395
396         assertEquals(
397                 "AnnotationTypeBuilder [packageName=my.package, name=MyAnnotationName, annotationBuilders=[AnnotationTypeBuilder [packageName=my.package, name=MySubAnnotationName, annotationBuilders=[], parameters=[]]], parameters=[ParameterImpl [name=MyParameter, value=myValue, values=[]]]]",
398                 annotationTypeBuilder.toString());
399
400         AnnotationType annotationTypeInstance = annotationTypeBuilder.toInstance();
401
402         assertEquals("my.package.MyAnnotationName", annotationTypeInstance.getFullyQualifiedName());
403         assertEquals(
404                 "AnnotationType [packageName=my.package, name=MyAnnotationName, annotations=[AnnotationType [packageName=my.package, name=MySubAnnotationName, annotations=[], parameters=[]]], parameters=[ParameterImpl [name=MyParameter, value=myValue, values=[]]]]",
405                 annotationTypeInstance.toString());
406
407     }
408
409     public void testAddAnnotation() {
410         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
411         annotBuilderImpl.addAnnotation("org.opedaylight.yangtools.test.v1", "AnnotationTest2");
412         annotBuilderImpl.addAnnotation(null, "AnnotationTest2");
413         assertFalse(annotBuilderImpl.toInstance().getAnnotations().isEmpty());
414     }
415
416     @Test
417     public void testAddParameterMethod() {
418         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
419         annotBuilderImpl.addParameter("testParam", "test value");
420         annotBuilderImpl.addParameter(null, "test value");
421         final AnnotationType annotType = annotBuilderImpl.toInstance();
422         assertEquals(1, annotType.getParameters().size());
423     }
424
425     @Test
426     public void testAddParametersMethod() {
427         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
428
429         final List<String> values = new ArrayList<>();
430         values.add("test1");
431         values.add("test2");
432         values.add("test3");
433         annotBuilderImpl.addParameters("testParam", values);
434
435         AnnotationType annotType = annotBuilderImpl.toInstance();
436         assertEquals(1, annotType.getParameters().size());
437
438         annotBuilderImpl.addParameters("testParam", null);
439
440         annotType = annotBuilderImpl.toInstance();
441         assertEquals(1, annotType.getParameters().size());
442     }
443
444     @Test
445     public void testHashCode() {
446         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
447         final AnnotationTypeBuilderImpl annotBuilderImpl2 = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest2");
448         assertFalse(annotBuilderImpl.hashCode() == annotBuilderImpl2.hashCode());
449     }
450
451     @Test
452     public void testEquals() {
453         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
454         final AnnotationTypeBuilderImpl annotBuilderImpl2 = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
455         final AnnotationTypeBuilderImpl annotBuilderImpl3 = annotBuilderImpl2;
456
457         assertTrue(annotBuilderImpl.equals(annotBuilderImpl2));
458         assertTrue(annotBuilderImpl2.equals(annotBuilderImpl3));
459         assertFalse(annotBuilderImpl2.equals(null));
460         assertFalse(annotBuilderImpl2.equals("test"));
461     }
462
463     @Test
464     public void testToString() {
465         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
466         assertNotNull(annotBuilderImpl.toString());
467     }
468
469     @Test
470     public void testMethodsForAnnotationTypeImpl() {
471         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
472         annotBuilderImpl.addParameter("testParam", "test value");
473         final AnnotationType annotationType = annotBuilderImpl.toInstance();
474
475         final AnnotationTypeBuilderImpl annotBuilderImpl2 = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
476         final AnnotationType annotationType2 = annotBuilderImpl2.toInstance();
477
478         assertTrue(annotationType.containsParameters());
479         assertTrue(annotationType.getAnnotations().isEmpty());
480         assertNotNull(annotationType.getFullyQualifiedName());
481         assertNotNull(annotationType.getName());
482         assertNotNull(annotationType.getPackageName());
483         assertNull(annotationType.getParameter(null));
484         assertNotNull(annotationType.getParameter("testParam"));
485         assertFalse(annotationType.getParameterNames().isEmpty());
486         assertFalse(annotationType.getParameters().isEmpty());
487
488         assertTrue(annotationType.hashCode() == annotationType2.hashCode());
489         assertTrue(annotationType.equals(annotationType2));
490         assertNotNull(annotationType.toString());
491     }
492
493     @Test
494     public void testMethodsForParameterImpl() {
495         final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
496         annotBuilderImpl.addParameter("testParam", "test value");
497         annotBuilderImpl.addParameter("testParam", "test value");
498         annotBuilderImpl.addParameter("", "test value");
499         annotBuilderImpl.addParameter(null, "test value");
500         annotBuilderImpl.addParameter("", null);
501         final AnnotationType annotationType = annotBuilderImpl.toInstance();
502
503         final Parameter testParam = annotationType.getParameter("testParam");
504         assertEquals("testParam", testParam.getName());
505         assertEquals("test value", testParam.getValue());
506         assertEquals(0, testParam.getValues().size());
507
508         final List<Parameter> testParams = annotationType.getParameters();
509         final Parameter sameParam = testParams.get(0);
510
511         assertFalse(testParams.get(0).equals(testParams.get(1)));
512         assertFalse(testParams.get(0).equals(null));
513         assertFalse(testParams.get(0).equals("test"));
514         assertTrue(testParams.get(0).equals(sameParam));
515         assertFalse(testParams.get(0).hashCode() == testParams.get(1).hashCode());
516         assertTrue(testParams.get(0).hashCode() == testParams.get(0).hashCode());
517     }
518 }