Repository: tomee Updated Branches: refs/heads/master 14b290dac -> c3a65be8d
adding a http test for openejb-client - best value is manual run to ensure caching works but it requires too much JVM internals to stay portable and CI friendly Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c3a65be8 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c3a65be8 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c3a65be8 Branch: refs/heads/master Commit: c3a65be8d02505ac1f1918106bb310a5e6ef99c5 Parents: 14b290d Author: Romain Manni-Bucau <[email protected]> Authored: Thu Aug 6 03:20:34 2015 -0700 Committer: Romain Manni-Bucau <[email protected]> Committed: Thu Aug 6 03:20:34 2015 -0700 ---------------------------------------------------------------------- .../openejb/client/HttpConnectionTest.java | 91 ++++++++++++++++++++ 1 file changed, 91 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/c3a65be8/server/openejb-client/src/test/java/org/apache/openejb/client/HttpConnectionTest.java ---------------------------------------------------------------------- diff --git a/server/openejb-client/src/test/java/org/apache/openejb/client/HttpConnectionTest.java b/server/openejb-client/src/test/java/org/apache/openejb/client/HttpConnectionTest.java new file mode 100644 index 0000000..a3287a4 --- /dev/null +++ b/server/openejb-client/src/test/java/org/apache/openejb/client/HttpConnectionTest.java @@ -0,0 +1,91 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.openejb.client; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.URI; +import java.net.URISyntaxException; + +public class HttpConnectionTest { + private HttpServer server; + + @Before + public void init() throws Exception { + server = HttpServer.create(new InetSocketAddress(0), 5); + server.createContext("/e", new HttpHandler() { + @Override + public void handle(final HttpExchange exchange) throws IOException { + exchange.getResponseHeaders().set("Content-Type", "text/plain"); + exchange.sendResponseHeaders(200, 0); + + final OutputStream responseBody = exchange.getResponseBody(); + responseBody.write("secure page".getBytes()); + responseBody.close(); + } + }); + server.start(); + } + + @After + public void close() { + server.stop(0); + } + + @Test + public void http() throws URISyntaxException, IOException { + final HttpConnectionFactory factory = new HttpConnectionFactory(); + final String url = "http://localhost:" + server.getAddress().getPort() + "/e"; + for (int i = 0; i < 3; i++) { + final Connection connection = factory.getConnection(new URI(url)); + + BufferedReader br = null; + final StringBuilder sb = new StringBuilder(); + String line; + try { + br = new BufferedReader(new InputStreamReader(connection.getInputStream())); + while ((line = br.readLine()) != null) { + sb.append(line); + } + } catch (final IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + connection.close(); + } + + Assert.assertTrue("should contain", sb.toString().contains("secure")); + } + } +}
