Merge "Revert "Added controller is-connected code""
[netvirt.git] / openstack / net-virt-providers / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / providers / openflow13 / PipelineOrchestratorImplTest.java
1 /*
2  * Copyright (c) 2015 Inocybe Technologies.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
13
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;
23
24 /**
25  * Unit test for {@link PipelineOrchestratorImplTest}
26  */
27 @Ignore //TODO SB_MIGRATION
28 @PrepareForTest(PipelineOrchestratorImpl.class)
29 @RunWith(PowerMockRunner.class)
30 public class PipelineOrchestratorImplTest {
31
32     @Mock
33     private ServiceReference ref;
34     @Mock
35     private ServiceReference ref2;
36     @Mock
37     private AbstractServiceInstance serviceInstance;
38     @Mock
39     private AbstractServiceInstance serviceInstance2;
40
41     @InjectMocks
42     private PipelineOrchestratorImpl orchestrator;
43
44     @Before
45     public void setUp() {
46         //Random r = new Random();
47
48         orchestrator = new PipelineOrchestratorImpl();
49         // TODO SB_MIGRATION
50         //orchestrator.init();
51         orchestrator.start();
52
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);
59
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);
66
67         when(serviceInstance.getService()).thenReturn(Service.CLASSIFIER);
68         when(serviceInstance2.getService()).thenReturn(Service.INBOUND_NAT);*/
69     }
70
71     /***
72      * Registers a mock service and verifies the registration by asking the
73      * pipeline orchestrator to return the associated service from its internal
74      * registry
75      */
76     @Test
77     public void testRegisterService() {
78         orchestrator.registerService(ref, serviceInstance);
79         assertEquals("Error, registerService() service registration fails",
80                 serviceInstance,
81                 orchestrator.getServiceInstance(Service.CLASSIFIER));
82     }
83
84     /***
85      * Test method {@link PipelineOrchestratorImplr#registerService(Service)}
86      *
87      * Unregisters a mock service and verifies the process by asking the
88      * pipeline orchestrator to return the associated service from its internal
89      * registry
90      */
91     @Test
92     public void testUnRegisterService() {
93
94         orchestrator = new PipelineOrchestratorImpl();
95         //orchestrator.init();
96         orchestrator.start();
97         orchestrator.registerService(ref, serviceInstance);
98         orchestrator.unregisterService(ref);
99
100         assertEquals("Error, unregisterService() service registration fails",
101                 null, orchestrator.getServiceInstance(Service.CLASSIFIER));
102
103     }
104
105     /**
106      * Test method
107      * {@link PipelineOrchestratorImplr#getNextServiceInPipeline(Service)}
108      */
109     @Test
110     public void testGetNextServiceInPipeline() {
111
112         assertEquals(orchestrator.getNextServiceInPipeline(Service.CLASSIFIER),
113                 Service.ARP_RESPONDER);
114         assertEquals(
115                 orchestrator.getNextServiceInPipeline(Service.ARP_RESPONDER),
116                 Service.INBOUND_NAT);
117         assertEquals(
118                 orchestrator.getNextServiceInPipeline(Service.INBOUND_NAT),
119                 Service.EGRESS_ACL);
120         assertEquals(orchestrator.getNextServiceInPipeline(Service.EGRESS_ACL),
121                 Service.LOAD_BALANCER);
122         assertEquals(
123                 orchestrator.getNextServiceInPipeline(Service.LOAD_BALANCER),
124                 Service.ROUTING);
125         assertEquals(orchestrator.getNextServiceInPipeline(Service.ROUTING),
126                 Service.L3_FORWARDING);
127         assertEquals(
128                 orchestrator.getNextServiceInPipeline(Service.L3_FORWARDING),
129                 Service.L2_REWRITE);
130         assertEquals(orchestrator.getNextServiceInPipeline(Service.L2_REWRITE),
131                 Service.INGRESS_ACL);
132         assertEquals(
133                 orchestrator.getNextServiceInPipeline(Service.INGRESS_ACL),
134                 Service.OUTBOUND_NAT);
135         assertEquals(
136                 orchestrator.getNextServiceInPipeline(Service.OUTBOUND_NAT),
137                 Service.L2_FORWARDING);
138         assertNull(orchestrator.getNextServiceInPipeline(Service.L2_FORWARDING));
139
140     }
141
142     /**
143      * Test method {@link PipelineOrchestratorImpl#getServiceInstance(Service)}
144      */
145     @Test
146     public void testGetServiceInstance() {
147
148         orchestrator = new PipelineOrchestratorImpl();
149         //orchestrator.init();
150         orchestrator.start();
151         orchestrator.registerService(ref, serviceInstance);
152         orchestrator.registerService(ref2, serviceInstance2);
153
154         assertEquals(
155                 "Error, getServiceInstance() fails to return an instance of a registered service",
156                 serviceInstance,
157                 orchestrator.getServiceInstance(Service.CLASSIFIER));
158
159         assertEquals(
160                 "Error, getServiceInstance() returned an instance of a service that wasn't registered.",
161                 null, orchestrator.getServiceInstance(Service.DIRECTOR));
162     }
163
164 }