Removing ovsdb plugin dependency on sal.utils classes
[netvirt.git] / integrationtest / src / test / java / org / opendaylight / ovsdb / integrationtest / netvirt / NetVirtIT.java
1 package org.opendaylight.ovsdb.integrationtest.netvirt;
2
3 import static org.ops4j.pax.exam.CoreOptions.maven;
4 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
5 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
6 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
7 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
8 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
9
10 import java.io.File;
11 import java.io.IOException;
12 import java.util.concurrent.ExecutionException;
13 import javax.inject.Inject;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
18 import org.ops4j.pax.exam.Configuration;
19 import org.ops4j.pax.exam.Option;
20 import org.ops4j.pax.exam.junit.PaxExam;
21 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
22 import org.osgi.framework.Bundle;
23 import org.osgi.framework.BundleContext;
24 import org.osgi.framework.InvalidSyntaxException;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 @RunWith(PaxExam.class)
29 public class NetVirtIT extends OvsdbIntegrationTestBase {
30     private Logger LOG = LoggerFactory.getLogger(NetVirtIT.class);
31     private static final String NETVIRT = "org.opendaylight.ovsdb.openstack.net-virt-providers";
32
33     @Inject
34     private BundleContext bc;
35
36     @Configuration
37     public Option[] config() {
38         return new Option[] {
39                 // Provision and launch a container based on a distribution of Karaf (Apache ServiceMix).
40                 karafDistributionConfiguration()
41                         .frameworkUrl(
42                                 maven()
43                                         .groupId("org.opendaylight.ovsdb")
44                                         .artifactId("distribution-karaf")
45                                         .type("tar.gz")
46                                         .version("1.3.0-SNAPSHOT"))
47                         .name("OpenDaylight")
48                         .unpackDirectory(new File("target/pax"))
49                         .useDeployFolder(false),
50                 // It is really nice if the container sticks around after the test so you can check the contents
51                 // of the data directory when things go wrong.
52                 keepRuntimeFolder(),
53                 // Don't bother with local console output as it just ends up cluttering the logs
54                 configureConsole().ignoreLocalConsole(),
55                 // Force the log level to INFO so we have more details during the test.  It defaults to WARN.
56                 logLevel(LogLevel.INFO),
57                 // Remember that the test executes in another process.  If you want to debug it, you need
58                 // to tell Pax Exam to launch that process with debugging enabled.  Launching the test class itself with
59                 // debugging enabled (for example in Eclipse) will not get you the desired results.
60                 //debugConfiguration("5005", true),
61                 features("mvn:org.opendaylight.controller/features-base/1.5.0-SNAPSHOT/xml/features",
62                        "odl-base-all"),
63                 features("mvn:org.opendaylight.controller/features-neutron/0.5.0-SNAPSHOT/xml/features",
64                         "odl-neutron-all"),
65                 features("mvn:org.opendaylight.ovsdb/features-ovsdb/1.1.1-SNAPSHOT/xml/features",
66                         "odl-ovsdb-openstack")
67         };
68     }
69
70     @Before
71     public void setUp () throws ExecutionException, InterruptedException, IOException, InvalidSyntaxException {
72         areWeReady(bc);
73
74         // TODO: this is where we should connect, but it fails currently because of
75         // dependency issues.
76         //try {
77         //    node = getPluginTestConnection();
78         //} catch (Exception e) {
79         //    fail("Exception : " + e.getMessage());
80         //}
81         isBundleReady(bc, NETVIRT);
82         // To be certain that all the bundles are Active sleep some more.
83         Thread.sleep(5000);
84     }
85
86     @Test
87     public void testGetProperty ()  throws Exception {
88         LOG.info(">>>>> We did it! Try to connect!");
89         LOG.info(">>>>> We did it! Try to connect!");
90         LOG.info(">>>>> We did it! Try to connect!");
91         Thread.sleep(10000);
92     }
93
94     /**
95      * isBundleReady is used to check if the requested bundle is Active
96      */
97     public void isBundleReady (BundleContext bc, String bundleName) throws InterruptedException {
98         boolean ready = false;
99
100         while (!ready) {
101             int state = Bundle.UNINSTALLED;
102             Bundle b[] = bc.getBundles();
103             for (Bundle element : b) {
104                 if (element.getSymbolicName().equals(bundleName)) {
105                     state = element.getState();
106                     break;
107                 }
108             }
109             if (state != Bundle.ACTIVE) {
110                 LOG.info(">>>>> bundle not ready");
111                 Thread.sleep(5000);
112             } else {
113                 ready = true;
114             }
115         }
116     }
117 }