Skip to content

Commit

Permalink
Switch to using Path instead of File in InProject.locate
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Oct 7, 2016
1 parent 8309f73 commit d247a6f
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ public static void buildJavascriptLibraries() throws IOException {
log.info("In dev mode. Copying required files in case we're using a WebDriver-backed Selenium");

Path dir =
InProject.locate("java/client/build/production/com/thoughtworks/selenium/webdriven").toPath();
InProject.locate("java/client/build/production/com/thoughtworks/selenium/webdriven");
Files.createDirectories(dir);
for (String target : ATOM_TARGETS) {
Path atom = new BuckBuild().of("//javascript/selenium-atoms:" + target).go();
Files.copy(atom, dir.resolve(atom.getFileName()), REPLACE_EXISTING);
}
Path sizzle = InProject.locate("third_party/js/sizzle/sizzle.js").toPath();
Path sizzle = InProject.locate("third_party/js/sizzle/sizzle.js");
Files.copy(sizzle, dir.resolve("sizzle.js"), REPLACE_EXISTING);

Path seDir = InProject.locate("java/client/test/com/thoughtworks/selenium").toPath();
Path seDir = InProject.locate("java/client/test/com/thoughtworks/selenium");
Path destDir =
InProject.locate("java/client/build/production/com/thoughtworks/selenium").toPath();
InProject.locate("java/client/build/production/com/thoughtworks/selenium");
Files.list(seDir)
.filter(path -> path.getFileName().toString().endsWith(".js"))
.forEach(path -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.openqa.selenium.testing.InProject;
import org.seleniumhq.jetty9.servlet.ServletContextHandler;

import java.io.File;
import java.nio.file.Path;

public class SeleniumAppServer extends JettyAppServer {

Expand All @@ -33,7 +33,7 @@ public SeleniumAppServer() {
addServlet(context, "/cachedContentTest", CachedContentServlet.class);
}

protected File findRootOfRcTestPages() {
protected Path findRootOfRcTestPages() {
return InProject.locate("java/server/test/org/openqa/selenium");
}

Expand Down
4 changes: 2 additions & 2 deletions java/client/test/org/openqa/selenium/BuckBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public BuckBuild of(String target) {
}

public Path go() throws IOException {
Path projectRoot = InProject.locate("Rakefile").toPath().getParent();
Path projectRoot = InProject.locate("Rakefile").getParent();

if (!isInDevMode()) {
// we should only need to do this when we're in dev mode
Expand Down Expand Up @@ -140,7 +140,7 @@ private void findBuck(Path projectRoot, ImmutableList.Builder<String> builder) t

private void downloadBuckPexIfNecessary(ImmutableList.Builder<String> builder)
throws IOException {
Path projectRoot = InProject.locate("Rakefile").getParentFile().toPath();
Path projectRoot = InProject.locate("Rakefile").getParent();
String buckVersion = new String(Files.readAllBytes(projectRoot.resolve(".buckversion"))).trim();

Path pex = projectRoot.resolve("buck-out/crazy-fun/" + buckVersion + "/buck.pex");
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private ProcessBuilder prepareBuild() {
}
command.addAll(targets);
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(InProject.locate("Rakefile").getParentFile());
builder.directory(InProject.locate("Rakefile").getParent().toFile());
builder.redirectErrorStream(true);
return builder;
}
Expand Down
46 changes: 23 additions & 23 deletions java/client/test/org/openqa/selenium/ExecutingJavascriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,28 @@

package org.openqa.selenium;

import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.PHANTOMJS;
import static org.openqa.selenium.testing.Driver.SAFARI;

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -32,9 +50,9 @@
import org.openqa.selenium.testing.NoDriverAfterTest;
import org.openqa.selenium.testing.NotYetImplemented;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -45,24 +63,6 @@
import java.util.List;
import java.util.Map;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.PHANTOMJS;
import static org.openqa.selenium.testing.Driver.SAFARI;

public class ExecutingJavascriptTest extends JUnit4TestBase {

@Before
Expand Down Expand Up @@ -471,8 +471,8 @@ public void testJavascriptStringHandlingShouldWorkAsExpected() {
public void testShouldBeAbleToExecuteABigChunkOfJavascriptCode() throws IOException {
driver.get(pages.javascriptPage);

File jqueryFile = InProject.locate("common/src/web/jquery-1.3.2.js");
String jquery = Files.toString(jqueryFile, Charset.forName("US-ASCII"));
Path jqueryFile = InProject.locate("common/src/web/jquery-1.3.2.js");
String jquery = new String(Files.readAllBytes(jqueryFile), US_ASCII);
assertTrue("The javascript code should be at least 50 KB.", jquery.length() > 50000);
// This should not throw an exception ...
executeScript(jquery);
Expand Down
9 changes: 5 additions & 4 deletions java/client/test/org/openqa/selenium/ReferrerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openqa.selenium;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.openqa.selenium.remote.CapabilityType.PROXY;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
Expand All @@ -33,7 +34,6 @@
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.common.net.HostAndPort;
import com.google.common.net.HttpHeaders;

Expand All @@ -60,6 +60,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -109,9 +110,9 @@ public class ReferrerTest extends JUnit4TestBase {

@BeforeClass
public static void readPages() throws IOException {
page1 = Files.toString(locate("common/src/web/proxy/page1.html"), Charsets.UTF_8);
page2 = Files.toString(locate("common/src/web/proxy/page2.html"), Charsets.UTF_8);
page3 = Files.toString(locate("common/src/web/proxy/page3.html"), Charsets.UTF_8);
page1 = new String(Files.readAllBytes(locate("common/src/web/proxy/page1.html")), UTF_8);
page2 = new String(Files.readAllBytes(locate("common/src/web/proxy/page2.html")), UTF_8);
page3 = new String(Files.readAllBytes(locate("common/src/web/proxy/page3.html")), UTF_8);
}

/**
Expand Down
15 changes: 8 additions & 7 deletions java/client/test/org/openqa/selenium/atoms/JavaScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

package org.openqa.selenium.atoms;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.io.Resources;

import org.openqa.selenium.Build;
import org.openqa.selenium.testing.InProject;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;

/**
* Utility class for loading JavaScript resources.
Expand All @@ -37,13 +38,13 @@ private JavaScriptLoader() {} // Utility class.
static String loadResource(String resourcePath, String resourceTask) throws IOException {
URL resourceUrl = JavaScriptLoader.class.getResource(resourcePath);
if (resourceUrl != null) {
return Resources.toString(resourceUrl, Charsets.UTF_8);
return Resources.toString(resourceUrl, UTF_8);
}
new Build().of(resourceTask).go();

File topDir = InProject.locate("Rakefile").getParentFile();
File builtFile = new File(topDir, taskToBuildOutput(resourceTask));
return Files.toString(builtFile, Charsets.UTF_8);
Path topDir = InProject.locate("Rakefile").getParent();
Path builtFile = topDir.resolve(taskToBuildOutput(resourceTask));
return new String(Files.readAllBytes(builtFile), UTF_8);
}

static String taskToBuildOutput(String taskName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
import org.seleniumhq.jetty9.util.resource.Resource;
import org.seleniumhq.jetty9.util.ssl.SslContextFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumSet;

import javax.servlet.DispatcherType;
Expand Down Expand Up @@ -186,14 +187,14 @@ public void start() {
http.setPort(port);
http.setIdleTimeout(500000);

File keystore = getKeyStore();
if (!keystore.exists()) {
Path keystore = getKeyStore();
if (!Files.exists(keystore)) {
throw new RuntimeException(
"Cannot find keystore for SSL cert: " + keystore.getAbsolutePath());
"Cannot find keystore for SSL cert: " + keystore.toAbsolutePath());
}

SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystore.getAbsolutePath());
sslContextFactory.setKeyStorePath(keystore.toAbsolutePath().toString());
sslContextFactory.setKeyStorePassword("password");
sslContextFactory.setKeyManagerPassword("password");

Expand All @@ -216,7 +217,7 @@ public void start() {
}
}

protected File getKeyStore() {
protected Path getKeyStore() {
return InProject.locate("java/client/test/org/openqa/selenium/environment/webserver/keystore");
}

Expand Down Expand Up @@ -268,13 +269,13 @@ protected void doDirectory(HttpServletRequest request, HttpServletResponse respo

}

protected ServletContextHandler addResourceHandler(String contextPath, File resourceBase) {
protected ServletContextHandler addResourceHandler(String contextPath, Path resourceBase) {
ServletContextHandler context = new ServletContextHandler();

ResourceHandler staticResource = new ResourceHandler2();
staticResource.setDirectoriesListed(true);
staticResource.setWelcomeFiles(new String[] { "index.html" });
staticResource.setResourceBase(resourceBase.getAbsolutePath());
staticResource.setResourceBase(resourceBase.toAbsolutePath().toString());
MimeTypes mimeTypes = new MimeTypes();
mimeTypes.addMimeMapping("appcache", "text/cache-manifest");
staticResource.setMimeTypes(mimeTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void shouldNotResetFrozenPreferences() throws Exception {
@Test
public void shouldInstallExtensionFromZip() throws IOException {
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(InProject.locate(FIREBUG_PATH));
profile.addExtension(InProject.locate(FIREBUG_PATH).toFile());
File profileDir = profile.layoutOnDisk();
File extensionDir = new File(profileDir, "extensions/firebug@software.joehewitt.com");
assertTrue(extensionDir.exists());
Expand All @@ -159,7 +159,7 @@ public void shouldInstallExtensionFromZip() throws IOException {
@Test
public void shouldInstallExtensionFromDirectory() throws IOException {
FirefoxProfile profile = new FirefoxProfile();
File extension = InProject.locate(FIREBUG_PATH);
File extension = InProject.locate(FIREBUG_PATH).toFile();
File unzippedExtension = FileHandler.unzip(new FileInputStream(extension));
profile.addExtension(unzippedExtension);
File profileDir = profile.layoutOnDisk();
Expand Down
9 changes: 5 additions & 4 deletions java/client/test/org/openqa/selenium/io/ZipTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

Expand Down Expand Up @@ -97,20 +98,20 @@ public void testShouldZipMultipleDirectories() throws IOException {

@Test
public void testCanUnzipASingleEntry() throws IOException {
File source = InProject.locate(
Path source = InProject.locate(
"java/client/test/org/openqa/selenium/internal/single-file.zip");

zip.unzip(source, outputDir);
zip.unzip(source.toFile(), outputDir);

assertTrue(new File(outputDir, "example.txt").exists());
}

@Test
public void testCanUnzipAComplexZip() throws IOException {
File source = InProject.locate(
Path source = InProject.locate(
"java/client/test/org/openqa/selenium/internal/subfolders.zip");

zip.unzip(source, outputDir);
zip.unzip(source.toFile(), outputDir);

assertTrue(new File(outputDir, "example.txt").exists());
assertTrue(new File(outputDir, "subdir/foodyfun.txt").exists());
Expand Down
Loading

0 comments on commit d247a6f

Please sign in to comment.