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.mockito.Matchers.anyString;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
17 import java.lang.reflect.Field;
18 import java.util.concurrent.ExecutorService;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
25 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
26 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
27 import org.osgi.framework.BundleContext;
28 import org.osgi.framework.ServiceReference;
29 import org.powermock.api.mockito.PowerMockito;
30 import org.powermock.core.classloader.annotations.PrepareForTest;
31 import org.powermock.modules.junit4.PowerMockRunner;
34 * Unit test for {@link PipelineOrchestratorImplTest}
36 @PrepareForTest(ServiceHelper.class)
37 @RunWith(PowerMockRunner.class)
38 public class PipelineOrchestratorImplTest {
39 @InjectMocks private PipelineOrchestratorImpl orchestrator;
41 @Mock private ExecutorService eventHandler;
42 @Mock private Southbound southbound;
45 * Registers a mock service and verifies the registration by asking the
46 * pipeline orchestrator to return the associated service from its internal
50 public void testRegisterAndUnregisterService() {
51 Service service = Service.CLASSIFIER;
52 ServiceReference<?> serviceReference = mock(ServiceReference.class);
53 when(serviceReference.getProperty(anyString())).thenReturn(service);
55 AbstractServiceInstance abstractServiceInstance = mock(AbstractServiceInstance.class);
57 orchestrator.registerService(serviceReference, abstractServiceInstance);
58 assertEquals("Error, registerService() service registration fails",
59 abstractServiceInstance,
60 orchestrator.getServiceInstance(service));
62 orchestrator.unregisterService(serviceReference);
63 assertNull("Error, unregisterService() didn't delete the service", orchestrator.getServiceInstance(service));
68 * {@link PipelineOrchestratorImplr#getNextServiceInPipeline(Service)}
71 public void testGetNextServiceInPipeline() {
73 assertEquals(orchestrator.getNextServiceInPipeline(Service.CLASSIFIER),
74 Service.ARP_RESPONDER);
76 orchestrator.getNextServiceInPipeline(Service.ARP_RESPONDER),
79 orchestrator.getNextServiceInPipeline(Service.INBOUND_NAT),
81 assertEquals(orchestrator.getNextServiceInPipeline(Service.EGRESS_ACL),
82 Service.LOAD_BALANCER);
84 orchestrator.getNextServiceInPipeline(Service.LOAD_BALANCER),
86 assertEquals(orchestrator.getNextServiceInPipeline(Service.ROUTING),
87 Service.L3_FORWARDING);
89 orchestrator.getNextServiceInPipeline(Service.L3_FORWARDING),
91 assertEquals(orchestrator.getNextServiceInPipeline(Service.L2_REWRITE),
94 orchestrator.getNextServiceInPipeline(Service.INGRESS_ACL),
95 Service.OUTBOUND_NAT);
97 orchestrator.getNextServiceInPipeline(Service.OUTBOUND_NAT),
98 Service.L2_FORWARDING);
99 assertNull(orchestrator.getNextServiceInPipeline(Service.L2_FORWARDING));
103 public void testSetDependencies() throws Exception {
104 NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
105 Southbound southbound = mock(Southbound.class);
107 PowerMockito.mockStatic(ServiceHelper.class);
108 PowerMockito.when(ServiceHelper.getGlobalInstance(NodeCacheManager.class, orchestrator)).thenReturn(nodeCacheManager);
109 PowerMockito.when(ServiceHelper.getGlobalInstance(Southbound.class, orchestrator)).thenReturn(southbound);
111 orchestrator.setDependencies(mock(BundleContext.class), mock(ServiceReference.class));
113 // assertEquals("Error, did not return the correct object", getField("nodeCacheManager"), nodeCacheManager);
114 assertEquals("Error, did not return the correct object", getField("southbound"), southbound);
117 private Object getField(String fieldName) throws Exception {
118 Field field = PipelineOrchestratorImpl.class.getDeclaredField(fieldName);
119 field.setAccessible(true);
120 return field.get(orchestrator);