-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #8 - alternate /tests/ setup for 100% maven
+ Deploys jetty9:testing (tagged) image in /jetty9/ module during integration-test phase + Adds /tests/ + Adds /tests/webapps/ + Adds /tests/gcloud-testing-core/ for common testing lib
- Loading branch information
Showing
16 changed files
with
812 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.google.cloud.runtimes.jetty.tests</groupId> | ||
<artifactId>tests-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>gcloud-testing-core</artifactId> | ||
<name>Jetty-Runtime :: Testing Core Lib</name> | ||
<packaging>jar</packaging> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<version>1.17</version> | ||
</dependency> | ||
<!-- | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-logging</artifactId> | ||
<version>0.3.0</version> | ||
</dependency> | ||
--> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.toolchain</groupId> | ||
<artifactId>jetty-test-helper</artifactId> | ||
<version>4.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
57 changes: 57 additions & 0 deletions
57
...loud-testing-core/src/main/java/com/google/cloud/runtime/jetty/testing/AppDeployment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.google.cloud.runtime.jetty.testing; | ||
|
||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public final class AppDeployment { | ||
public static final String PROJECT_ID; | ||
public static final String VERSION_ID; | ||
public static final String MODULE_ID; | ||
public static final URI SERVER_URI; | ||
|
||
static { | ||
String projectId = System.getProperty("app.deploy.project"); | ||
String version = System.getProperty("app.deploy.version"); | ||
|
||
Objects.requireNonNull(projectId, "app.deploy.project"); | ||
Objects.requireNonNull(version, "app.deploy.version"); | ||
|
||
PROJECT_ID = projectId; | ||
VERSION_ID = version; | ||
|
||
String moduleId = null; | ||
|
||
Path appYamlPath = MavenTestingUtils.getProjectFilePath("src/main/appengine/app.yaml"); | ||
if (Files.exists(appYamlPath)) { | ||
try (BufferedReader reader = Files.newBufferedReader(appYamlPath, StandardCharsets.UTF_8)) { | ||
Yaml yaml = new Yaml(); | ||
Map map = (Map) yaml.load(reader); | ||
moduleId = (String) map.get("module"); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Unable to parse app.yaml", e); | ||
} | ||
} | ||
|
||
MODULE_ID = moduleId; | ||
|
||
StringBuilder uri = new StringBuilder(); | ||
uri.append("https://"); | ||
uri.append(version).append("-dot-"); | ||
if (moduleId != null) { | ||
uri.append(moduleId).append("-dot-"); | ||
} | ||
uri.append(projectId); | ||
uri.append(".appspot.com/"); | ||
|
||
SERVER_URI = URI.create(uri.toString()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...gcloud-testing-core/src/main/java/com/google/cloud/runtime/jetty/testing/HttpURLUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.google.cloud.runtime.jetty.testing; | ||
|
||
import org.eclipse.jetty.toolchain.test.IO; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.StringWriter; | ||
import java.net.HttpURLConnection; | ||
import java.net.URI; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public final class HttpURLUtil { | ||
/** | ||
* Open a new {@link HttpURLConnection} to the provided URI. | ||
* | ||
* <p> | ||
* Note: will also set the 'User-Agent' to {@code jetty-runtime/gcloud-testing-core} | ||
* </p> | ||
* | ||
* @param uri the URI to open to | ||
* @return the open HttpURLConnection | ||
* @throws IOException if unable to open the connection | ||
*/ | ||
public static HttpURLConnection openTo(URI uri) throws IOException { | ||
HttpURLConnection http = (HttpURLConnection) uri.toURL().openConnection(); | ||
http.setRequestProperty("User-Agent", "jetty-runtime/gcloud-testing-core"); | ||
return http; | ||
} | ||
|
||
/** | ||
* Obtain the text (non-binary) response body from an {@link HttpURLConnection}, | ||
* using the response provided charset. | ||
* | ||
* <p> | ||
* Note: Normal HttpURLConnection doesn't use the provided charset properly. | ||
* </p> | ||
* | ||
* @param http the {@link HttpURLConnection} to obtain the response body from | ||
* @return the text of the response body | ||
* @throws IOException if unable to get the text of the response body | ||
*/ | ||
public static String getResponseBody(HttpURLConnection http) throws IOException { | ||
Charset responseEncoding = StandardCharsets.UTF_8; | ||
if (http.getContentEncoding() != null) { | ||
responseEncoding = Charset.forName(http.getContentEncoding()); | ||
} | ||
|
||
try (InputStream in = http.getInputStream(); | ||
InputStreamReader reader = new InputStreamReader(in, responseEncoding); | ||
StringWriter writer = new StringWriter()) { | ||
IO.copy(reader, writer); | ||
return writer.toString(); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...gcloud-testing-core/src/main/java/com/google/cloud/runtime/jetty/testing/ProcessUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.google.cloud.runtime.jetty.testing; | ||
|
||
import org.eclipse.jetty.toolchain.test.IO; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Arrays; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
||
/** | ||
* Utilities for executing and collecting output from command line processes. | ||
*/ | ||
public final class ProcessUtil { | ||
private static final ExecutorService executor = Executors.newFixedThreadPool(5); | ||
|
||
/** | ||
* Execute a command line. | ||
* <p> | ||
* Report output from command line to Writer | ||
* </p> | ||
* | ||
* @param output where to put the output from the execution of the command line | ||
* @param args the command line arguments | ||
* @return the exit code from the execution | ||
*/ | ||
public static int exec(OutputStream output, String... args) | ||
throws IOException, InterruptedException, ExecutionException { | ||
System.out.printf("exec(%s)%n", Arrays.toString(args)); | ||
Process process = Runtime.getRuntime().exec(args); | ||
|
||
InputStream in = process.getInputStream(); | ||
|
||
Future<Void> fut = executor.submit(new Callable<Void>() { | ||
@Override | ||
public Void call() throws Exception { | ||
IO.copy(in, output); | ||
return null; | ||
} | ||
}); | ||
|
||
fut.get(); | ||
|
||
return process.waitFor(); | ||
} | ||
} |
Oops, something went wrong.