Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styx tests should pass in windows #101

Merged
merged 10 commits into from
Mar 15, 2018
Prev Previous commit
Next Next commit
DISP-1419: fixing failing tests in Windows. "e2e" tests missing (orig…
…ins file is open so we cannot copy it)
  • Loading branch information
a-dlatorre committed Mar 14, 2018
commit a2bde3329cb86038e13f8b1e0de80c8cc849e122
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2013-2017 Expedia Inc.
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,11 +18,13 @@
import com.hotels.styx.api.Resource;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import static com.google.common.base.Throwables.propagate;
import static java.lang.System.lineSeparator;
import static java.util.stream.Collectors.joining;

Expand All @@ -31,7 +33,11 @@ private Resources() {
}

public static String load(Resource resource) throws IOException {
return fileContents(Paths.get(resource.absolutePath()));
try {
return fileContents(Paths.get(resource.url().toURI()));
}catch (URISyntaxException e){
throw propagate(e);
}
}

private static String fileContents(Path path) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2013-2017 Expedia Inc.
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,14 +19,12 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;

import static com.hotels.styx.StartupConfig.CONFIG_FILE_LOCATION_VAR_NAME;
import static com.hotels.styx.StartupConfig.LOGBACK_CONFIG_LOCATION_VAR_NAME;
import static com.hotels.styx.StartupConfig.STYX_HOME_VAR_NAME;
import static com.hotels.styx.StartupConfig.newStartupConfigBuilder;
import static com.hotels.styx.StartupConfig.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the * import in Styx as we like to only import exactly what we are using.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, that's due to IntelliJ settings. The IDE itself was changing the imports as per the "count to use (static) import with *" If you could do an export of the Settings -> Editor -> Code Style to verify that I don't have any other settings configured that break codestyle's expectations, that would be great.

import static com.hotels.styx.support.ResourcePaths.fixturesHome;
import static java.lang.System.clearProperty;
import static java.lang.System.setProperty;
Expand Down Expand Up @@ -58,21 +56,22 @@ public void readsConfigurationFromDefaultLocation() {
setProperty(STYX_HOME_VAR_NAME, fixturesHome());
StartupConfig config = StartupConfig.load();


assertThat(config.styxHome(), is(Paths.get(fixturesHome())));
}

