Return-Path: X-Original-To: apmail-olingo-commits-archive@minotaur.apache.org Delivered-To: apmail-olingo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CCB3118A52 for ; Wed, 10 Jun 2015 08:55:48 +0000 (UTC) Received: (qmail 23711 invoked by uid 500); 10 Jun 2015 08:55:48 -0000 Delivered-To: apmail-olingo-commits-archive@olingo.apache.org Received: (qmail 23665 invoked by uid 500); 10 Jun 2015 08:55:48 -0000 Mailing-List: contact commits-help@olingo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@olingo.apache.org Delivered-To: mailing list commits@olingo.apache.org Received: (qmail 23648 invoked by uid 99); 10 Jun 2015 08:55:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2015 08:55:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 84F4FE02EE; Wed, 10 Jun 2015 08:55:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mibo@apache.org To: commits@olingo.apache.org Date: Wed, 10 Jun 2015 08:55:49 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] olingo-odata4 git commit: Adding olingo-server side OSGi tests 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 Authored: Tue Jun 9 18:33:36 2015 +0200 Committer: Michael Bolz 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 @@ + + + + 4.0.0 + + odata-karaf-itests + jar + ${project.artifactId} + + + org.apache.olingo + odata-ext + 4.0.0-SNAPSHOT + ../.. + + + + + org.apache.olingo + odata-karaf-features + ${project.version} + xml + features + + + + org.apache.karaf.features + org.apache.karaf.features.core + ${karaf.version} + + + org.apache.karaf.shell + org.apache.karaf.shell.console + ${karaf.version} + + + org.osgi + org.osgi.core + ${osgi.version} + + + org.osgi + org.osgi.compendium + ${osgi.version} + + + org.apache.geronimo.specs + geronimo-atinject_1.0_spec + 1.0 + provided + + + junit + junit + test + + + + + org.ops4j.pax.exam + pax-exam-junit4 + ${pax.exam.version} + test + + + org.ops4j.pax.exam + pax-exam + ${pax.exam.version} + test + + + org.ops4j.pax.exam + pax-exam-container-karaf + ${pax.exam.version} + test + + + org.ops4j.pax.exam + pax-exam-link-mvn + ${pax.exam.version} + test + + + + org.apache.karaf + apache-karaf + ${karaf.version} + tar.gz + test + + + org.apache.karaf.shell + org.apache.karaf.shell.dev + + + org.eclipse + osgi + + + org.eclipse + org.eclipse.osgi + + + org.apache.karaf + org.apache.karaf.client + + + org.apache.felix + org.apache.felix.framework + + + + + + + + + org.apache.servicemix.tooling + depends-maven-plugin + 1.2 + + + generate-depends-file + + generate-depends-file + + + + + + + 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 @@ 9080 7.0.55 + + 4.2.0 + 3.0.3 + 4.5.0 + UTF-8 1.6