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 java.util.List;
13 import javax.xml.bind.JAXBException;
14 import org.junit.Assert;
15 import org.junit.Test;
17 public class NeutronPortJAXBTest {
19 private static final String NEUTRON_PORT_SOURCE_JSON = "{ " + "\"status\": \"ACTIVE\", " + "\"name\": \"net1\", "
20 + "\"admin_state_up\": true, " + "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", "
21 + "\"fixed_ips\": [ { \"ip_address\":\"192.168.111.3\" , "
22 + "\"subnet_id\": \"22b44fc2-4ffb-4de4-b0f9-69d58b37ae27\" } ],"
23 + "\"binding:vif_details\": {\"port_filter\": \"true\" , \"ovs_hybrid_plug\": \"false\" }, "
24 + "\"extra_dhcp_opts\": [\"\"], " + "\"security_groups\": [\"\"], " + "\"allowed_address_pairs\": [\"\"], "
25 + "\"device_id\": \"257614cc-e178-4c92-9c61-3b28d40eca44\", " + "\"device_owner\": \"\", "
26 + "\"binding:host_id\": \"\", " + "\"binding:vif_type\": \"unbound\", "
27 + "\"binding:vnic_type\": \"normal\", " + "\"mac_address\": \"fa:16:3e:c9:cb:f0\", "
28 + "\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f5\", "
29 + "\"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\" }";
32 public void test_NeutronPort_JAXB() throws JAXBException {
33 NeutronPort testObject = new NeutronPort();
35 NeutronPort neutronObject = (NeutronPort) JaxbTestHelper.jaxbUnmarshall(testObject, NEUTRON_PORT_SOURCE_JSON);
36 Assert.assertEquals("NeutronPort JAXB Test 1: Testing id failed", "4e8e5957-649f-477b-9e5b-f1f75b21c03c",
37 neutronObject.getID());
39 Assert.assertEquals("NeutronPort JAXB Test 2: Testing tenant_id failed", "9bacb3c5d39d41a79512987f338cf177",
40 neutronObject.getTenantID());
42 Assert.assertEquals("NeutronPort JAXB Test 3: Testing network_id failed",
43 "e9330b1f-a2ef-4160-a991-169e56ab17f5", neutronObject.getNetworkUUID());
45 Assert.assertEquals("NeutronPort JAXB Test 4: Testing status failed", "ACTIVE", neutronObject.getStatus());
47 List<NeutronIPs> fixedIPs = neutronObject.getFixedIPs();
48 Assert.assertEquals(" NeutronPort JAXB Test 5.1: Testing fixed_ips list length failed", 1, fixedIPs.size());
50 Assert.assertEquals(" NeutronPort JAXB Test 5.2: Testing ip_address value failed", "192.168.111.3",
51 fixedIPs.get(0).ipAddress);
53 Assert.assertEquals(" NeutronPort JAXB Test 5.3: Testing subnet_id value failed",
54 "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27", fixedIPs.get(0).subnetUUID);
56 List<NeutronPortExtraDHCPOption> extraDHCPOptions = neutronObject.getExtraDHCPOptions();
58 Assert.assertEquals("NeutronPort JAXB Test 6: Testing extra_dhcp_opts list length failed", 1,
59 extraDHCPOptions.size());
61 List<NeutronSecurityGroup> securityGroups = neutronObject.getSecurityGroups();
62 Assert.assertEquals("NeutronPort JAXB Test 7: Testing security_groups list length failed", 1,
63 securityGroups.size());
65 List<NeutronPortAllowedAddressPairs> allowedAddressPairs = neutronObject.getAllowedAddressPairs();
66 Assert.assertEquals("NeutronPort JAXB Test 8: Testing allowed_address_pairs list length failed", 1,
67 allowedAddressPairs.size());
69 Map<String, String> vifDetails = neutronObject.getVIFDetails();
71 Assert.assertEquals("NeutronPort JAXB Test 9.1: Testing vif_details list length failed", 2,
74 Assert.assertEquals("NeutronPort JAXB Test 9.2: Testing port_filter value failed", "true",
75 vifDetails.get("port_filter"));
77 Assert.assertEquals("NeutronPort JAXB Test 9.3: Testing ovs_hybrid_plug value failed", "false",
78 vifDetails.get("ovs_hybrid_plug"));
80 Assert.assertEquals("NeutronPort JAXB Test 10: Testing name failed", "net1", neutronObject.getName());
82 Assert.assertEquals("NeutronPort JAXB Test 11: Testing admin_state_up failed", true,
83 neutronObject.getAdminStateUp());
85 Assert.assertEquals("NeutronPort JAXB Test 12: Testing binding:vif_type failed", "unbound",
86 neutronObject.getBindingvifType());
88 Assert.assertEquals("NeutronPort JAXB Test 13: Testing binding:vnic_type failed", "normal",
89 neutronObject.getBindingvnicType());
91 Assert.assertEquals("NeutronPort JAXB Test 14: Testing mac_address failed", "fa:16:3e:c9:cb:f0",
92 neutronObject.getMacAddress());
94 Assert.assertEquals("NeutronPort JAXB Test 15: Testing device_id failed",
95 "257614cc-e178-4c92-9c61-3b28d40eca44", neutronObject.getDeviceID());
97 Assert.assertEquals("NeutronPort JAXB Test 16: Testing device_owner failed", "",
98 neutronObject.getDeviceOwner());
100 Assert.assertEquals("NeutronPort JAXB Test 17: Testing binding:host_id failed", "",
101 neutronObject.getBindinghostID());