Merge "Add missing table versions to Typed Table classes" into topic/schema
[ovsdb.git] / schemas / Open_vSwitch / src / test / java / org / opendaylight / ovsdb / schema / openvswitch / SflowTestCases.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 : Brent Salisbury, 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.junit.Assert.assertNull;
34 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
35
36 public class SflowTestCases extends OpenVswitchSchemaTestBase {
37
38     Logger logger = LoggerFactory.getLogger(SflowTestCases.class);
39
40     @Before
41     public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
42         super.setUp();
43     }
44
45     @Test
46     public void testCreateTypedSflow() throws InterruptedException, ExecutionException, IllegalArgumentException{
47         String sFlowUuidStr = "testSFlow";
48         String sFlowTarget = "172.16.20.200:6343";
49         Integer header = 128;
50         Integer obsPointId = 358;
51         Integer polling = 10;
52         String agent = "172.16.20.210";
53         Integer sampling = 64;
54         SFlow sFlow = ovs.createTypedRowWrapper(SFlow.class);
55         sFlow.setTargets(ImmutableSet.of(sFlowTarget));
56         sFlow.setHeader(ImmutableSet.of(header));
57         sFlow.setPolling(ImmutableSet.of(obsPointId));
58         sFlow.setPolling(ImmutableSet.of(polling));
59         sFlow.setAgent(ImmutableSet.of(agent));
60         sFlow.setSampling(ImmutableSet.of(sampling));
61         sFlow.setExternalIds(ImmutableMap.of("kit", "tah"));
62         Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
63         TransactionBuilder transactionBuilder = ovs.transactBuilder()
64                 .add(op.insert(sFlow.getSchema())
65                         .withId(sFlowUuidStr)
66                         .value(sFlow.getTargetsColumn())
67                         .value(sFlow.getHeaderColumn())
68                         .value(sFlow.getPollingColumn())
69                         .value(sFlow.getAgentColumn())
70                         .value(sFlow.getSamplingColumn())
71                         .value(sFlow.getExternalIdsColumn()))
72                 .add(op.mutate(bridge.getSchema())
73                         .addMutation(bridge.getSflowColumn().getSchema(), Mutator.INSERT,
74                                 Sets.newHashSet(new UUID(sFlowUuidStr)))
75                         .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
76                         .build());
77         ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
78         List<OperationResult> operationResults = results.get();
79         for (OperationResult result : operationResults) {
80             assertNull(result.getError());
81         }
82         Assert.assertFalse(operationResults.isEmpty());
83         // Check if Results matches the number of operations in transaction
84         Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
85         logger.info("Insert & Mutate operation results for SFlow = {} ", operationResults);
86     }
87
88     @Override
89     public void update(Object context, UpdateNotification upadateNotification) {
90
91     }
92
93     @Override
94     public void locked(Object context, List<String> ids) {
95
96     }
97
98     @Override
99     public void stolen(Object context, List<String> ids) {
100
101     }
102 }