2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.processors;
\r
11 import static org.mockito.Matchers.any;
\r
12 import static org.mockito.Matchers.eq;
\r
13 import static org.mockito.Mockito.verify;
\r
15 import java.util.concurrent.ExecutionException;
\r
17 import org.junit.Before;
\r
18 import org.junit.Test;
\r
19 import org.mockito.Mockito;
\r
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
21 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
\r
22 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
\r
23 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
\r
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
\r
25 import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;
\r
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
\r
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
\r
35 public class NeutronListenerTest extends AbstractDataBrokerTest {
\r
37 private DataBroker dataBroker;
\r
39 private SocketInfo socketInfo;
\r
41 private BaseEndpointByPort bebp;
\r
42 private NeutronListener neutronListener;
\r
43 private PortAware baseEpByPortListener;
\r
46 public void init() {
\r
47 port = TestUtils.createValidVppPort();
\r
48 bebp = TestUtils.createBaseEndpointByPortForPort();
\r
49 socketInfo = new SocketInfo("/tmp/", "_socket");
\r
50 dataBroker = getDataBroker();
\r
51 neutronListener = new NeutronListener(dataBroker, socketInfo);
\r
52 neutronListener.clearDataChangeProviders();
\r
53 baseEpByPortListener = Mockito.spy(new PortAware(new PortHandler(
\r
54 dataBroker, socketInfo), dataBroker));
\r
55 neutronListener.addDataChangeProvider(baseEpByPortListener);
\r
59 public void constructorTest() {
\r
60 dataBroker = Mockito.spy(dataBroker);
\r
61 NeutronListener neutronListener = new NeutronListener(dataBroker, socketInfo);
\r
62 verify(dataBroker).registerDataTreeChangeListener(
\r
63 eq(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
\r
64 InstanceIdentifier.builder(Neutron.class)
\r
65 .build())), any(NeutronListener.class));
\r
66 verify(dataBroker).registerDataTreeChangeListener(
\r
67 eq(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
\r
68 InstanceIdentifier.builder(Mappings.class)
\r
69 .child(GbpByNeutronMappings.class)
\r
70 .child(BaseEndpointsByPorts.class)
\r
71 .child(BaseEndpointByPort.class)
\r
72 .build())), any(PortAware.class));
\r
73 neutronListener.close();
\r
77 public void testProcessCreatedNeutronDto() throws Exception {
\r
78 putPortAndBaseEndpointByPort();
\r
79 neutronListener.close();
\r
80 verify(baseEpByPortListener).processCreatedNeutronDto(port);
\r
84 public void testProcessUpdatedNeutronDto() throws Exception {
\r
85 putPortAndBaseEndpointByPort();
\r
86 Port updatedPort = new PortBuilder(port).setName("renamed").build();
\r
87 WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
\r
88 wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(updatedPort.getKey()), updatedPort);
\r
90 neutronListener.close();
\r
91 verify(baseEpByPortListener).processUpdatedNeutronDto(port, updatedPort);
\r
95 public void testProcessDeletedNeutronDto() throws Exception {
\r
96 putPortAndBaseEndpointByPort();
\r
97 WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
\r
98 wTx.delete(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()));
\r
100 verify(baseEpByPortListener).processDeletedNeutronDto(port);
\r
103 private void putPortAndBaseEndpointByPort() throws InterruptedException, ExecutionException {
\r
104 WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
\r
105 wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()), port);
\r
106 wTx.put(LogicalDatastoreType.OPERATIONAL, TestUtils.createBaseEpByPortIid(port.getUuid()), bebp);
\r
107 wTx.submit().get();
\r