Repository: camel Updated Branches: refs/heads/master f7f53a477 -> c285fbf88
http://git-wip-us.apache.org/repos/asf/camel/blob/c285fbf8/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2SampleServer.java ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2SampleServer.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2SampleServer.java new file mode 100644 index 0000000..2125be1 --- /dev/null +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2SampleServer.java @@ -0,0 +1,89 @@ +/** + * 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.camel.component.olingo2; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URISyntaxException; + +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.handler.DefaultHandler; +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.webapp.WebAppContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The embedded server for hosting the olingo2 sample service during the tests + */ +public class Olingo2SampleServer { + private static final Logger LOG = LoggerFactory.getLogger(Olingo2SampleServer.class); + + private org.eclipse.jetty.server.Server server; + private int port; + + /** + * + * @param port + * @param resourcePath + */ + public Olingo2SampleServer(int port, String resourcePath) { + this.port = port; + server = new org.eclipse.jetty.server.Server(port); + + WebAppContext webappcontext = new WebAppContext(); + String contextPath = null; + try { + contextPath = Olingo2SampleServer.class.getResource(resourcePath).toURI().getPath(); + } catch (URISyntaxException e) { + LOG.error("Unable to read the resource at {}", resourcePath, e); + } + webappcontext.setContextPath("/"); + + webappcontext.setWar(contextPath); + + HandlerCollection handlers = new HandlerCollection(); + handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()}); + server.setHandler(handlers); + } + + public void start() throws Exception { + server.start(); + LOG.debug("Olingo sample server started at port {}", port); + } + + public void stop() throws Exception { + server.stop(); + } + + public void destroy() { + server.destroy(); + } + + static void generateSampleData(String serviceUrl) throws IOException { + try { + // need to use reflection to avoid a build error even when the sample source is not available + Class<?> clz = Class.forName("org.apache.olingo.sample.annotation.util.AnnotationSampleDataGenerator"); + Method m = clz.getMethod("generateData", String.class); + m.invoke(null, serviceUrl); + } catch (Throwable t) { + LOG.error("Unable to load the required sample class", t); + throw new IOException("unable to load the required sample class"); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c285fbf8/components/camel-olingo2/camel-olingo2-component/src/test/resources/olingo2_ref/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/resources/olingo2_ref/WEB-INF/web.xml b/components/camel-olingo2/camel-olingo2-component/src/test/resources/olingo2_ref/WEB-INF/web.xml new file mode 100644 index 0000000..951f9b8 --- /dev/null +++ b/components/camel-olingo2/camel-olingo2-component/src/test/resources/olingo2_ref/WEB-INF/web.xml @@ -0,0 +1,45 @@ +<?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. + --> +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://java.sun.com/xml/ns/javaee" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" + id="WebApp_ID" version="3.0"> + <display-name>org.apache.olingo.sample.annotation</display-name> + + <servlet> + <servlet-name>CarServiceServlet</servlet-name> + <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class> + <init-param> + <param-name>javax.ws.rs.Application</param-name> + <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value> + </init-param> + <init-param> + <param-name>org.apache.olingo.odata2.service.factory</param-name> + <param-value>org.apache.olingo.sample.annotation.processor.AnnotationSampleServiceFactory</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + + <servlet-mapping> + <servlet-name>CarServiceServlet</servlet-name> + <url-pattern>/MyFormula.svc/*</url-pattern> + </servlet-mapping> + +</web-app> http://git-wip-us.apache.org/repos/asf/camel/blob/c285fbf8/components/camel-olingo2/camel-olingo2-component/src/test/resources/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/resources/test-options.properties b/components/camel-olingo2/camel-olingo2-component/src/test/resources/test-options.properties index 97e37bb..0c4e992 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/resources/test-options.properties +++ b/components/camel-olingo2/camel-olingo2-component/src/test/resources/test-options.properties @@ -15,5 +15,5 @@ # limitations under the License. # # Test values for Olingo configuration properties -serviceUri=http://localhost:8080/MyFormula.svc +#serviceUri=http://localhost:8080/MyFormula.svc contentType=application/json;charset=utf-8 \ No newline at end of file