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