Integrate JavaTypeName as Identifier
[mdsal.git] / binding / mdsal-binding-generator-util / src / test / java / org / opendaylight / mdsal / binding / model / util / generated / type / builder / ConstantImplTest.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.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.assertTrue;
14
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
17
18 public class ConstantImplTest {
19
20     @Test
21     public void testMethodsOfConstantImpl() {
22         final CodegenGeneratedTypeBuilder definingType = new CodegenGeneratedTypeBuilder(
23             JavaTypeName.create("org.opendaylight.yangtools.test", "DefiningType"));
24         final CodegenGeneratedTypeBuilder type = new CodegenGeneratedTypeBuilder(
25             JavaTypeName.create("org.opendaylight.yangtools.test.v1", "BaseType"));
26         final ConstantImpl constImpl = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.1");
27         final ConstantImpl constImpl2 = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.1");
28         final ConstantImpl constImpl3 = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.0");
29         final ConstantImpl constImpl4 = constImpl;
30         final ConstantImpl constImpl5 = new ConstantImpl(definingType, type, null, "127.0.0.0");
31         final ConstantImpl constImpl6 = new ConstantImpl(definingType, type, "IpAddress", null);
32
33         assertEquals("DefiningType", constImpl.getDefiningType().getName());
34         assertEquals("BaseType", constImpl.getType().getName());
35         assertEquals("IpAddress", constImpl.getName());
36         assertEquals("127.0.0.1", constImpl.getValue());
37         assertTrue(constImpl.toFormattedString().contains("GeneratedTransferObject"));
38         assertTrue(constImpl.toString().contains("GeneratedTransferObject"));
39         assertEquals(constImpl.hashCode(), constImpl2.hashCode());
40         assertNotNull(constImpl.getDefiningType());
41         assertNotNull(constImpl.getType());
42         assertNotNull(constImpl.getName());
43         assertNotNull(constImpl.getValue());
44         assertNotNull(constImpl.toFormattedString());
45         assertNotNull(constImpl.toString());
46         assertNotNull(constImpl.hashCode());
47         assertFalse(constImpl.equals(null));
48         assertFalse(constImpl.equals("test"));
49
50         assertTrue(constImpl.equals(constImpl2));
51         assertFalse(constImpl.equals(constImpl3));
52         assertTrue(constImpl.equals(constImpl4));
53         assertFalse(constImpl5.equals(constImpl));
54         assertFalse(constImpl6.equals(constImpl));
55     }
56 }