Add Initial Pax Exam IT for OVSDB Northbound API 31/8331/1
authorDave Tucker <djt@redhat.com>
Wed, 25 Jun 2014 13:52:29 +0000 (14:52 +0100)
committerDave Tucker <djt@redhat.com>
Wed, 25 Jun 2014 13:52:29 +0000 (14:52 +0100)
- Add nortbound.yaml for defining test cases
- OvsdbNorthboundIT which parses yaml file and uses parameterized
  runner to run each test case
- Add coverage for the common GET operations

Change-Id: Ia24e2e6605335060cc8ed1d6a39d59853a16ccad
Signed-off-by: Dave Tucker <djt@redhat.com>
integrationtest/.gitignore
integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/northbound/OvsdbNorthboundIT.java [new file with mode: 0644]
integrationtest/src/test/resources/logback.xml
integrationtest/src/test/resources/northbound.yaml [new file with mode: 0644]
integrationtest/src/test/resources/tomcat-server.xml

index a48e45b9df040944defaa65e35fb09ca27311306..b677ad3d98e4b3350d19fc62d08e8cbb4c61c087 100644 (file)
@@ -1 +1,4 @@
 /target-ide
+PutObjectStoreHere
+ObjectStore
+logs
diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/northbound/OvsdbNorthboundIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/northbound/OvsdbNorthboundIT.java
new file mode 100644 (file)
index 0000000..cd0fca8
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ *  Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.integrationtest.northbound;
+
+import com.google.common.collect.Lists;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.junit.runners.Parameterized;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.usermanager.IUserManager;
+import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
+import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExamParameterized;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.PathUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
+import javax.inject.Inject;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+@RunWith(PaxExamParameterized.class)
+@ExamReactorStrategy(PerClass.class)
+public class OvsdbNorthboundIT extends OvsdbIntegrationTestBase {
+
+    private Logger log = LoggerFactory.getLogger(OvsdbNorthboundIT.class);
+    public static final String USERNAME = "admin";
+    public static final String PASSWORD = "admin";
+    public static final String BASE_URI = "http://localhost:8088";
+
+    @Inject
+    private BundleContext bc;
+    private Node node = null;
+    private IUserManager userManager;
+
+    @Parameterized.Parameters(name="{index}:({0})")
+    public static List<Object[]> getData() throws FileNotFoundException {
+        ClassLoader classloader = OvsdbNorthboundIT.class.getClassLoader();
+        InputStream input = classloader.getResourceAsStream("northbound.yaml");
+        Yaml yaml = new Yaml();
+        List<Map<String, Object>> object = (List<Map<String, Object>>) yaml.load(input);
+        List parameters = Lists.newArrayList();
+
+        for (Map<String, Object> o : object){
+            Object[] l = o.values().toArray();
+            parameters.add(l);
+        }
+
+        return parameters;
+
+    }
+
+    private String fTestCase;
+    private String fOperation;
+    private String fPath;
+    private String fJson;
+    private int fExpectedStatusCode;
+
+    public OvsdbNorthboundIT(String testCase, String operation, String path, String json, int expectedStatusCode){
+        fTestCase = testCase;
+        fOperation = operation;
+        fPath = path;
+        fJson = json;
+        fExpectedStatusCode = expectedStatusCode;
+    }
+
+    private String expandPath(String path){
+        String uri = BASE_URI + path;
+        uri = uri.replace("${node}", node.getNodeIDString());
+        return uri;
+    }
+
+    @Test
+    public void testApi(){
+
+        System.out.println("Running " + fTestCase);
+
+        Client client = Client.create();
+        client.addFilter(new HTTPBasicAuthFilter(USERNAME , PASSWORD));
+        WebResource webResource = client.resource(expandPath(fPath));
+        ClientResponse response = null;
+
+        switch (fOperation) {
+            case "GET":
+                response = webResource.accept("application/json")
+                        .get(ClientResponse.class);
+                break;
+            case "POST":
+                response = webResource.accept("application/json")
+                        .post(ClientResponse.class, fJson);
+                break;
+            case "PUT":
+                response = webResource.accept("application/json")
+                        .put(ClientResponse.class, fJson);
+                break;
+            case "DELETE":
+                response = webResource.accept("application/json")
+                        .put(ClientResponse.class, fJson);
+                break;
+            default:
+                fail("Unsupported operation");
+        }
+
+        System.out.println("" + response.toString());
+        assertEquals(fExpectedStatusCode, response.getStatus());
+
+    }
+
+     private String stateToString(int state) {
+        switch (state) {
+            case Bundle.ACTIVE:
+                return "ACTIVE";
+            case Bundle.INSTALLED:
+                return "INSTALLED";
+            case Bundle.RESOLVED:
+                return "RESOLVED";
+            case Bundle.UNINSTALLED:
+                return "UNINSTALLED";
+            default:
+                return "Not CONVERTED";
+        }
+    }
+
+    @Before
+    public void areWeReady() {
+        assertNotNull(bc);
+        boolean debugit = false;
+        Bundle b[] = bc.getBundles();
+        for (Bundle element : b) {
+            int state = element.getState();
+            if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
+                log.info("Bundle:" + element.getSymbolicName() + " state:"
+                        + stateToString(state));
+                debugit = true;
+            }
+        }
+        if (debugit) {
+            log.debug("Do some debugging because some bundle is unresolved");
+        }
+
+        // Fail if true, if false we are good to go!
+        assertFalse(debugit);
+
+        ServiceReference r = bc.getServiceReference(IUserManager.class.getName());
+        if (r != null) {
+            this.userManager = (IUserManager) bc.getService(r);
+        }
+        // If UserManager is null, cannot login to run tests.
+        assertTrue(this.userManager != null);
+
+        try {
+            node = getTestConnection();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Configuration
+    public static Option[] configuration() {
+        return options(
+                //
+                systemProperty("logback.configurationFile").value(
+                        "file:" + PathUtils.getBaseDir()
+                                + "/src/test/resources/logback.xml"
+                ),
+
+                systemProperty("org.eclipse.gemini.web.tomcat.config.path").value(
+                        PathUtils.getBaseDir() + "/src/test/resources/tomcat-server.xml"),
+
+                // To start OSGi console for inspection remotely
+                systemProperty("osgi.console").value("2401"),
+
+                propagateSystemProperty("ovsdbserver.ipaddress"),
+                propagateSystemProperty("ovsdbserver.port"),
+
+                ConfigurationBundles.controllerBundles(),
+                ConfigurationBundles.controllerNorthboundBundles(),
+                ConfigurationBundles.ovsdbLibraryBundles(),
+                mavenBundle("org.opendaylight.ovsdb", "ovsdb.northbound").versionAsInProject(),
+                junitBundles()
+        );
+    }
+}
+
index 0a137c5c6e3662a68d01fd580a1f2b5eff076eda..dead4a64af2a1773f8a181a3ad052e76b7e89d4f 100644 (file)
@@ -6,9 +6,9 @@
     </encoder>
   </appender>
 
-  <logger name="org.opendaylight.ovsdb.*" level="INFO" />
+  <logger name="org.opendaylight.ovsdb" level="INFO" />
 
-  <root level="error">
+  <root level="ERROR">
     <appender-ref ref="STDOUT" />
   </root>
 </configuration>
diff --git a/integrationtest/src/test/resources/northbound.yaml b/integrationtest/src/test/resources/northbound.yaml
new file mode 100644 (file)
index 0000000..856954b
--- /dev/null
@@ -0,0 +1,67 @@
+# This file contains test cases for the OVSDB Northbound API
+---
+- name: testGetBridgeRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/bridge/rows
+  json:
+  expected: 200
+
+- name: testGetPortRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/port/rows
+  json:
+  expected: 200
+
+- name: testGetInterfaceRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/interface/rows
+  json:
+  expected: 200
+
+- name: testGetControllerRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/controller/rows
+  json:
+  expected: 200
+
+- name: testGetSslRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/ssl/rows
+  json:
+  expected: 200
+
+- name: testGetSflowRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/sflow/rows
+  json:
+  expected: 200
+
+- name: testGetQosRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/qos/rows
+  json:
+  expected: 200
+
+- name: testGetQueueRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/queue/rows
+  json:
+  expected: 200
+
+- name: testGetNetflowRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/netflow/rows
+  json:
+  expected: 200
+
+- name: testGetManagerRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/manager/rows
+  json:
+  expected: 200
+
+- name: testGetOpenVswitchRows
+  operation: GET
+  uri: /ovsdb/nb/v2/node/OVS/${node}/tables/open_vswitch/rows
+  json:
+  expected: 200
index aa47aea8f5eb6269a61852dc78a466c3cfce9055..4cef1ef3d3486909ba35c2044bf6efb5243330bd 100644 (file)
         <Realm className="org.opendaylight.controller.security.ControllerCustomRealm" />
         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
 
+        <!--
         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                prefix="web_access_log_" suffix=".txt" resolveHosts="false"
                rotatable="true" fileDateFormat="yyyy-MM"
                pattern="%{yyyy-MM-dd HH:mm:ss.SSS z}t - [%a] - %r"/>
+        -->
 
       </Host>
     </Engine>