2 * [[ Authors will Fill in the Copyright header ]]
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
8 * Authors : Brent Salisbury, Aswin Raveendran, Madhu Venugopal
10 package org.opendaylight.ovsdb.lib.message;
12 import com.fasterxml.jackson.annotation.JsonAutoDetect;
13 import com.fasterxml.jackson.annotation.PropertyAccessor;
14 import com.fasterxml.jackson.databind.ObjectMapper;
15 import com.google.common.base.Function;
16 import com.google.common.collect.Ordering;
17 import com.google.common.io.InputSupplier;
18 import com.google.common.io.Resources;
20 import junit.framework.TestCase;
22 import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
23 import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
24 import org.opendaylight.ovsdb.lib.notation.UUID;
25 import org.opendaylight.ovsdb.lib.table.Bridge;
26 import org.opendaylight.ovsdb.lib.table.Interface;
27 import org.opendaylight.ovsdb.lib.table.Port;
28 import org.opendaylight.ovsdb.lib.table.Table;
30 import java.io.IOException;
31 import java.io.InputStream;
33 import java.util.Collection;
34 import java.util.List;
38 public class MonitorResponseTest extends TestCase {
40 public void testDeser() throws IOException {
41 URL resource = Resources.getResource(MonitorResponseTest.class, "monitor_response1.json");
42 InputSupplier<InputStream> inputStreamInputSupplier = Resources.newInputStreamSupplier(resource);
43 InputStream input = inputStreamInputSupplier.getInput();
44 ObjectMapper mapper = new ObjectMapper();
45 mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.ANY);
46 TableUpdates updates = mapper.readValue(input, TableUpdates.class);
48 Set<Table.Name> available = updates.availableUpdates();
49 for (Table.Name name : available) {
50 if (Bridge.NAME.equals(name)) {
51 verifyBridge(updates);
52 } else if (Port.NAME.equals(name)) {
54 } else if (Interface.NAME.equals(name)) {
55 verifyInterface(updates);
60 private void verifyInterface(TableUpdates updates) {
61 TableUpdate<Interface> update = updates.getUpdate(Interface.NAME);
62 for (TableUpdate.Row<Interface> interfaceRow : update.getRows()) {
63 System.out.println("interfaceRow = " + interfaceRow);
64 Interface aNew = interfaceRow.getNew();
66 OvsDBMap<String, String> options = aNew.getOptions();
67 if (options != null) {
68 for (Map.Entry<String, String> optE : options.entrySet()) {
69 System.out.println("optE.getKey() = " + optE.getKey());
70 System.out.println("optE.getValue() = " + optE.getValue());
77 private void verifyBridge(TableUpdates updates) {
78 TableUpdate<Bridge> update = updates.getUpdate(Bridge.NAME);
79 for (TableUpdate.Row<Bridge> row : update.getRows()) {
80 assertEquals("788de61c-0e4f-43d8-a068-259e75aabbba", row.getId());
81 Bridge bridge = row.getNew();
82 assertNotNull(bridge);
83 OvsDBSet<UUID> ports = bridge.getPorts();
84 assertEquals(2, ports.size());
85 List<UUID> uuids = Ordering.usingToString().sortedCopy(ports);
86 assertEquals("f6018e7a-7ca5-4e72-a744-a9b434f47011", uuids.get(0).toString());
87 assertEquals("fe3c89fd-2ff3-44d8-9f27-f9c7ac2a693d", uuids.get(1).toString());
88 bridge = row.getOld();
93 private void veriftyPort(TableUpdates updates) {
94 TableUpdate<Port> update = updates.getUpdate(Port.NAME);
95 Collection<TableUpdate.Row<Port>> rows = update.getRows();
96 assertEquals(2, rows.size());
97 List<TableUpdate.Row<Port>> sorted = Ordering.natural().onResultOf(new Function<TableUpdate.Row<Port>, String>() {
99 public String apply(org.opendaylight.ovsdb.lib.message.TableUpdate.Row<Port> input) {
100 return input.getId();
104 TableUpdate.Row<Port> portRow = sorted.get(0);
105 assertEquals("f6018e7a-7ca5-4e72-a744-a9b434f47011", portRow.getId());
106 Port port = portRow.getNew();
108 List<UUID> interfaces = Ordering.usingToString().sortedCopy(port.getInterfaces());
109 assertEquals("13548b08-dca3-4d4b-9e9b-f50c237dcb9e", interfaces.get(0).toString());
110 port = portRow.getOld();
113 portRow = sorted.get(1);
114 assertEquals("fe3c89fd-2ff3-44d8-9f27-f9c7ac2a693d", portRow.getId());
115 port = portRow.getNew();
117 interfaces = Ordering.usingToString().sortedCopy(port.getInterfaces());
118 assertEquals("88ae29fb-8c91-41a9-a14f-a74126e790c0", interfaces.get(0).toString());
119 port = portRow.getOld();