2 * Copyright (c) 2015 Tata Consultancy Services. All rights reserved.
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
9 package org.opendaylight.neutron.spi;
11 import javax.xml.bind.JAXBException;
12 import org.junit.Assert;
13 import org.junit.Test;
15 public class NeutronSecurityRuleJAXBTest {
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\" }";
29 private static final String NeutronSecurityRuleProtocolNumber_sourceJson="{" +
30 "\"id\": \"2bc0accf-312e-429a-956e-e4407625eb62\", " +
31 "\"direction\": \"ingress\", " +
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\" }";
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\" }";
54 public void test_NeutronSecurityRule_JAXB() {
55 NeutronSecurityRule dummyObject = new NeutronSecurityRule();
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());
61 Assert.assertEquals("NeutronSecurityRule JAXB Test 2: Testing direction failed",
62 "ingress", testObject.getSecurityRuleDirection());
64 Assert.assertEquals("NeutronSecurityRule JAXB Test 3: Testing protocol failed",
65 "tcp", testObject.getSecurityRuleProtocol());
67 Assert.assertEquals("NeutronSecurityRule JAXB Test 4: Testing port range min failed",
68 new Integer(80), testObject.getSecurityRulePortMin());
70 Assert.assertEquals("NeutronSecurityRule JAXB Test 5: Testing port range max failed",
71 new Integer(80), testObject.getSecurityRulePortMax());
73 Assert.assertEquals("NeutronSecurityRule JAXB Test 6: Testing ethertype failed",
74 "IPv4", testObject.getSecurityRuleEthertype());
76 Assert.assertEquals("NeutronSecurityRule JAXB Test 7: Testing remote ip prefix failed",
77 "0.0.0.0/0", testObject.getSecurityRuleRemoteIpPrefix());
79 Assert.assertEquals("NeutronSecurityRule JAXB Test 8: Testing remote group id failed",
80 "85cc3048-abc3-43cc-89b3-377341426ac5", testObject.getSecurityRemoteGroupID());
82 Assert.assertEquals("NeutronSecurityRule JAXB Test 9: Testing security group id failed",
83 "a7734e61-b545-452d-a3cd-0189cbd9747a", testObject.getSecurityRuleGroupID());
85 Assert.assertEquals("NeutronSecurityRule JAXB Test 10: Testing tenant id failed",
86 "e4f50856753b4dc6afee5fa6b9b6c550", testObject.getTenantID());
87 } catch (Exception e) {
88 Assert.fail("Tests failed");
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());
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());