2 * Copyright (C) 2014 Red Hat, Inc.
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
10 package org.opendaylight.ovsdb.schema.openvswitch;
12 import com.google.common.collect.ImmutableMap;
13 import com.google.common.collect.Sets;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import junit.framework.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
19 import org.opendaylight.ovsdb.lib.notation.Mutator;
20 import org.opendaylight.ovsdb.lib.notation.UUID;
21 import org.opendaylight.ovsdb.lib.operations.OperationResult;
22 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import java.io.IOException;
27 import java.util.List;
28 import java.util.concurrent.ExecutionException;
29 import java.util.concurrent.TimeoutException;
31 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
33 public class SslTestCases extends OpenVswitchSchemaTestBase {
34 Logger logger = LoggerFactory.getLogger(SslTestCases.class);
37 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
42 public void testCreateTypedSslTable() throws InterruptedException, ExecutionException, IllegalArgumentException {
44 String sslUuidStr = "sslUuidName";
45 String caCert = "PARC";
46 String certificate = "01101110 01100101 01110010 01100100";
47 String privateKey = "SSL_Table_Test_Secret";
48 ImmutableMap<String, String> externalIds = ImmutableMap.of("roomba", "powered");
50 SSL ssl = ovs.createTypedRowWrapper(SSL.class);
51 ssl.setCaCert(caCert);
52 ssl.setCertificate(certificate);
53 ssl.setPrivateKey(privateKey);
54 ssl.setExternalIds(externalIds);
55 // Get the parent OVS table UUID in it's single row
56 UUID openVSwitchRowUuid = this.getOpenVSwitchTableUuid(ovs, OpenVswitchSchemaSuiteIT.getTableCache());
57 OpenVSwitch openVSwitch = ovs.getTypedRowWrapper(OpenVSwitch.class, null);
58 // The transaction index for the SSL insert is used to store the SSL UUID
59 int insertSslOperationIndex = 0;
60 TransactionBuilder transactionBuilder = ovs.transactBuilder(OpenVswitchSchemaSuiteIT.dbSchema)
61 .add(op.insert(ssl.getSchema())
63 .value(ssl.getCertificateColumn())
64 .value(ssl.getPrivateKeyColumn())
65 .value(ssl.getCaCertColumn())
66 .value(ssl.getExternalIdsColumn()))
67 .add(op.mutate(openVSwitch.getSchema())
68 .addMutation(openVSwitch.getSslColumn().getSchema(), Mutator.INSERT,
69 Sets.newHashSet(new UUID(sslUuidStr)))
70 .where(openVSwitch.getUuidColumn().getSchema().opEqual(openVSwitchRowUuid))
73 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
74 List<OperationResult> operationResults = results.get();
75 Assert.assertFalse(operationResults.isEmpty());
76 for (OperationResult result : operationResults) {
77 Assert.assertNull(result.getError());
79 // Store the returned SSL row UUID to be used in the TearDown deletion transaction
80 OpenVswitchSchemaSuiteIT.setTestSslUuid(operationResults.get(insertSslOperationIndex).getUuid());
81 // Check if Results matches the number of operations in transaction
82 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
83 logger.info("Insert & Mutate operation results for SSL = {} ", operationResults);
88 public void update(Object context, UpdateNotification upadateNotification) {
93 public void locked(Object context, List<String> ids) {
98 public void stolen(Object context, List<String> ids) {