Fix incorrect OVSDB class names
[ovsdb.git] / schemas / openvswitch / src / test / java / org / opendaylight / ovsdb / schema / openvswitch / PortAndInterfaceTestCases.java
1 /*
2  * Copyright (C) 2014 Red Hat, Inc.
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  *  Authors : Dave Tucker
9  */
10
11 package org.opendaylight.ovsdb.schema.openvswitch;
12
13 import com.google.common.collect.ImmutableMap;
14 import com.google.common.collect.ImmutableSet;
15 import com.google.common.collect.Sets;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import junit.framework.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
21 import org.opendaylight.ovsdb.lib.notation.Mutator;
22 import org.opendaylight.ovsdb.lib.notation.UUID;
23 import org.opendaylight.ovsdb.lib.operations.OperationResult;
24 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import java.io.IOException;
29 import java.util.List;
30 import java.util.concurrent.ExecutionException;
31 import java.util.concurrent.TimeoutException;
32
33 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
34
35 public class PortAndInterfaceTestCases extends OpenVswitchSchemaTestBase {
36
37     Logger logger = LoggerFactory.getLogger(PortAndInterfaceTestCases.class);
38
39     @Before
40     public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
41         super.setUp();
42     }
43
44
45     @Test
46     public void testCreateTypedPortandInterface() throws InterruptedException, ExecutionException {
47         String portUuidStr = "testPort";
48         String intfUuidStr = "testIntf";
49         Port port = ovs.createTypedRowWrapper(Port.class);
50         port.setName("testPort");
51         port.setTag(ImmutableSet.of(1L));
52         port.setMac(ImmutableSet.of("00:00:00:00:00:01"));
53         port.setInterfaces(ImmutableSet.of(new UUID(intfUuidStr)));
54
55         Interface intf = ovs.createTypedRowWrapper(Interface.class);
56         intf.setName(port.getNameColumn().getData());
57         intf.setExternalIds(ImmutableMap.of("vm-id", "12345abcedf78910"));
58
59         Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
60         TransactionBuilder transactionBuilder = ovs.transactBuilder(OpenVswitchSchemaSuiteIT.dbSchema)
61                 .add(op.insert(port.getSchema())
62                         .withId(portUuidStr)
63                         .value(port.getNameColumn())
64                         .value(port.getMacColumn()))
65                 .add(op.insert(intf.getSchema())
66                         .withId(intfUuidStr)
67                         .value(intf.getNameColumn()))
68                 .add(op.update(port.getSchema())
69                         .set(port.getTagColumn())
70                         .set(port.getMacColumn())
71                         .set(port.getInterfacesColumn())
72                         .where(port.getNameColumn().getSchema().opEqual(port.getName()))
73                         .build())
74                 .add(op.update(intf.getSchema())
75                         .set(intf.getExternalIdsColumn())
76                         .where(intf.getNameColumn().getSchema().opEqual(intf.getName()))
77                         .build())
78                 .add(op.mutate(bridge.getSchema())
79                         .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT, Sets.newHashSet(new UUID(portUuidStr)))
80                         .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
81                         .build());
82         ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
83         List<OperationResult> operationResults = results.get();
84         Assert.assertFalse(operationResults.isEmpty());
85         // Check if Results matches the number of operations in transaction
86         Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
87         logger.info("Insert & Mutate operation results for Port and Interface = " + operationResults);
88     }
89
90     @Override
91     public void update(Object context, UpdateNotification upadateNotification) {
92
93     }
94
95     @Override
96     public void locked(Object context, List<String> ids) {
97
98     }
99
100     @Override
101     public void stolen(Object context, List<String> ids) {
102
103     }
104 }