2 * Copyright (c) 2015 Inocybe Technologies. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Matchers.any;
15 import static org.mockito.Matchers.anyString;
16 import static org.mockito.Mockito.mock;
17 import static org.mockito.Mockito.times;
18 import static org.mockito.Mockito.verify;
19 import static org.mockito.Mockito.when;
21 import java.lang.reflect.Field;
22 import java.util.Random;
23 import java.util.concurrent.BlockingQueue;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.runners.MockitoJUnitRunner;
32 import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
33 import org.opendaylight.neutron.spi.INeutronPortCRUD;
34 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
35 import org.opendaylight.neutron.spi.NeutronLoadBalancerPool;
36 import org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent;
37 import org.opendaylight.ovsdb.openstack.netvirt.AbstractHandler;
38 import org.opendaylight.ovsdb.openstack.netvirt.LBaaSHandler;
39 import org.opendaylight.ovsdb.openstack.netvirt.LBaaSPoolHandler;
40 import org.opendaylight.ovsdb.openstack.netvirt.NeutronCacheUtils;
41 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
42 import org.opendaylight.ovsdb.openstack.netvirt.impl.EventDispatcherImpl;
43 import org.osgi.framework.ServiceReference;
44 import org.powermock.api.mockito.PowerMockito;
45 import org.powermock.core.classloader.annotations.PrepareForTest;
46 import org.powermock.modules.junit4.PowerMockRunner;
49 * Unit test for {@link PipelineOrchestratorImplTest}
51 @PrepareForTest(PipelineOrchestratorImpl.class)
52 @RunWith(PowerMockRunner.class)
53 public class PipelineOrchestratorImplTest {
56 private ServiceReference ref;
58 private ServiceReference ref2;
60 private AbstractServiceInstance serviceInstance;
62 private AbstractServiceInstance serviceInstance2;
65 private PipelineOrchestratorImpl orchestrator;
67 private AbstractEvent.HandlerType handlerTypeObject = AbstractEvent.HandlerType.NEUTRON_FLOATING_IP;
71 Random r = new Random();
73 orchestrator = new PipelineOrchestratorImpl();
77 when(ref.getProperty(org.osgi.framework.Constants.SERVICE_ID))
78 .thenReturn(r.nextLong());
79 when(ref.getProperty(Constants.EVENT_HANDLER_TYPE_PROPERTY))
80 .thenReturn(handlerTypeObject);
81 when(ref.getProperty(AbstractServiceInstance.SERVICE_PROPERTY))
82 .thenReturn(Service.CLASSIFIER);
84 when(ref2.getProperty(org.osgi.framework.Constants.SERVICE_ID))
85 .thenReturn(r.nextLong());
86 when(ref2.getProperty(Constants.EVENT_HANDLER_TYPE_PROPERTY))
87 .thenReturn(handlerTypeObject);
88 when(ref2.getProperty(AbstractServiceInstance.SERVICE_PROPERTY))
89 .thenReturn(Service.INBOUND_NAT);
91 when(serviceInstance.getService()).thenReturn(Service.CLASSIFIER);
92 when(serviceInstance2.getService()).thenReturn(Service.INBOUND_NAT);
96 * Registers a mock service and verifies the registration by asking the
97 * pipeline orchestrator to return the associated service from its internal
101 public void testRegisterService() {
102 orchestrator.registerService(ref, serviceInstance);
103 assertEquals("Error, registerService() service registration fails",
105 orchestrator.getServiceInstance(Service.CLASSIFIER));
109 * Test method {@link PipelineOrchestratorImplr#registerService(Service)}
111 * Unregisters a mock service and verifies the process by asking the
112 * pipeline orchestrator to return the associated service from its internal
116 public void testUnRegisterService() {
118 orchestrator = new PipelineOrchestratorImpl();
120 orchestrator.start();
121 orchestrator.registerService(ref, serviceInstance);
122 orchestrator.unregisterService(ref);
124 assertEquals("Error, unregisterService() service registration fails",
125 null, orchestrator.getServiceInstance(Service.CLASSIFIER));
131 * {@link PipelineOrchestratorImplr#getNextServiceInPipeline(Service)}
134 public void testGetNextServiceInPipeline() {
136 assertEquals(orchestrator.getNextServiceInPipeline(Service.CLASSIFIER),
137 Service.ARP_RESPONDER);
139 orchestrator.getNextServiceInPipeline(Service.ARP_RESPONDER),
140 Service.INBOUND_NAT);
142 orchestrator.getNextServiceInPipeline(Service.INBOUND_NAT),
144 assertEquals(orchestrator.getNextServiceInPipeline(Service.EGRESS_ACL),
145 Service.LOAD_BALANCER);
147 orchestrator.getNextServiceInPipeline(Service.LOAD_BALANCER),
149 assertEquals(orchestrator.getNextServiceInPipeline(Service.ROUTING),
150 Service.L3_FORWARDING);
152 orchestrator.getNextServiceInPipeline(Service.L3_FORWARDING),
154 assertEquals(orchestrator.getNextServiceInPipeline(Service.L2_REWRITE),
155 Service.INGRESS_ACL);
157 orchestrator.getNextServiceInPipeline(Service.INGRESS_ACL),
158 Service.OUTBOUND_NAT);
160 orchestrator.getNextServiceInPipeline(Service.OUTBOUND_NAT),
161 Service.L2_FORWARDING);
162 assertNull(orchestrator.getNextServiceInPipeline(Service.L2_FORWARDING));
167 * Test method {@link PipelineOrchestratorImpl#getServiceInstance(Service)}
170 public void testGetServiceInstance() {
172 orchestrator = new PipelineOrchestratorImpl();
174 orchestrator.start();
175 orchestrator.registerService(ref, serviceInstance);
176 orchestrator.registerService(ref2, serviceInstance2);
179 "Error, getServiceInstance() fails to return an instance of a registered service",
181 orchestrator.getServiceInstance(Service.CLASSIFIER));
184 "Error, getServiceInstance() returned an instance of a service that wasn't registered.",
185 null, orchestrator.getServiceInstance(Service.DIRECTOR));