Merge branch '1.3.x'
This commit is contained in:
commit
ccd19ce2c3
|
|
@ -16,11 +16,16 @@
|
||||||
|
|
||||||
package sample.data.cassandra;
|
package sample.data.cassandra;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.cassandraunit.spring.CassandraDataSet;
|
import org.cassandraunit.spring.CassandraDataSet;
|
||||||
import org.cassandraunit.spring.EmbeddedCassandra;
|
import org.cassandraunit.spring.EmbeddedCassandra;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TestRule;
|
||||||
|
import org.junit.runner.Description;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.rule.OutputCapture;
|
import org.springframework.boot.test.rule.OutputCapture;
|
||||||
|
|
@ -44,10 +49,35 @@ public class SampleCassandraApplicationTests {
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static OutputCapture outputCapture = new OutputCapture();
|
public static OutputCapture outputCapture = new OutputCapture();
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static SkipOnWindows skipOnWindows = new SkipOnWindows();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultSettings() throws Exception {
|
public void testDefaultSettings() throws Exception {
|
||||||
String output = SampleCassandraApplicationTests.outputCapture.toString();
|
String output = SampleCassandraApplicationTests.outputCapture.toString();
|
||||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class SkipOnWindows implements TestRule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Statement apply(final Statement base, Description description) {
|
||||||
|
return new Statement() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void evaluate() throws Throwable {
|
||||||
|
if (!runningOnWindows()) {
|
||||||
|
base.evaluate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean runningOnWindows() {
|
||||||
|
return File.separatorChar == '\\';
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,17 @@
|
||||||
|
|
||||||
package sample.data.elasticsearch;
|
package sample.data.elasticsearch;
|
||||||
|
|
||||||
import java.net.ConnectException;
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.junit.ClassRule;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TestRule;
|
||||||
|
import org.junit.runner.Description;
|
||||||
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.boot.test.rule.OutputCapture;
|
import org.springframework.boot.test.rule.OutputCapture;
|
||||||
import org.springframework.core.NestedCheckedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
|
@ -33,34 +36,40 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
public class SampleElasticsearchApplicationTests {
|
public class SampleElasticsearchApplicationTests {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public OutputCapture outputCapture = new OutputCapture();
|
public OutputCapture outputCapture = new OutputCapture();
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static SkipOnWindows skipOnWindows = new SkipOnWindows();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultSettings() throws Exception {
|
public void testDefaultSettings() throws Exception {
|
||||||
try {
|
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
|
||||||
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
|
|
||||||
}
|
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
if (serverNotRunning(ex)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String output = this.outputCapture.toString();
|
String output = this.outputCapture.toString();
|
||||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean serverNotRunning(IllegalStateException ex) {
|
static class SkipOnWindows implements TestRule {
|
||||||
@SuppressWarnings("serial")
|
|
||||||
NestedCheckedException nested = new NestedCheckedException("failed", ex) {
|
@Override
|
||||||
};
|
public Statement apply(final Statement base, Description description) {
|
||||||
if (nested.contains(ConnectException.class)) {
|
return new Statement() {
|
||||||
Throwable root = nested.getRootCause();
|
|
||||||
if (root.getMessage().contains("Connection refused")) {
|
@Override
|
||||||
return true;
|
public void evaluate() throws Throwable {
|
||||||
}
|
if (!runningOnWindows()) {
|
||||||
|
base.evaluate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean runningOnWindows() {
|
||||||
|
return File.separatorChar == '\\';
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue