659c597d61ac05bff24aa79b8898ea4e6a725751
[neutron.git] / neutron-spi / src / test / java / org / opendaylight / neutron / spi / NeutronSecurityRuleJAXBTest.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 javax.xml.bind.JAXBException;
12 import org.junit.Assert;
13 import org.junit.Test;
14
15 public class NeutronSecurityRuleJAXBTest {
16
17     private static final String NeutronSecurityRule_sourceJson="{" +
18         "\"id\": \"2bc0accf-312e-429a-956e-e4407625eb62\", " +
19         "\"direction\": \"ingress\", " +
20         "\"protocol\": \"tcp\", " +
21         "\"port_range_min\": 80, " +
22         "\"port_range_max\": 80, " +
23         "\"ethertype\": \"IPv4\", " +
24         "\"remote_ip_prefix\": \"0.0.0.0/0\", " +
25         "\"remote_group_id\": \"85cc3048-abc3-43cc-89b3-377341426ac5\", " +
26         "\"security_group_id\": \"a7734e61-b545-452d-a3cd-0189cbd9747a\", " +
27         "\"tenant_id\": \"e4f50856753b4dc6afee5fa6b9b6c550\" }";
28
29     private static final String NeutronSecurityRuleProtocolNumber_sourceJson="{" +
30         "\"id\": \"2bc0accf-312e-429a-956e-e4407625eb62\", " +
31         "\"direction\": \"ingress\", " +
32         "\"protocol\": 6, " +
33         "\"port_range_min\": 80, " +
34         "\"port_range_max\": 80, " +
35         "\"ethertype\": \"IPv4\", " +
36         "\"remote_ip_prefix\": \"0.0.0.0/0\", " +
37         "\"remote_group_id\": \"85cc3048-abc3-43cc-89b3-377341426ac5\", " +
38         "\"security_group_id\": \"a7734e61-b545-452d-a3cd-0189cbd9747a\", " +
39         "\"tenant_id\": \"e4f50856753b4dc6afee5fa6b9b6c550\" }";
40
41     private static final String NeutronSecurityRuleProtocolNumberString_sourceJson="{" +
42         "\"id\": \"2bc0accf-312e-429a-956e-e4407625eb62\", " +
43         "\"direction\": \"ingress\", " +
44         "\"protocol\": \"6\", " +
45         "\"port_range_min\": 80, " +
46         "\"port_range_max\": 80, " +
47         "\"ethertype\": \"IPv4\", " +
48         "\"remote_ip_prefix\": \"0.0.0.0/0\", " +
49         "\"remote_group_id\": \"85cc3048-abc3-43cc-89b3-377341426ac5\", " +
50         "\"security_group_id\": \"a7734e61-b545-452d-a3cd-0189cbd9747a\", " +
51         "\"tenant_id\": \"e4f50856753b4dc6afee5fa6b9b6c550\" }";
52
53     @Test
54     public void test_NeutronSecurityRule_JAXB() {
55         NeutronSecurityRule dummyObject = new NeutronSecurityRule();
56         try {
57             NeutronSecurityRule testObject = (NeutronSecurityRule) JaxbTestHelper.jaxbUnmarshall(dummyObject, NeutronSecurityRule_sourceJson);
58             Assert.assertEquals("NeutronSecurityRule JAXB Test 1: Testing id failed",
59                   "2bc0accf-312e-429a-956e-e4407625eb62", testObject.getID());
60
61             Assert.assertEquals("NeutronSecurityRule JAXB Test 2: Testing direction failed",
62                   "ingress", testObject.getSecurityRuleDirection());
63
64             Assert.assertEquals("NeutronSecurityRule JAXB Test 3: Testing protocol failed",
65                   "tcp", testObject.getSecurityRuleProtocol());
66
67             Assert.assertEquals("NeutronSecurityRule JAXB Test 4: Testing port range min failed",
68                     new Integer(80), testObject.getSecurityRulePortMin());
69
70             Assert.assertEquals("NeutronSecurityRule JAXB Test 5: Testing port range max failed",
71                     new Integer(80), testObject.getSecurityRulePortMax());
72
73             Assert.assertEquals("NeutronSecurityRule JAXB Test 6: Testing ethertype failed",
74                   "IPv4", testObject.getSecurityRuleEthertype());
75
76             Assert.assertEquals("NeutronSecurityRule JAXB Test 7: Testing remote ip prefix failed",
77                    "0.0.0.0/0", testObject.getSecurityRuleRemoteIpPrefix());
78
79             Assert.assertEquals("NeutronSecurityRule JAXB Test 8: Testing remote group id failed",
80                   "85cc3048-abc3-43cc-89b3-377341426ac5", testObject.getSecurityRemoteGroupID());
81
82             Assert.assertEquals("NeutronSecurityRule JAXB Test 9: Testing security group id failed",
83                     "a7734e61-b545-452d-a3cd-0189cbd9747a", testObject.getSecurityRuleGroupID());
84
85             Assert.assertEquals("NeutronSecurityRule JAXB Test 10: Testing tenant id failed",
86                     "e4f50856753b4dc6afee5fa6b9b6c550", testObject.getTenantID());
87         } catch (Exception e) {
88             Assert.fail("Tests failed");
89         }
90     }
91
92     @Test
93     public void test_NeutronSecurityRuleProtocolNumber_JAXB() throws JAXBException {
94         NeutronSecurityRule dummyObject = new NeutronSecurityRule();
95         NeutronSecurityRule testObject =
96             (NeutronSecurityRule) JaxbTestHelper.jaxbUnmarshall(dummyObject,
97                                                                 NeutronSecurityRuleProtocolNumber_sourceJson);
98         Assert.assertEquals("NeutronSecurityRuleProtocolNumber JAXB: Testing protocol failed",
99                             "6", testObject.getSecurityRuleProtocol());
100     }
101
102     @Test
103     public void test_NeutronSecurityRuleProtocolNumberString_JAXB() throws JAXBException {
104         NeutronSecurityRule dummyObject = new NeutronSecurityRule();
105         NeutronSecurityRule testObject =
106             (NeutronSecurityRule) JaxbTestHelper.jaxbUnmarshall(dummyObject,
107                                                                 NeutronSecurityRuleProtocolNumberString_sourceJson);
108         Assert.assertEquals("NeutronSecurityRuleProtocolNumberString JAXB: Testing protocol failed",
109                             "6", testObject.getSecurityRuleProtocol());
110     }
111 }