Introduce top-level pom file.
[mdsal.git] / binding / mdsal-binding-generator-util / src / test / java / org / opendaylight / yangtools / binding / generator / util / generated / type / builder / GeneratedTOBuilderTest.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.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.Test;
15 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
16 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
17 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
18
19 public class GeneratedTOBuilderTest {
20
21     @Test
22     public void testBuilder() {
23         final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
24                 "org.opendaylight.controller", "AnnotClassCache");
25
26         genTypeBuilder.setSUID(genTypeBuilder.addProperty("SUID"));
27         genTypeBuilder.addMethod("addCount");
28
29         GeneratedTransferObject genTO = genTypeBuilder.toInstance();
30         genTypeBuilder.setExtendsType(genTO);
31
32         GeneratedPropertyBuilder property = genTypeBuilder
33                 .addProperty("customProperty");
34         genTypeBuilder.addHashIdentity(property);
35
36         genTypeBuilder.addEqualsIdentity(property);
37
38         genTypeBuilder.addToStringProperty(property);
39
40         assertNotNull(genTO);
41         assertNotNull(genTO.getProperties());
42     }
43
44     @Test
45     public void testToString() {
46         final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
47                 "org.opendaylight.controller", "AnnotClassCache");
48         String toString = genTypeBuilder.toString();
49         assertTrue(toString.contains("GeneratedTransferObject"));
50     }
51
52     @Test
53     public void testTransferBuilderToString() {
54         final GeneratedTOBuilder genTypeBuilder1 = new GeneratedTOBuilderImpl(
55                 "org.opendaylight.controller", "AnnotClassCache");
56
57         genTypeBuilder1.setTypedef(true);
58         GeneratedTransferObject genTO = genTypeBuilder1.toInstance();
59         String toString = genTO.toString();
60         assertFalse(toString.contains("GeneratedTransferObject"));
61
62         final GeneratedTOBuilder genTypeBuilder2 = new GeneratedTOBuilderImpl(
63                 "org.opendaylight.controller", "AnnotClassCache");
64
65         genTypeBuilder2.setTypedef(false);
66         genTO = genTypeBuilder2.toInstance();
67         toString = genTO.toString();
68
69         assertTrue(toString.contains("GeneratedTransferObject"));
70     }
71 }