Code ReOrganization and Re-Architecture changes
[ovsdb.git] / library / src / test / java / org / opendaylight / ovsdb / lib / OvsDBClientTestIT.java
1 /*
2  * Copyright (C) 2014 EBay Software Foundation
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 : Ashwin Raveendran
9  */
10 package org.opendaylight.ovsdb.lib;
11
12 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
13
14 import java.io.IOException;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors;
20
21 import junit.framework.Assert;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
26 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
27 import org.opendaylight.ovsdb.lib.operations.OperationResult;
28 import org.opendaylight.ovsdb.lib.schema.ATableSchema;
29 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
30 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
31 import org.opendaylight.ovsdb.lib.schema.TableSchema;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 import com.google.common.util.concurrent.ListenableFuture;
36
37
38 public class OvsDBClientTestIT extends OvsdbTestBase {
39     Logger logger = LoggerFactory.getLogger(OvsDBClientTestIT.class);
40
41     OvsDBClientImpl ovs;
42
43
44
45     @Test
46     public void testTransact() throws IOException, InterruptedException, ExecutionException {
47
48         ListenableFuture<DatabaseSchema> schema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true);
49         TableSchema<ATableSchema> bridge = schema.get().table("Bridge");
50
51         for (Map.Entry<String, ColumnSchema> names : bridge.getColumnSchemas().entrySet()) {
52             System.out.println("names = " + names.getKey());
53             System.out.println("names.getValue().getType() = " + names.getValue().getType().getBaseType());
54         }
55
56         ColumnSchema<ATableSchema, String> name = bridge.column("name", String.class);
57         ColumnSchema<ATableSchema, String> fail_mode = bridge.column("fail_mode", String.class);
58
59         ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
60                 .add(op.insert(bridge).value(name, "br-int"))
61                 .add(op.update(bridge)
62                         .set(fail_mode, "secure")
63                         .where(name.opEqual("br-int"))
64                         //.and(name.opEqual("br-int"))
65                         .operation())
66                 .execute();
67
68         List<OperationResult> operationResults = results.get();
69         Assert.assertFalse(operationResults.isEmpty());
70         System.out.println("operationResults = " + operationResults);
71     }
72
73     @Test
74     public void testGetDBs() throws ExecutionException, InterruptedException {
75         ListenableFuture<List<String>> databases = ovs.getDatabases();
76         List<String> dbNames = databases.get();
77         Assert.assertNotNull(dbNames);
78         Assert.assertTrue(dbNames.size() > 0);
79     }
80
81     @Before
82     public  void initalize() throws IOException {
83         if (ovs != null) {
84             return;
85         }
86         OvsdbRPC rpc = getTestConnection();
87         if (rpc == null) {
88             System.out.println("Unable to Establish Test Connection");
89         }
90         ExecutorService executorService = Executors.newFixedThreadPool(3);
91         ovs = new OvsDBClientImpl(rpc, executorService);
92     }
93
94
95     @Override
96     public void update(Object node, UpdateNotification upadateNotification) {
97         // TODO Auto-generated method stub
98
99     }
100     @Override
101     public void locked(Object node, List<String> ids) {
102         // TODO Auto-generated method stub
103
104     }
105     @Override
106     public void stolen(Object node, List<String> ids) {
107         // TODO Auto-generated method stub
108
109     }
110 }