Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Make test resource loading Eclipse compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
szab100 committed May 3, 2017
1 parent 65ea377 commit 488b105
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
21 changes: 0 additions & 21 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,27 +485,6 @@
dir="${basedir}" maxmemory="512m">
<sysproperty key="net.sourceforge.cobertura.datafile"
file="${build-instrument.dir}/cobertura.ser"/>
<!-- test-keys.jks created with:
keytool -genkeypair -alias adaptor -keystore test/test-keys.jks
-keyalg RSA -validity 1000000 -storepass changeit -dname
"CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown,
C=Unknown" -keypass changeit
-->
<sysproperty key="javax.net.ssl.keyStore"
file="${test.dir}/test-keys.jks"/>
<sysproperty key="javax.net.ssl.keyStoreType" value="jks"/>
<sysproperty key="javax.net.ssl.keyStorePassword" value="changeit"/>
<!-- test-cacerts.jks created with:
keytool -exportcert -alias adaptor -keystore test/test-keys.jks -rfc
-file tmp.crt -storepass changeit
keytool -importcert -keystore test/test-cacerts.jks -file tmp.crt
-storepass changeit -noprompt -alias adaptor
rm tmp.crt
-->
<sysproperty key="javax.net.ssl.trustStore"
file="${test.dir}/test-cacerts.jks"/>
<sysproperty key="javax.net.ssl.trustStoreType" value="jks"/>
<sysproperty key="javax.net.ssl.trustStorePassword" value="changeit"/>
<classpath refid="adaptorlib.run.classpath"/>
<classpath refid="examples.run.classpath"/>
<classpath refid="cobertura.classpath"/>
Expand Down
1 change: 1 addition & 0 deletions test/com/google/enterprise/adaptor/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public void testBasicListen() throws Exception {

@Test
public void testBasicHttpsListen() throws Exception {
TestHelper.initSSLKeystores();
config.setValue("server.secure", "true");
app.start();
assertTrue(adaptor.inited);
Expand Down
6 changes: 4 additions & 2 deletions test/com/google/enterprise/adaptor/DashboardHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URL;

/**
* Tests for {@link DashboardHandler}.
Expand All @@ -33,9 +34,10 @@ public class DashboardHandlerTest {

/** Returns entire static test file's contents. */
private static byte[] readLocal(String basename) throws IOException {
String dirname = "test/com/google/enterprise/adaptor/resources/";
String dirname = "/com/google/enterprise/adaptor/resources/";
String filename = dirname + basename;
RandomAccessFile f = new RandomAccessFile(filename, "r");
URL fileUrl = DashboardHandlerTest.class.getResource(filename);
RandomAccessFile f = new RandomAccessFile(fileUrl.getPath(), "r");
byte b[] = new byte[(int) f.length()];
f.readFully(b);
f.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.rules.ExpectedException;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -52,8 +53,8 @@ public class GsaCommunicationHandlerTest {
* -validity 7300 -dname "CN=Unknown, OU=Unknown, O=Unknown, L=Unknown,
* ST=Unknown, C=Unknown"}.
*/
private static final String KEYSTORE_VALID_FILENAME
= "test/com/google/enterprise/adaptor/GsaCommunicationHandlerTest.valid.jks";
private static final String KEYSTORE_VALID_FILENAME =
"/com/google/enterprise/adaptor/GsaCommunicationHandlerTest.valid.jks";

private Config config;
private GsaCommunicationHandler gsa;
Expand Down Expand Up @@ -394,8 +395,10 @@ public void testCreateAclTransformNoOp() throws Exception {

@Test
public void testKeyStore() throws Exception {
URL fileUrl =
GsaCommunicationHandlerTest.class.getResource(KEYSTORE_VALID_FILENAME);
assertNotNull(GsaCommunicationHandler.getKeyPair("notadaptor",
KEYSTORE_VALID_FILENAME, "JKS", "notchangeit"));
fileUrl.getPath(), "JKS", "notchangeit"));
}

@Test
Expand All @@ -415,8 +418,10 @@ public void testKeyStoreMissing() throws Exception {
@Test
public void testKeyStoreNoAlias() throws Exception {
thrown.expect(RuntimeException.class);
GsaCommunicationHandler.getKeyPair("notherealalias",
KEYSTORE_VALID_FILENAME, "JKS", "notchangeit");
URL url =
GsaCommunicationHandlerTest.class.getResource(KEYSTORE_VALID_FILENAME);
GsaCommunicationHandler.getKeyPair("notherealalias", url.getPath(), "JKS",
"notchangeit");
}

private static class NullAdaptor extends AbstractAdaptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.net.URL;
import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream;

import javax.net.ssl.SSLContext;

/**
Expand All @@ -53,6 +52,7 @@ public class GsaFeedFileSenderTest {

@Before
public void startup() throws IOException {
TestHelper.initSSLKeystores();
server = HttpServer.create(new InetSocketAddress(0), 0);
port = server.getAddress().getPort();
server.start();
Expand Down
8 changes: 5 additions & 3 deletions test/com/google/enterprise/adaptor/JavaExecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
/** Unit tests for {@link JavaExec}. */
public class JavaExecTest {
// Relative to WORKING_DIR
private static final File CHILD_JAR
= new File("../test/com/google/enterprise/adaptor/JavaExecTestChild.jar");
private static final File WORKING_DIR = new File("build/");
private static final File CHILD_JAR = new File(JavaExecTest.class
.getResource("/com/google/enterprise/adaptor/JavaExecTestChild.jar")
.getPath());
private static final File WORKING_DIR =
new File(JavaExecTest.class.getResource("/").getPath());

private PrintStream savedStdout;
private ByteArrayOutputStream stdoutBytes = new ByteArrayOutputStream();
Expand Down
Binary file modified test/com/google/enterprise/adaptor/JavaExecTestChild.jar
Binary file not shown.
21 changes: 21 additions & 0 deletions test/com/google/enterprise/adaptor/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,25 @@ public static byte[] getDocContent(Adaptor adaptor, DocId docId)
}
return baos.toByteArray();
}

public static void initSSLKeystores() {
/*
* test-keys.jks created with: keytool -genkeypair -alias adaptor -keystore
* test/test-keys.jks -keyalg RSA -validity 1000000 -storepass changeit
* -dname "CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown,
* C=Unknown" -keypass changeit"
*/
System.setProperty("javax.net.ssl.keyStore",
TestHelper.class.getResource("/test-keys.jks").getPath());
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
/*
* test-cacerts.jks created with: keytool -exportcert -alias adaptor
* -keystore test/test-keys.jks -rfc -file tmp.crt -storepass changeit
* keytool -importcert -keystore test/test-cacerts.jks -file tmp.crt
* -storepass changeit -noprompt -alias adaptor rm tmp.crt
*/
System.setProperty("javax.net.ssl.trustStore",
TestHelper.class.getResource("/test-cacerts.jks").getPath());
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
}
}

0 comments on commit 488b105

Please sign in to comment.