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;
14 import org.junit.Before;
15 import org.junit.Ignore;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.InjectMocks;
19 import org.mockito.Mock;
20 import org.osgi.framework.ServiceReference;
21 import org.powermock.core.classloader.annotations.PrepareForTest;
22 import org.powermock.modules.junit4.PowerMockRunner;
25 * Unit test for {@link PipelineOrchestratorImplTest}
27 @Ignore //TODO SB_MIGRATION
28 @PrepareForTest(PipelineOrchestratorImpl.class)
29 @RunWith(PowerMockRunner.class)
30 public class PipelineOrchestratorImplTest {
33 private ServiceReference ref;
35 private ServiceReference ref2;
37 private AbstractServiceInstance serviceInstance;
39 private AbstractServiceInstance serviceInstance2;
42 private PipelineOrchestratorImpl orchestrator;
46 //Random r = new Random();
48 orchestrator = new PipelineOrchestratorImpl();
50 //orchestrator.init();
53 /*when(ref.getProperty(org.osgi.framework.Constants.SERVICE_ID))
54 .thenReturn(r.nextLong());
55 when(ref.getProperty(Constants.EVENT_HANDLER_TYPE_PROPERTY))
56 .thenReturn(handlerTypeObject);
57 when(ref.getProperty(AbstractServiceInstance.SERVICE_PROPERTY))
58 .thenReturn(Service.CLASSIFIER);
60 when(ref2.getProperty(org.osgi.framework.Constants.SERVICE_ID))
61 .thenReturn(r.nextLong());
62 when(ref2.getProperty(Constants.EVENT_HANDLER_TYPE_PROPERTY))
63 .thenReturn(handlerTypeObject);
64 when(ref2.getProperty(AbstractServiceInstance.SERVICE_PROPERTY))
65 .thenReturn(Service.INBOUND_NAT);
67 when(serviceInstance.getService()).thenReturn(Service.CLASSIFIER);
68 when(serviceInstance2.getService()).thenReturn(Service.INBOUND_NAT);*/
72 * Registers a mock service and verifies the registration by asking the
73 * pipeline orchestrator to return the associated service from its internal
77 public void testRegisterService() {
78 orchestrator.registerService(ref, serviceInstance);
79 assertEquals("Error, registerService() service registration fails",
81 orchestrator.getServiceInstance(Service.CLASSIFIER));
85 * Test method {@link PipelineOrchestratorImplr#registerService(Service)}
87 * Unregisters a mock service and verifies the process by asking the
88 * pipeline orchestrator to return the associated service from its internal
92 public void testUnRegisterService() {
94 orchestrator = new PipelineOrchestratorImpl();
95 //orchestrator.init();
97 orchestrator.registerService(ref, serviceInstance);
98 orchestrator.unregisterService(ref);
100 assertEquals("Error, unregisterService() service registration fails",
101 null, orchestrator.getServiceInstance(Service.CLASSIFIER));
107 * {@link PipelineOrchestratorImplr#getNextServiceInPipeline(Service)}
110 public void testGetNextServiceInPipeline() {
112 assertEquals(orchestrator.getNextServiceInPipeline(Service.CLASSIFIER),
113 Service.ARP_RESPONDER);
115 orchestrator.getNextServiceInPipeline(Service.ARP_RESPONDER),
116 Service.INBOUND_NAT);
118 orchestrator.getNextServiceInPipeline(Service.INBOUND_NAT),
120 assertEquals(orchestrator.getNextServiceInPipeline(Service.EGRESS_ACL),
121 Service.LOAD_BALANCER);
123 orchestrator.getNextServiceInPipeline(Service.LOAD_BALANCER),
125 assertEquals(orchestrator.getNextServiceInPipeline(Service.ROUTING),
126 Service.L3_FORWARDING);
128 orchestrator.getNextServiceInPipeline(Service.L3_FORWARDING),
130 assertEquals(orchestrator.getNextServiceInPipeline(Service.L2_REWRITE),
131 Service.INGRESS_ACL);
133 orchestrator.getNextServiceInPipeline(Service.INGRESS_ACL),
134 Service.OUTBOUND_NAT);
136 orchestrator.getNextServiceInPipeline(Service.OUTBOUND_NAT),
137 Service.L2_FORWARDING);
138 assertNull(orchestrator.getNextServiceInPipeline(Service.L2_FORWARDING));
143 * Test method {@link PipelineOrchestratorImpl#getServiceInstance(Service)}
146 public void testGetServiceInstance() {
148 orchestrator = new PipelineOrchestratorImpl();
149 //orchestrator.init();
150 orchestrator.start();
151 orchestrator.registerService(ref, serviceInstance);
152 orchestrator.registerService(ref2, serviceInstance2);
155 "Error, getServiceInstance() fails to return an instance of a registered service",
157 orchestrator.getServiceInstance(Service.CLASSIFIER));
160 "Error, getServiceInstance() returned an instance of a service that wasn't registered.",
161 null, orchestrator.getServiceInstance(Service.DIRECTOR));