@Test
public void willLoadLogbackFromDefaultLocationIfNotSpecified() {
public void willLoadLogbackFromDefaultLocationIfNotSpecified() throws URISyntaxException {
String styxHome = fixturesHome();
setProperty(STYX_HOME_VAR_NAME, styxHome);

StartupConfig startupConfig = StartupConfig.load();

assertThat(startupConfig.logConfigLocation().url().getFile(), is(realPathOf("conf/logback.xml").toString()));
assertThat(startupConfig.logConfigLocation().url().toURI(), is(realPathOf("conf/logback.xml").toUri()));
}

@Test
public void shouldLoadLogbackFromClasspath() throws URISyntaxException {
public void shouldLoadLogbackFromClasspath() {
String styxHome = fixturesHome();
setProperty(STYX_HOME_VAR_NAME, styxHome);

Expand All @@ -84,14 +83,14 @@ public void shouldLoadLogbackFromClasspath() throws URISyntaxException {
}

@Test
public void logbackLocationCanBeOverridden() throws URISyntaxException {
public void logbackLocationCanBeOverridden() {
String styxHome = fixturesHome();
setProperty(STYX_HOME_VAR_NAME, styxHome);
setProperty(LOGBACK_CONFIG_LOCATION_VAR_NAME, "/conf/foobar.xml");

StartupConfig startupConfig = StartupConfig.load();

assertThat(startupConfig.logConfigLocation().toString(), is("/conf/foobar.xml"));
assertThat(startupConfig.logConfigLocation().path(), is(new File("/conf/foobar.xml").getPath()));
}

@Test
Expand All @@ -101,15 +100,15 @@ public void yamlConfigFileUsesSuppliedValue() {

StartupConfig config = StartupConfig.load();

assertThat(config.configFileLocation().path(), is("conf/foobar.yml"));
assertThat(config.configFileLocation().path(), is("conf/foobar.yml".replace("/", File.separator)));
}

@Test
public void usesDefaultConfigurationFile() {
setProperty(STYX_HOME_VAR_NAME, fixturesHome());

StartupConfig config = StartupConfig.load();
Path fullPath = Paths.get(Resources.getResource(".").getFile(), "conf/default.yml");
Path fullPath = new File(Resources.getResource(".").getFile(), "conf/default.yml").toPath();

assertThat(config.configFileLocation().path(), is(fullPath.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2013-2017 Expedia Inc.
* Copyright (C) 2013-2018 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,15 +18,14 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hotels.styx.api.Clock;
import com.hotels.styx.api.HttpRequest;
import com.hotels.styx.server.HttpInterceptorContext;
import org.testng.annotations.Test;

import java.time.Duration;
import java.util.Optional;
import java.util.function.Supplier;

import static com.hotels.styx.support.api.HttpMessageBodies.bodyAsString;
import static com.hotels.styx.api.HttpRequest.Builder.get;
import static com.hotels.styx.support.api.HttpMessageBodies.bodyAsString;
import static java.lang.System.currentTimeMillis;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -90,9 +89,9 @@ public void prettyPrintsOutputWhenPrettyIsSetToTrue() throws Exception {
Supplier<Convertible> supplier = sequentialSupplier(new Convertible("foo", 456));
JsonHandler<Convertible> handler = new JsonHandler<>(supplier, Optional.empty());

assertThat(responseFor(handler, request), is("{\n" +
" \"string\" : \"foo\",\n" +
" \"integer\" : 456\n" +
assertThat(responseFor(handler, request), is("{" + System.lineSeparator() +
" \"string\" : \"foo\"," + System.lineSeparator() +
" \"integer\" : 456" + System.lineSeparator() +
"}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static com.hotels.styx.api.messages.HttpResponseStatus.OK;
import static com.hotels.styx.support.ResourcePaths.fixturesHome;
import static com.hotels.styx.support.api.BlockingObservables.waitForResponse;
import static com.hotels.styx.support.matchers.RegExMatcher.matchesRegex;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand All @@ -42,7 +43,7 @@ public void showsErrorMessageInContentIfLogConfigFileDoesNotExist() {
FullHttpResponse response = waitForResponse(handler.handle(get("/").build()));

assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("Could not load resource='/foo/bar'"));
assertThat(response.bodyAs(UTF_8), matchesRegex("Could not load resource=.*foo[\\\\/]bar'"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ public void prettyPrintsOriginsSnapshot() throws Exception {
eventBus.post(new OriginsSnapshot(APP_ID, pool(emptySet()), pool(emptySet()), pool(disabledOrigins)));

FullHttpResponse response = waitForResponse(handler.handle(get("/?pretty=1").build()));
assertThat(response.bodyAs(UTF_8), matchesRegex("\\{\n" +
" \"" + APP_ID + "\" : \\{\n" +
" \"appId\" : \"" + APP_ID + "\",\n" +
" \"activeOrigins\" : \\[ ],\n" +
" \"inactiveOrigins\" : \\[ ],\n" +
" \"disabledOrigins\" : \\[ \\{\n" +
" \"id\" : \"origin.\",\n" +
" \"host\" : \"localhost:....\"\n" +
" }, \\{\n" +
" \"id\" : \"origin.\",\n" +
" \"host\" : \"localhost:....\"\n" +
" } ]\n" +
" }\n" +
assertThat(response.bodyAs(UTF_8), matchesRegex("\\{\\R" +
" \"" + APP_ID + "\" : \\{\\R" +
" \"appId\" : \"" + APP_ID + "\",\\R" +
" \"activeOrigins\" : \\[ ],\\R" +
" \"inactiveOrigins\" : \\[ ],\\R" +
" \"disabledOrigins\" : \\[ \\{\\R" +
" \"id\" : \"origin.\",\\R" +
" \"host\" : \"localhost:....\"\\R" +
" }, \\{\\R" +
" \"id\" : \"origin.\",\\R" +
" \"host\" : \"localhost:....\"\\R" +
" } ]\\R" +
" }\\R" +
"}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
import java.util.List;

import static com.hotels.styx.api.HttpRequest.Builder.put;
import static com.hotels.styx.api.messages.HttpResponseStatus.BAD_REQUEST;
import static com.hotels.styx.api.messages.HttpResponseStatus.NOT_FOUND;
import static com.hotels.styx.api.messages.HttpResponseStatus.OK;
import static com.hotels.styx.api.messages.HttpResponseStatus.*;
import static com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin;
import static com.hotels.styx.support.api.BlockingObservables.waitForResponse;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -61,7 +59,7 @@ public void enablesDisabledPlugin() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'off' changed to 'enabled'\",\"plugin\":{\"name\":\"off\",\"state\":\"enabled\"}}\n"));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'off' changed to 'enabled'\",\"plugin\":{\"name\":\"off\",\"state\":\"enabled\"}}"+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(true));
}
Expand All @@ -73,7 +71,7 @@ public void disablesEnabledPlugin() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'on' changed to 'disabled'\",\"plugin\":{\"name\":\"on\",\"state\":\"disabled\"}}\n"));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'on' changed to 'disabled'\",\"plugin\":{\"name\":\"on\",\"state\":\"disabled\"}}"+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(false));
assertThat(initiallyDisabled.enabled(), is(false));
}
Expand All @@ -85,7 +83,7 @@ public void notifiesWhenPluginAlreadyDisabled() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'off' was already 'disabled'\",\"plugin\":{\"name\":\"off\",\"state\":\"disabled\"}}\n"));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'off' was already 'disabled'\",\"plugin\":{\"name\":\"off\",\"state\":\"disabled\"}}"+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
Expand All @@ -97,7 +95,7 @@ public void notifiesWhenPluginAlreadyEnabled() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'on' was already 'enabled'\",\"plugin\":{\"name\":\"on\",\"state\":\"enabled\"}}\n"));
assertThat(response.bodyAs(UTF_8), is("{\"message\":\"State of 'on' was already 'enabled'\",\"plugin\":{\"name\":\"on\",\"state\":\"enabled\"}}"+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
Expand All @@ -109,7 +107,7 @@ public void saysBadRequestWhenUrlIsInvalid() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(BAD_REQUEST));
assertThat(response.bodyAs(UTF_8), is("Invalid URL\n"));
assertThat(response.bodyAs(UTF_8), is("Invalid URL"+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
Expand All @@ -121,7 +119,7 @@ public void saysBadRequestWhenNoStateSpecified() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(BAD_REQUEST));
assertThat(response.bodyAs(UTF_8), is("No such state: only 'true' and 'false' are valid.\n"));
assertThat(response.bodyAs(UTF_8), is("No such state: only 'true' and 'false' are valid."+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
Expand All @@ -133,7 +131,7 @@ public void saysBadRequestWhenPluginDoesNotExist() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(NOT_FOUND));
assertThat(response.bodyAs(UTF_8), is("No such plugin\n"));
assertThat(response.bodyAs(UTF_8), is("No such plugin"+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
Expand All @@ -145,7 +143,7 @@ public void saysBadRequestWhenValueIsInvalid() {
FullHttpResponse response = waitForResponse(handler.handle(request));

assertThat(response.status(), is(BAD_REQUEST));
assertThat(response.bodyAs(UTF_8), is("No such state: only 'true' and 'false' are valid.\n"));
assertThat(response.bodyAs(UTF_8), is("No such state: only 'true' and 'false' are valid."+System.lineSeparator()));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.hotels.styx.api.HttpRequest.Builder.get;
import static com.hotels.styx.api.messages.HttpResponseStatus.OK;
import static com.hotels.styx.support.api.BlockingObservables.waitForResponse;
import static com.hotels.styx.support.matchers.RegExMatcher.matchesRegex;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand All @@ -41,10 +42,10 @@ public void outputsExpectedData(){
FullHttpResponse response = waitForResponse(handler.handle(get("/").build()));

assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("<html><body>" +
"Styx Home='/foo'" +
"<br />Config File Location='/bar/configure-me.yml'" +
"<br />Log Config Location='/baz/logback-conf.xml'" +
assertThat(response.bodyAs(UTF_8), matchesRegex("<html><body>" +
"Styx Home='[/\\\\]foo'" +
"<br />Config File Location='.*[/\\\\]bar[/\\\\]configure-me.yml'" +
"<br />Log Config Location='.*[/\\\\]baz[/\\\\]logback-conf.xml'" +
"</body></html>"));
}
}
Loading