8568eac5a8a39b7351ce3fd40772e6dad43d8ffe
[neutron.git] / neutron-spi / src / test / java / org / opendaylight / neutron / spi / NeutronPort_ExtraDHCPOptionJAXBTest.java
1 /*
2  * Copyright (c) 2015 Tata Consultancy Services.  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
9 package org.opendaylight.neutron.spi;
10
11 import org.junit.Assert;
12 import org.junit.Test;
13
14 public class NeutronPort_ExtraDHCPOptionJAXBTest {
15
16     private static final String NeutronPort_ExtraDHCPOption_sourceJson = "{" + "\"opt_value\": \"123.123.123.456\", "
17             + "\"opt_name\": \"server-ip-address\" "
18             + "}";
19     private static final String NeutronPort_ExtraDHCPOption_IPv4_sourceJson = "{" + "\"opt_value\": \"123.123.123.456\", "
20             + "\"opt_name\": \"server-ip-address\", "
21             + "\"ip_version\": 4"
22             + "}";
23     private static final String NeutronPort_ExtraDHCPOption_IPv6_sourceJson = "{" + "\"opt_value\": \"::ffff:123.123.123.456\", "
24             + "\"opt_name\": \"server-ip-address\", "
25             + "\"ip_version\": 6"
26             + "}";
27
28     @Test
29     public void test_NeutronPort_ExtraDHCPOption_JAXB() {
30         NeutronPort_ExtraDHCPOption portObject = new NeutronPort_ExtraDHCPOption();
31         NeutronPort_ExtraDHCPOption testObject;
32         try {
33             testObject = (NeutronPort_ExtraDHCPOption) JaxbTestHelper.jaxbUnmarshall(
34                     portObject, NeutronPort_ExtraDHCPOption_sourceJson);
35         } catch (Exception e) {
36             Assert.assertFalse("Tests Failed", true);
37             return;
38         }
39
40         Assert.assertEquals("NeutronPort_ExtraDHCPOption JAXB Test 1: Testing opt_value failed", "123.123.123.456",
41                             testObject.getValue());
42         Assert.assertEquals("NeutronPort_ExtraDHCPOption JAXB Test 10: Testing opt_name failed",
43                             "server-ip-address", testObject.getName());
44         Assert.assertEquals("NeutronPort_ExtraDHCPOption JAXB Test 20: Testing opt_name failed",
45                             4, testObject.getIpVersion().intValue());
46     }
47
48     @Test
49     public void test_NeutronPort_ExtraDHCPOption_IPv4_JAXB() {
50         NeutronPort_ExtraDHCPOption portObject = new NeutronPort_ExtraDHCPOption();
51         NeutronPort_ExtraDHCPOption testObject;
52         try {
53             testObject = (NeutronPort_ExtraDHCPOption) JaxbTestHelper.jaxbUnmarshall(
54                     portObject, NeutronPort_ExtraDHCPOption_IPv4_sourceJson);
55         } catch (Exception e) {
56             Assert.assertFalse("Tests Failed", true);
57             return;
58         }
59
60         Assert.assertEquals("NeutronPort_ExtraDHCPOption_IPv4 JAXB Test 1: Testing opt_value failed",
61                             "123.123.123.456", testObject.getValue());
62         Assert.assertEquals("NeutronPort_ExtraDHCPOption_IPv4 JAXB Test 10: Testing opt_name failed",
63                             "server-ip-address", testObject.getName());
64         Assert.assertEquals("NeutronPort_ExtraDHCPOption_IPv4 JAXB Test 20: Testing opt_name failed",
65                             4, testObject.getIpVersion().intValue());
66     }
67
68     @Test
69     public void test_NeutronPort_ExtraDHCPOption_IPv6_JAXB() {
70         NeutronPort_ExtraDHCPOption portObject = new NeutronPort_ExtraDHCPOption();
71         NeutronPort_ExtraDHCPOption testObject;
72         try {
73             testObject = (NeutronPort_ExtraDHCPOption) JaxbTestHelper.jaxbUnmarshall(
74                     portObject, NeutronPort_ExtraDHCPOption_IPv6_sourceJson);
75         } catch (Exception e) {
76             Assert.assertFalse("Tests Failed", true);
77             return;
78         }
79
80         Assert.assertEquals("NeutronPort_ExtraDHCPOption_IPv6 JAXB Test 1: Testing opt_value failed",
81                             "::ffff:123.123.123.456", testObject.getValue());
82         Assert.assertEquals("NeutronPort_ExtraDHCPOption_IPv6 JAXB Test 10: Testing opt_name failed",
83                             "server-ip-address", testObject.getName());
84         Assert.assertEquals("NeutronPort_ExtraDHCPOption_IPv6 JAXB Test 20: Testing opt_name failed",
85                             6, testObject.getIpVersion().intValue());
86     }
87 }