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