olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [2/3] olingo-odata4 git commit: Adding olingo-server side OSGi tests
Date Wed, 10 Jun 2015 08:55:49 GMT
Adding olingo-server side OSGi tests


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/7ab54a2b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/7ab54a2b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/7ab54a2b

Branch: refs/heads/OLINGO-642_OSGi-Sample
Commit: 7ab54a2b852a396fc34e5c0a1c781d7b2d78c6cb
Parents: 0b8d46f
Author: Aki Yoshida <elakito@gmail.com>
Authored: Tue Jun 9 18:33:36 2015 +0200
Committer: Michael Bolz <michael.bolz@sap.com>
Committed: Wed Jun 10 06:14:26 2015 +0200

----------------------------------------------------------------------
 ext/karaf/itests/pom.xml                        | 152 +++++++++++++++++++
 .../apache/olingo/osgi/itests/BundlesTest.java  |  56 +++++++
 .../osgi/itests/OlingoOSGiTestSupport.java      | 137 +++++++++++++++++
 .../osgi/itests/server/CarServiceTest.java      | 105 +++++++++++++
 pom.xml                                         |   5 +
 5 files changed, 455 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7ab54a2b/ext/karaf/itests/pom.xml
----------------------------------------------------------------------
diff --git a/ext/karaf/itests/pom.xml b/ext/karaf/itests/pom.xml
new file mode 100644
index 0000000..989a7bd
--- /dev/null
+++ b/ext/karaf/itests/pom.xml
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>odata-karaf-itests</artifactId>
+  <packaging>jar</packaging>
+  <name>${project.artifactId}</name>
+
+  <parent>
+    <groupId>org.apache.olingo</groupId>
+    <artifactId>odata-ext</artifactId>
+    <version>4.0.0-SNAPSHOT</version>
+    <relativePath>../..</relativePath>
+  </parent>
+  <dependencies>
+    <!-- Karaf features -->
+    <dependency>
+      <groupId>org.apache.olingo</groupId>
+      <artifactId>odata-karaf-features</artifactId>
+      <version>${project.version}</version>
+      <type>xml</type>
+      <classifier>features</classifier>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.karaf.features</groupId>
+      <artifactId>org.apache.karaf.features.core</artifactId>
+      <version>${karaf.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.karaf.shell</groupId>
+      <artifactId>org.apache.karaf.shell.console</artifactId>
+      <version>${karaf.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${osgi.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>${osgi.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-atinject_1.0_spec</artifactId>
+      <version>1.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <!-- pax-exam -->
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit4</artifactId>
+      <version>${pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam</artifactId>
+      <version>${pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-container-karaf</artifactId>
+      <version>${pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-link-mvn</artifactId>
+      <version>${pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.karaf</groupId>
+      <artifactId>apache-karaf</artifactId>
+      <version>${karaf.version}</version>
+      <type>tar.gz</type>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.karaf.shell</groupId>
+          <artifactId>org.apache.karaf.shell.dev</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.eclipse</groupId>
+          <artifactId>osgi</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.eclipse</groupId>
+          <artifactId>org.eclipse.osgi</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.karaf</groupId>
+          <artifactId>org.apache.karaf.client</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.apache.felix.framework</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <!-- generate dependencies versions that are needed -->
+      <plugin>
+        <groupId>org.apache.servicemix.tooling</groupId>
+        <artifactId>depends-maven-plugin</artifactId>
+        <version>1.2</version>
+        <executions>
+          <execution>
+            <id>generate-depends-file</id>
+            <goals>
+              <goal>generate-depends-file</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7ab54a2b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/BundlesTest.java
----------------------------------------------------------------------
diff --git a/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/BundlesTest.java
b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/BundlesTest.java
new file mode 100644
index 0000000..4b542a1
--- /dev/null
+++ b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/BundlesTest.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+
+package org.apache.olingo.osgi.itests;
+
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
+
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class BundlesTest extends OlingoOSGiTestSupport {
+    @Test
+    public void test() throws Exception {
+        // check the server-api and server-core
+        assertBundleStarted("org.apache.olingo.odata-server-api");
+        assertBundleStarted("org.apache.olingo.odata-server-core");
+
+        // check the client-api and client-core
+        assertBundleStarted("org.apache.olingo.odata-client-api");
+        assertBundleStarted("org.apache.olingo.odata-client-core");
+    }
+
+    @Configuration
+    public Option[] config() {
+        return new Option[]{
+            olingoBaseConfig(),
+            features(olingoUrl, "olingo-server", "olingo-client"),
+            logLevel(LogLevel.INFO)};
+    }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7ab54a2b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/OlingoOSGiTestSupport.java
----------------------------------------------------------------------
diff --git a/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/OlingoOSGiTestSupport.java
b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/OlingoOSGiTestSupport.java
new file mode 100644
index 0000000..e882736
--- /dev/null
+++ b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/OlingoOSGiTestSupport.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+
+package org.apache.olingo.osgi.itests;
+
+
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.inject.Inject;
+
+import org.apache.karaf.features.FeaturesService;
+import org.junit.Assert;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.ProbeBuilder;
+import org.ops4j.pax.exam.TestProbeBuilder;
+import org.ops4j.pax.exam.options.MavenUrlReference;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.when;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+
+/**
+ * 
+ */
+public class OlingoOSGiTestSupport {
+    private static final String MAVEN_DEPENDENCIES_PROPERTIES = "/META-INF/maven/dependencies.properties";
+
+    @Inject
+    protected BundleContext bundleContext;
+
+    @Inject
+    protected FeaturesService featureService;
+
+    protected ExecutorService executor = Executors.newCachedThreadPool();
+
+    protected MavenUrlReference olingoUrl;
+    protected MavenUrlReference karafUrl;
+
+    /**
+     * @param probe
+     * @return
+     */
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+        probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE, "*,org.apache.felix.service.*;status=provisional");
+        return probe;
+    }
+
+    private static String getKarafVersion() {
+        String karafVersion = getVersionFromPom("org.apache.karaf/apache-karaf/version");
+        if (karafVersion == null) {
+            karafVersion = System.getProperty("karaf.version");
+        }
+        if (karafVersion == null) {
+            // setup the default version of it
+            karafVersion = "3.0.3";
+        }
+        return karafVersion;
+    }
+
+    private static String getVersionFromPom(String key) {
+        try {
+            InputStream ins = OlingoOSGiTestSupport.class.getResourceAsStream(MAVEN_DEPENDENCIES_PROPERTIES);
+            Properties p = new Properties();
+            p.load(ins);
+            return p.getProperty(key);
+        } catch (Exception t) {
+            throw new IllegalStateException(MAVEN_DEPENDENCIES_PROPERTIES + " can not be
found", t);
+        }
+    }    
+    /**
+     * Create an {@link org.ops4j.pax.exam.Option} for using a .
+     * 
+     * @return
+     */
+    protected Option olingoBaseConfig() {
+        karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf").version(getKarafVersion())
+            .type("tar.gz");
+        olingoUrl = maven().groupId("org.apache.olingo").artifactId("odata-karaf-features").versionAsInProject()
+            .type("xml").classifier("features");
+        String localRepo = System.getProperty("localRepository");
+        return composite(karafDistributionConfiguration()
+                             .frameworkUrl(karafUrl)
+                             .karafVersion(getKarafVersion())
+                             .name("Apache Karaf")
+                             .useDeployFolder(false)
+                             .unpackDirectory(new File("target/paxexam/")),
+                         //DO NOT COMMIT WITH THIS LINE ENABLED!!!    
+                         //KarafDistributionOption.keepRuntimeFolder(),                 
       
+                         systemProperty("java.awt.headless").value("true"),
+                         when(localRepo != null)
+                             .useOptions(editConfigurationFilePut("etc/org.ops4j.pax.url.mvn.cfg",
+                                                                  "org.ops4j.pax.url.mvn.localRepository",
+                                                                  localRepo)));
+    }
+
+    protected void assertBundleStarted(String name) {
+        Bundle bundle = findBundleByName(name);
+        Assert.assertNotNull("Bundle " + name + " should be installed", bundle);
+        Assert.assertEquals("Bundle " + name + " should be started", Bundle.ACTIVE, bundle.getState());
+    }
+
+    protected Bundle findBundleByName(String symbolicName) {
+        for (Bundle bundle : bundleContext.getBundles()) {
+            if (bundle.getSymbolicName().equals(symbolicName)) {
+                return bundle;
+            }
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7ab54a2b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/server/CarServiceTest.java
----------------------------------------------------------------------
diff --git a/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/server/CarServiceTest.java
b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/server/CarServiceTest.java
new file mode 100644
index 0000000..d727253
--- /dev/null
+++ b/ext/karaf/itests/src/test/java/org/apache/olingo/osgi/itests/server/CarServiceTest.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.osgi.itests.server;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.olingo.osgi.itests.OlingoOSGiTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
+
+/**
+ *
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class CarServiceTest extends OlingoOSGiTestSupport {
+    private static final String SERVICE_URL = "http://localhost:8181/olingo-cars/cars.svc/";
+
+    @Test
+    public void testServiceStarted() throws Exception {
+        // check if the bundle is started
+        assertBundleStarted("org.apache.olingo.odata-server-osgi-sample");
+        
+        // use the jdk http client to verify the server side
+        verifyContent(getContent(SERVICE_URL));
+        
+        verifyContent(getContent(SERVICE_URL + "$metadata"));
+        
+        verifyContent(getContent(SERVICE_URL + "Cars"));
+        
+        verifyContent(getContent(SERVICE_URL + "Cars(1)"));
+        
+        verifyContent(getContent(SERVICE_URL + "Cars(1)/Price"));
+    }    
+
+    private static void verifyContent(String content) {
+        // this is currently a simple test to check if there is no error
+        Assert.assertNotNull(content);
+        Assert.assertTrue(content.indexOf("error") < 0);
+    }
+
+    private static String getContent(String target) throws Exception {
+        InputStream in = null;
+        try {
+            URL url = new URL(target);
+            URLConnection urlConnection = url.openConnection();
+            urlConnection.setRequestProperty("Accept", "*/*");
+            in = urlConnection.getInputStream();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            byte[] buf = new byte[4096];
+            int n = 0;
+            while ((n = in.read(buf, 0, buf.length)) != -1) {
+                baos.write(buf, 0, n);
+            }
+            return new String(baos.toByteArray(), "utf-8");
+        } finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+        
+    }
+
+    @Configuration
+    public Option[] config() {
+        return new Option[] {
+            olingoBaseConfig(),
+            features(olingoUrl, "olingo-server", "olingo-client"),
+            mavenBundle("org.apache.olingo", "odata-server-osgi-sample", "4.0.0-SNAPSHOT"),
+            logLevel(LogLevel.INFO)
+        };
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7ab54a2b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e4d2b76..1544783 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,6 +97,11 @@
     <tomcat.servlet.port>9080</tomcat.servlet.port>
     <tomcat.version>7.0.55</tomcat.version>
 
+    <!-- for osgi integration testing -->
+    <osgi.version>4.2.0</osgi.version>
+    <karaf.version>3.0.3</karaf.version>
+    <pax.exam.version>4.5.0</pax.exam.version>
+
     <!-- Project build settings -->
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.build.source>1.6</project.build.source>


Mime
View raw message