/*\r
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
*\r
* This program and the accompanying materials are made available under the\r
* terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
\r
package org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.processors;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
import static org.mockito.Matchers.any;\r
import static org.mockito.Matchers.eq;\r
import static org.mockito.Mockito.verify;\r
\r
-import java.util.Collection;\r
+import java.util.concurrent.ExecutionException;\r
\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.mockito.Mockito;\r
import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;\r
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;\r
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;\r
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.MacAddressType;\r
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
-import org.opendaylight.yangtools.concepts.ListenerRegistration;\r
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
\r
-public class NeutronListenerTest extends AbstractDataBrokerTest implements DataTreeChangeListener<VppEndpoint> {\r
+public class NeutronListenerTest extends AbstractDataBrokerTest {\r
\r
private DataBroker dataBroker;\r
- private Integer eventCount;\r
- private static final LogicalDatastoreType CONFIG = LogicalDatastoreType.CONFIGURATION;\r
- private static final LogicalDatastoreType OPER = LogicalDatastoreType.OPERATIONAL;\r
\r
- private final Port port = new PortBuilder().setUuid(new Uuid("00000000-1111-2222-3333-444444444444")).build();\r
- private final BaseEndpointByPort bebp = new BaseEndpointByPortBuilder().setContextId(\r
- new ContextId("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"))\r
- .setAddress("00:11:11:11:11:11")\r
- .setPortId(new UniqueId("00000000-1111-2222-3333-444444444444"))\r
- .setContextType(MappingUtils.L2_BRDIGE_DOMAIN)\r
- .setAddressType(MacAddressType.class)\r
- .build();\r
+ private SocketInfo socketInfo;\r
+ private Port port;\r
+ private BaseEndpointByPort bebp;\r
+ private NeutronListener neutronListener;\r
+ private BaseEndpointByPortListener baseEpByPortListener;\r
\r
@Before\r
public void init() {\r
+ port = TestUtils.createValidVppPort();\r
+ bebp = TestUtils.createBaseEndpointByPortForPort();\r
+ socketInfo = new SocketInfo("/tmp/", "_socket");\r
dataBroker = getDataBroker();\r
+ neutronListener = new NeutronListener(dataBroker, socketInfo);\r
+ neutronListener.clearDataChangeProviders();\r
+ baseEpByPortListener = Mockito.spy(new BaseEndpointByPortListener(new PortHandler(\r
+ dataBroker, socketInfo), dataBroker));\r
+ neutronListener.addDataChangeProvider(baseEpByPortListener);\r
}\r
\r
@Test\r
public void constructorTest() {\r
dataBroker = Mockito.spy(dataBroker);\r
- NeutronListener neutronListener = new NeutronListener(dataBroker);\r
+ NeutronListener neutronListener = new NeutronListener(dataBroker, socketInfo);\r
verify(dataBroker).registerDataTreeChangeListener(\r
eq(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,\r
InstanceIdentifier.builder(Neutron.class)\r
}\r
\r
@Test\r
- public void createAndDeleteTest() throws Exception {\r
- eventCount = 0;\r
- ListenerRegistration<NeutronListenerTest> registerDataTreeChangeListener = registerVppEpListener();\r
- NeutronListener neutronListener = new NeutronListener(dataBroker);\r
+ public void testProcessCreatedNeutronDto() throws Exception {\r
+ putPortAndBaseEndpointByPort();\r
+ neutronListener.close();\r
+ verify(baseEpByPortListener).processCreatedNeutronDto(port);\r
+ }\r
+\r
+ @Test\r
+ public void testProcessUpdatedNeutronDto() throws Exception {\r
+ putPortAndBaseEndpointByPort();\r
+ Port updatedPort = new PortBuilder(port).setName("renamed").build();\r
WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
- wTx.put(CONFIG, TestUtils.createPortIid(port.getKey()), port);\r
- wTx.put(OPER, TestUtils.createBaseEpByPortIid(port.getUuid()), bebp);\r
+ wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(updatedPort.getKey()), updatedPort);\r
wTx.submit().get();\r
- wTx = dataBroker.newWriteOnlyTransaction();\r
- wTx.delete(CONFIG, TestUtils.createPortIid(port.getKey()));\r
- wTx.delete(OPER, TestUtils.createBaseEpByPortIid(port.getUuid()));\r
- DataStoreHelper.submitToDs(wTx);\r
- // manual delay for max 5s\r
- for (int i = 0; i < 50; i++) {\r
- if (eventCount >= 2) {\r
- break;\r
- }\r
- Thread.sleep(100);\r
- }\r
- assertEquals(Integer.valueOf(2), eventCount);\r
- registerDataTreeChangeListener.close();\r
neutronListener.close();\r
+ verify(baseEpByPortListener).processUpdatedNeutronDto(port, updatedPort);\r
}\r
\r
- @Override\r
- public void onDataTreeChanged(Collection<DataTreeModification<VppEndpoint>> changes) {\r
- for (DataTreeModification<VppEndpoint> change : changes) {\r
- DataObjectModification<VppEndpoint> vppEpChange = change.getRootNode();\r
- ModificationType modType = vppEpChange.getModificationType();\r
- if (modType.equals(ModificationType.WRITE)) {\r
- assertNull(vppEpChange.getDataBefore());\r
- assertNotNull(vppEpChange.getDataAfter());\r
- eventCount++;\r
- } else if (modType.equals(ModificationType.DELETE)) {\r
- assertNotNull(vppEpChange.getDataBefore());\r
- assertNull(vppEpChange.getDataAfter());\r
- eventCount++;\r
- }\r
- }\r
+ @Test\r
+ public void testProcessDeletedNeutronDto() throws Exception {\r
+ putPortAndBaseEndpointByPort();\r
+ WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
+ wTx.delete(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()));\r
+ wTx.submit().get();\r
+ verify(baseEpByPortListener).processDeletedNeutronDto(port);\r
}\r
\r
- private ListenerRegistration<NeutronListenerTest> registerVppEpListener() {\r
- return dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,\r
- InstanceIdentifier.builder(Config.class).child(VppEndpoint.class).build()), this);\r
+ private void putPortAndBaseEndpointByPort() throws InterruptedException, ExecutionException {\r
+ WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
+ wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()), port);\r
+ wTx.put(LogicalDatastoreType.OPERATIONAL, TestUtils.createBaseEpByPortIid(port.getUuid()), bebp);\r
+ wTx.submit().get();\r
}\r
}\r