2 * Copyright © 2016 Red Hat, Inc. and others.
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
8 package org.opendaylight.ovsdb.southbound;
10 import java.net.InetAddress;
11 import java.net.UnknownHostException;
12 import java.util.concurrent.ExecutionException;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
19 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.ovsdb.lib.OvsdbConnection;
22 import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvokerImpl;
23 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 * Unit tests for the data-tree change listener.
34 public class OvsdbDataTreeChangeListenerTest extends AbstractDataBrokerTest {
36 private final OvsdbConnection ovsdbConnection = Mockito.mock(OvsdbConnection.class);
37 private DataBroker dataBroker;
38 private OvsdbDataTreeChangeListener listener;
41 public void setupListener() {
42 dataBroker = getDataBroker();
43 EntityOwnershipService entityOwnershipService = Mockito.mock(EntityOwnershipService.class);
44 listener = new OvsdbDataTreeChangeListener(dataBroker,
45 new OvsdbConnectionManager(dataBroker, new TransactionInvokerImpl(dataBroker), entityOwnershipService,
50 public void testConnect() throws UnknownHostException, InterruptedException, ExecutionException {
53 // When we request a connection ...
54 InetAddress inetAddress = InetAddress.getByName("127.0.0.1");
56 IpAddress ipAddress = SouthboundMapper.createIpAddress(inetAddress);
57 PortNumber portNumber = new PortNumber(port);
59 final ConnectionInfo connectionInfo = new ConnectionInfoBuilder()
60 .setRemoteIp(ipAddress)
61 .setRemotePort(portNumber)
63 final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
64 WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
65 transaction.put(LogicalDatastoreType.CONFIGURATION, iid, SouthboundUtils.createNode(connectionInfo),
66 WriteTransaction.CREATE_MISSING_PARENTS);
67 transaction.submit().get();
69 // Then the listener tries to open a connection
70 Mockito.verify(ovsdbConnection).connect(inetAddress, port);