2 * Copyright (c) 2016 Intel Corporation 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 java.util.List;
13 import javax.xml.bind.JAXBException;
14 import org.junit.Assert;
15 import org.junit.Test;
17 public class NeutronPortSecurityJAXBTest {
19 // JSON with PortSecurityEnabled set true
20 private static final String PORT_SECURITY_ENABLED_SOURCE_JSON = "{ " + "\"status\": \"ACTIVE\", "
21 + "\"name\": \"net1\", " + "\"admin_state_up\": true, "
22 + "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", "
23 + "\"fixed_ips\": [ { \"ip_address\":\"192.168.111.3\" , "
24 + "\"subnet_id\": \"22b44fc2-4ffb-4de4-b0f9-69d58b37ae27\" } ],"
25 + "\"binding:vif_details\": {\"port_filter\": \"true\" , \"ovs_hybrid_plug\": \"false\" }, "
26 + "\"extra_dhcp_opts\": [\"\"], " + "\"security_groups\": [\"\"], " + "\"allowed_address_pairs\": [\"\"], "
27 + "\"device_id\": \"257614cc-e178-4c92-9c61-3b28d40eca44\", " + "\"device_owner\": \"\", "
28 + "\"binding:host_id\": \"\", " + "\"binding:vif_type\": \"unbound\", "
29 + "\"binding:vnic_type\": \"normal\", " + "\"mac_address\": \"fa:16:3e:c9:cb:f0\", "
30 + "\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f5\", "
31 + "\"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", " + "\"port_security_enabled\": true }";
33 // JSON with PortSecurityEnabled set false
34 private static final String PORT_SECURITY_DISABLED_SOURCE_JSON = "{ " + "\"status\": \"ACTIVE\", "
35 + "\"name\": \"net1\", " + "\"admin_state_up\": true, "
36 + "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", "
37 + "\"fixed_ips\": [ { \"ip_address\":\"192.168.111.3\" , "
38 + "\"subnet_id\": \"22b44fc2-4ffb-4de4-b0f9-69d58b37ae27\" } ],"
39 + "\"binding:vif_details\": {\"port_filter\": \"true\" , \"ovs_hybrid_plug\": \"false\" }, "
40 + "\"extra_dhcp_opts\": [\"\"], " + "\"security_groups\": [\"\"], " + "\"allowed_address_pairs\": [\"\"], "
41 + "\"device_id\": \"257614cc-e178-4c92-9c61-3b28d40eca44\", " + "\"device_owner\": \"\", "
42 + "\"binding:host_id\": \"\", " + "\"binding:vif_type\": \"unbound\", "
43 + "\"binding:vnic_type\": \"normal\", " + "\"mac_address\": \"fa:16:3e:c9:cb:f0\", "
44 + "\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f5\", "
45 + "\"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", " + "\"port_security_enabled\": false }";
47 // JSON with PortSecurityEnabled not set for compatibility test
48 private static final String PORT_SECURITY_DEFAULT_SOURCE_JSON = "{ " + "\"status\": \"ACTIVE\", "
49 + "\"name\": \"net1\", " + "\"admin_state_up\": true, "
50 + "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", "
51 + "\"fixed_ips\": [ { \"ip_address\":\"192.168.111.3\" , "
52 + "\"subnet_id\": \"22b44fc2-4ffb-4de4-b0f9-69d58b37ae27\" } ],"
53 + "\"binding:vif_details\": {\"port_filter\": \"true\" , \"ovs_hybrid_plug\": \"false\" }, "
54 + "\"extra_dhcp_opts\": [\"\"], " + "\"security_groups\": [\"\"], " + "\"allowed_address_pairs\": [\"\"], "
55 + "\"device_id\": \"257614cc-e178-4c92-9c61-3b28d40eca44\", " + "\"device_owner\": \"\", "
56 + "\"binding:host_id\": \"\", " + "\"binding:vif_type\": \"unbound\", "
57 + "\"binding:vnic_type\": \"normal\", " + "\"mac_address\": \"fa:16:3e:c9:cb:f0\", "
58 + "\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f5\", "
59 + "\"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\" }";
62 public void test_NeutronPortSecurityEnabled_JAXB() throws JAXBException {
63 test_PortSecurityEnabled_JAXB(PORT_SECURITY_ENABLED_SOURCE_JSON, true);
67 public void test_NeutronPortSecurityDisabled_JAXB() throws JAXBException {
68 test_PortSecurityEnabled_JAXB(PORT_SECURITY_DISABLED_SOURCE_JSON, false);
72 By Default PortSecurity is enabled for backward compatibility.
73 This test checks the case when the parameter is not available.
76 public void test_NeutronPortSecurityDefault_JAXB() throws JAXBException {
77 test_PortSecurityEnabled_JAXB(PORT_SECURITY_DEFAULT_SOURCE_JSON, true);
80 private void test_PortSecurityEnabled_JAXB(String sourceJson, Boolean portSecurityEnabled) throws JAXBException {
81 NeutronPort testObject = new NeutronPort();
83 NeutronPort neutronObject = (NeutronPort) JaxbTestHelper.jaxbUnmarshall(testObject, sourceJson);
84 Assert.assertEquals("NeutronPort JAXB Test 1: Testing id failed", "4e8e5957-649f-477b-9e5b-f1f75b21c03c",
85 neutronObject.getID());
87 Assert.assertEquals("NeutronPort JAXB Test 2: Testing tenant_id failed", "9bacb3c5d39d41a79512987f338cf177",
88 neutronObject.getTenantID());
90 Assert.assertEquals("NeutronPort JAXB Test 3: Testing network_id failed",
91 "e9330b1f-a2ef-4160-a991-169e56ab17f5", neutronObject.getNetworkUUID());
93 Assert.assertEquals("NeutronPort JAXB Test 4: Testing status failed", "ACTIVE", neutronObject.getStatus());
95 List<NeutronIPs> fixedIPs = neutronObject.getFixedIPs();
96 Assert.assertEquals(" NeutronPort JAXB Test 5.1: Testing fixed_ips list length failed", 1, fixedIPs.size());
98 Assert.assertEquals(" NeutronPort JAXB Test 5.2: Testing ip_address value failed", "192.168.111.3",
99 fixedIPs.get(0).ipAddress);
101 Assert.assertEquals(" NeutronPort JAXB Test 5.3: Testing subnet_id value failed",
102 "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27", fixedIPs.get(0).subnetUUID);
104 List<NeutronPortExtraDHCPOption> extraDHCPOptions = neutronObject.getExtraDHCPOptions();
106 Assert.assertEquals("NeutronPort JAXB Test 6: Testing extra_dhcp_opts list length failed", 1,
107 extraDHCPOptions.size());
109 List<NeutronSecurityGroup> securityGroups = neutronObject.getSecurityGroups();
110 Assert.assertEquals("NeutronPort JAXB Test 7: Testing security_groups list length failed", 1,
111 securityGroups.size());
113 List<NeutronPortAllowedAddressPairs> allowedAddressPairs = neutronObject.getAllowedAddressPairs();
114 Assert.assertEquals("NeutronPort JAXB Test 8: Testing allowed_address_pairs list length failed", 1,
115 allowedAddressPairs.size());
117 Map<String, String> vifDetails = neutronObject.getVIFDetails();
119 Assert.assertEquals("NeutronPort JAXB Test 9.1: Testing vif_details list length failed", 2,
122 Assert.assertEquals("NeutronPort JAXB Test 9.2: Testing port_filter value failed", "true",
123 vifDetails.get("port_filter"));
125 Assert.assertEquals("NeutronPort JAXB Test 9.3: Testing ovs_hybrid_plug value failed", "false",
126 vifDetails.get("ovs_hybrid_plug"));
128 Assert.assertEquals("NeutronPort JAXB Test 10: Testing name failed", "net1", neutronObject.getName());
130 Assert.assertEquals("NeutronPort JAXB Test 11: Testing admin_state_up failed", true,
131 neutronObject.getAdminStateUp());
133 Assert.assertEquals("NeutronPort JAXB Test 12: Testing binding:vif_type failed", "unbound",
134 neutronObject.getBindingvifType());
136 Assert.assertEquals("NeutronPort JAXB Test 13: Testing binding:vnic_type failed", "normal",
137 neutronObject.getBindingvnicType());
139 Assert.assertEquals("NeutronPort JAXB Test 14: Testing mac_address failed", "fa:16:3e:c9:cb:f0",
140 neutronObject.getMacAddress());
142 Assert.assertEquals("NeutronPort JAXB Test 15: Testing device_id failed",
143 "257614cc-e178-4c92-9c61-3b28d40eca44", neutronObject.getDeviceID());
145 Assert.assertEquals("NeutronPort JAXB Test 16: Testing device_owner failed", "",
146 neutronObject.getDeviceOwner());
148 Assert.assertEquals("NeutronPort JAXB Test 17: Testing binding:host_id failed", "",
149 neutronObject.getBindinghostID());
151 Assert.assertEquals("NeutronPort JAXB Test 18: Testing port_security_enabled failed", portSecurityEnabled,
152 neutronObject.getPortSecurityEnabled());