Normalize Bundle Naming
[ovsdb.git] / schemas / openvswitch / src / test / java / org / opendaylight / ovsdb / schema / openvswitch / FlowSampleCollectorSetTestCases.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.util.concurrent.ListenableFuture;
15 import junit.framework.Assert;
16 import org.junit.Assume;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
20 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
21 import org.opendaylight.ovsdb.lib.notation.Version;
22 import org.opendaylight.ovsdb.lib.operations.OperationResult;
23 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import java.io.IOException;
28 import java.util.List;
29 import java.util.concurrent.ExecutionException;
30 import java.util.concurrent.TimeoutException;
31
32 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
33
34 public class FlowSampleCollectorSetTestCases extends OpenVswitchSchemaTestBase {
35     Logger logger = LoggerFactory.getLogger(FlowSampleCollectorSet.class);
36     Version schemaVersion;
37     Version flowSampleCollectorSetFromVersion = Version.fromString("7.1.0");
38
39     @Before
40     public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
41         super.setUp();
42         schemaVersion = ovs.getDatabaseSchema("Open_vSwitch").getVersion();
43     }
44
45     @Test
46     public void testTableNotSupported() {
47         // Don't run this test if the table is supported
48         Assume.assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) < 0);
49         boolean isExceptionRaised = false;
50         try {
51             FlowSampleCollectorSet flowSampleCollectorSet = ovs.createTypedRowWrapper(FlowSampleCollectorSet.class);
52         } catch (SchemaVersionMismatchException e) {
53             isExceptionRaised = true;
54         }
55         Assert.assertTrue(isExceptionRaised);
56     }
57
58
59     @Test
60     public void testCreateTypedFlowSampleCollectorSet() throws InterruptedException, ExecutionException, IllegalArgumentException{
61         // Don't run this test if the table is not supported
62         Assume.assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) >= 0);
63         FlowSampleCollectorSet flowSampleCollectorSet = ovs.createTypedRowWrapper(FlowSampleCollectorSet.class);
64         flowSampleCollectorSet.setId(Long.valueOf(1));
65         flowSampleCollectorSet.setExternalIds(ImmutableMap.of("<3", "ovs"));
66         flowSampleCollectorSet.setBridge(OpenVswitchSchemaSuiteIT.getTestBridgeUuid());
67         Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
68         TransactionBuilder transactionBuilder = ovs.transactBuilder(OpenVswitchSchemaSuiteIT.dbSchema)
69                 .add(op.insert(flowSampleCollectorSet.getSchema())
70                         .value(flowSampleCollectorSet.getIdColumn())
71                         .value(flowSampleCollectorSet.getExternalIdsColumn())
72                         .value(flowSampleCollectorSet.getBridgeColumn()));
73         ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
74         List<OperationResult> operationResults = results.get();
75         Assert.assertFalse(operationResults.isEmpty());
76         // Check if Results matches the number of operations in transaction
77         Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
78         for (OperationResult result : operationResults) Assert.assertNull(result.getError());
79         logger.info("Insert operation results for FlowSampleCollectorSet = {} ", operationResults);
80     }
81
82     @Override
83     public void update(Object context, UpdateNotification upadateNotification) {
84
85     }
86
87     @Override
88     public void locked(Object context, List<String> ids) {
89
90     }
91
92     @Override
93     public void stolen(Object context, List<String> ids) {
94
95     }
96 }