Cleaned up Integration Tests
[controller.git] / opendaylight / forwardingrulesmanager / integrationtest / src / test / java / org / opendaylight / controller / forwardingrulesmanager / internal / ForwardingRulesManagerIT.java
1 package org.opendaylight.controller.forwardingrulesmanager.internal;
2
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11 import org.osgi.framework.ServiceReference;
12 import org.osgi.framework.Bundle;
13 import javax.inject.Inject;
14
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.junit.Before;
18 import org.junit.runner.RunWith;
19 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
20 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
21 import org.opendaylight.controller.sal.action.Action;
22 import org.opendaylight.controller.sal.action.Drop;
23 import org.opendaylight.controller.sal.core.Node;
24 import org.opendaylight.controller.sal.core.NodeConnector;
25 import org.opendaylight.controller.sal.flowprogrammer.Flow;
26 import org.opendaylight.controller.sal.match.Match;
27 import org.opendaylight.controller.sal.match.MatchType;
28 import org.opendaylight.controller.sal.reader.FlowOnNode;
29 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
30 import org.opendaylight.controller.sal.reader.NodeDescription;
31 import org.opendaylight.controller.sal.utils.NodeCreator;
32 import org.opendaylight.controller.sal.utils.Status;
33 import org.opendaylight.controller.sal.utils.StatusCode;
34 import org.ops4j.pax.exam.junit.PaxExam;
35 import org.osgi.framework.BundleContext;
36 import static org.junit.Assert.*;
37 import org.ops4j.pax.exam.junit.Configuration;
38 import static org.ops4j.pax.exam.CoreOptions.*;
39
40 import org.ops4j.pax.exam.Option;
41 import org.ops4j.pax.exam.util.PathUtils;
42
43 @RunWith(PaxExam.class)
44 public class ForwardingRulesManagerIT {
45     private Logger log = LoggerFactory.getLogger(ForwardingRulesManagerIT.class);
46     // get the OSGI bundle context
47     @Inject
48     private BundleContext bc;
49
50     private IForwardingRulesManager manager = null;
51
52     // Configure the OSGi container
53     @Configuration
54     public Option[] config() {
55         return options(
56                 //
57                 systemProperty("logback.configurationFile").value(
58                         "file:" + PathUtils.getBaseDir()
59                                 + "/src/test/resources/logback.xml"),
60                 // To start OSGi console for inspection remotely
61                 systemProperty("osgi.console").value("2401"),
62                 // Set the systemPackages (used by clustering)
63                 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
64                 // List framework bundles
65                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
66                         "1.0.0.v20120522-1841"),
67                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
68                         "1.0.400.v20120522-2049"),
69                 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
70                         "3.3.100.v20120522-1822"),
71                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
72                         "1.4.0.v20120522-1841"),
73                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
74                         "0.8.0.v201108120515"),
75                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
76                         "0.8.0.v201108120515"),
77                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
78                         "0.8.0.v201110170705"),
79                 // List logger bundles
80                 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
81                 mavenBundle("org.slf4j", "log4j-over-slf4j")
82                         .versionAsInProject(),
83                 mavenBundle("ch.qos.logback", "logback-core")
84                         .versionAsInProject(),
85                 mavenBundle("ch.qos.logback", "logback-classic")
86                         .versionAsInProject(),
87                 // List all the bundles on which the test case depends
88                 mavenBundle("org.opendaylight.controller", "sal")
89                         .versionAsInProject(),
90                 mavenBundle("org.opendaylight.controller", "sal.implementation")
91                         .versionAsInProject(),
92
93                 mavenBundle("org.opendaylight.controller",
94                         "protocol_plugins.stub").versionAsInProject(),
95
96                 mavenBundle("org.opendaylight.controller", "containermanager")
97                         .versionAsInProject(),
98                 mavenBundle("org.opendaylight.controller",
99                         "containermanager.implementation").versionAsInProject(),
100
101                 mavenBundle("org.opendaylight.controller",
102                         "forwardingrulesmanager").versionAsInProject(),
103
104                 mavenBundle("org.opendaylight.controller",
105                         "forwardingrulesmanager.implementation")
106                         .versionAsInProject(),
107
108                 mavenBundle("org.opendaylight.controller",
109                         "clustering.services").versionAsInProject(),
110                 mavenBundle("org.opendaylight.controller", "clustering.stub")
111                         .versionAsInProject(),
112                 mavenBundle("org.opendaylight.controller", "switchmanager")
113                         .versionAsInProject(),
114                 mavenBundle("org.opendaylight.controller",
115                         "switchmanager.implementation").versionAsInProject(),
116                 mavenBundle("org.opendaylight.controller", "configuration")
117                         .versionAsInProject(),
118
119                 mavenBundle("org.opendaylight.controller",
120                         "configuration.implementation").versionAsInProject(),
121                 mavenBundle("org.opendaylight.controller", "hosttracker")
122                         .versionAsInProject(),
123                 mavenBundle("org.opendaylight.controller",
124                         "hosttracker.implementation").versionAsInProject(),
125
126                 // needed by hosttracker
127                 mavenBundle("org.opendaylight.controller", "topologymanager")
128                         .versionAsInProject(),
129
130                 mavenBundle("org.jboss.spec.javax.transaction",
131                         "jboss-transaction-api_1.1_spec").versionAsInProject(),
132                 mavenBundle("org.apache.commons", "commons-lang3")
133                         .versionAsInProject(),
134                 mavenBundle("org.apache.felix",
135                         "org.apache.felix.dependencymanager")
136                         .versionAsInProject(), junitBundles());
137     }
138
139     private String stateToString(int state) {
140         switch (state) {
141         case Bundle.ACTIVE:
142             return "ACTIVE";
143         case Bundle.INSTALLED:
144             return "INSTALLED";
145         case Bundle.RESOLVED:
146             return "RESOLVED";
147         case Bundle.UNINSTALLED:
148             return "UNINSTALLED";
149         default:
150             return "Not CONVERTED";
151         }
152     }
153
154     @Before
155     public void areWeReady() {
156         assertNotNull(bc);
157         boolean debugit = false;
158         Bundle b[] = bc.getBundles();
159         for (int i = 0; i < b.length; i++) {
160             int state = b[i].getState();
161             if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
162                 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
163                         + stateToString(state));
164                 debugit = true;
165             }
166         }
167         if (debugit) {
168             log.debug("Do some debugging because some bundle is "
169                     + "unresolved");
170         }
171
172         // Assert if true, if false we are good to go!
173         assertFalse(debugit);
174
175         ServiceReference r = bc
176                 .getServiceReference(IForwardingRulesManager.class.getName());
177         if (r != null) {
178             this.manager = (IForwardingRulesManager) bc.getService(r);
179         }
180         // If StatisticsManager is null, cannot run tests.
181         assertNotNull(this.manager);
182
183     }
184
185     @Test
186     public void testFlowEntries() {
187         Flow flow = new Flow();
188
189         Match match = new Match();
190         try {
191             match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
192         } catch (UnknownHostException e) {
193         }
194         flow.setMatch(match);
195         Action action = new Drop();
196
197         List<Action> actions = new ArrayList<Action>();
198         actions.add(action);
199         flow.setActions(actions);
200
201         Node node = NodeCreator.createOFNode(1L);
202         FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
203
204         Status stat = manager.installFlowEntry(null);
205         Assert.assertTrue(stat.getCode().equals(StatusCode.NOTACCEPTABLE));
206     }
207
208 }