Added checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-05 10:38:16 +01:00
parent cc9ad3a56c
commit b1546c59ca
357 changed files with 8332 additions and 6406 deletions

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample;
import java.io.IOException;
@@ -22,28 +38,33 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* Test for gh-975.
* org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
* 'vaultEnvironmentRepositoryFactory' defined in
* org.springframework.cloud.config.server.config.CompositeRepositoryConfiguration: Unsatisfied dependency
* No qualifying bean of type 'javax.servlet.http.HttpServletRequest' available:
* Test for gh-975. org.springframework.beans.factory.UnsatisfiedDependencyException:
* Error creating bean with name 'vaultEnvironmentRepositoryFactory' defined in
* org.springframework.cloud.config.server.config.CompositeRepositoryConfiguration:
* Unsatisfied dependency No qualifying bean of type
* 'javax.servlet.http.HttpServletRequest' available.
*
* @author Spencer Gibb
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the config
// server on the classpath we need to set it explicitly
properties = { "spring.cloud.config.enabled:true", "",
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" }, webEnvironment = RANDOM_PORT)
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config
// server on the classpath we need to set it explicitly
properties = { "spring.cloud.config.enabled:true", "",
"management.security.enabled=false",
"management.endpoints.web.exposure.include=*" }, webEnvironment = RANDOM_PORT)
public class ApplicationBootstrapTests {
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
private static int configPort = SocketUtils.findAvailableTcpPort();
private static ConfigurableApplicationContext server;
@LocalServerPort
private int port;
private static ConfigurableApplicationContext server;
@BeforeClass
public static void startConfigServer() throws IOException {
System.setProperty("spring.cloud.bootstrap.name", "bootstrapservercomposite");
@@ -69,20 +90,20 @@ public class ApplicationBootstrapTests {
}
}
@Test
@SuppressWarnings("unchecked")
public void contextLoads() {
Map res = new TestRestTemplate()
.getForObject("http://localhost:" + port + BASE_PATH + "/env/info.foo", Map.class);
assertThat(res).containsKey("propertySources");
Map<String, Object> property = (Map<String,Object>) res.get("property");
assertThat(property).containsEntry("value", "bar");
}
public static void main(String[] args) throws IOException {
configPort = 8888;
startConfigServer();
SpringApplication.run(Application.class, args);
}
@Test
@SuppressWarnings("unchecked")
public void contextLoads() {
Map res = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + BASE_PATH + "/env/info.foo", Map.class);
assertThat(res).containsKey("propertySources");
Map<String, Object> property = (Map<String, Object>) res.get("property");
assertThat(property).containsEntry("value", "bar");
}
}

View File

@@ -1,25 +1,43 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample;
import org.junit.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
public class ApplicationFailFastTests {
@Test
public void contextFails() {
try {
new SpringApplicationBuilder()
.sources(Application.class)
.run("--server.port=0", "--spring.cloud.config.enabled=true",
"--spring.cloud.config.fail-fast=true",
"--spring.cloud.config.uri=http://server-host-doesnt-exist:1234");
fail("failFast option did not produce an exception");
} catch (Exception e) {
assertTrue("Exception not caused by fail fast", e.getMessage().contains("fail fast"));
}
}
try {
new SpringApplicationBuilder().sources(Application.class).run(
"--server.port=0", "--spring.cloud.config.enabled=true",
"--spring.cloud.config.fail-fast=true",
"--spring.cloud.config.uri=http://server-host-doesnt-exist:1234");
fail("failFast option did not produce an exception");
}
catch (Exception e) {
assertThat(e.getMessage().contains("fail fast"))
.as("Exception not caused by fail fast").isTrue();
}
}
}

View File

@@ -1,9 +1,29 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample;
import java.io.IOException;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.test.context.SpringBootTest;
@@ -14,28 +34,28 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.SocketUtils;
import java.io.IOException;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the config
// server on the classpath we need to set it explicitly
properties = { "spring.cloud.config.enabled:true",
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" }, webEnvironment = RANDOM_PORT)
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config
// server on the classpath we need to set it explicitly
properties = { "spring.cloud.config.enabled:true",
"management.security.enabled=false",
"management.endpoints.web.exposure.include=*" }, webEnvironment = RANDOM_PORT)
public class ApplicationTests {
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
private static int configPort = SocketUtils.findAvailableTcpPort();
private static ConfigurableApplicationContext server;
@LocalServerPort
private int port;
private static ConfigurableApplicationContext server;
@BeforeClass
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils
@@ -46,8 +66,10 @@ public class ApplicationTests {
org.springframework.cloud.config.server.ConfigServerApplication.class,
"--server.port=" + configPort, "--spring.config.name=server",
"--spring.cloud.config.server.git.uri=" + repo);
/*FIXME configPort = ((EmbeddedWebApplicationContext) server)
.getEmbeddedServletContainer().getPort();*/
/*
* FIXME configPort = ((EmbeddedWebApplicationContext) server)
* .getEmbeddedServletContainer().getPort();
*/
System.setProperty("config.port", "" + configPort);
}
@@ -59,20 +81,20 @@ public class ApplicationTests {
}
}
@Test
@SuppressWarnings("unchecked")
public void contextLoads() {
Map res = new TestRestTemplate()
.getForObject("http://localhost:" + port + BASE_PATH + "/env/info.foo", Map.class);
assertThat(res).containsKey("propertySources");
Map<String, Object> property = (Map<String,Object>) res.get("property");
assertThat(property).containsEntry("value", "bar");
}
public static void main(String[] args) throws IOException {
configPort = 8888;
startConfigServer();
SpringApplication.run(Application.class, args);
}
@Test
@SuppressWarnings("unchecked")
public void contextLoads() {
Map res = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + BASE_PATH + "/env/info.foo", Map.class);
assertThat(res).containsKey("propertySources");
Map<String, Object> property = (Map<String, Object>) res.get("property");
assertThat(property).containsEntry("value", "bar");
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample;
import java.io.IOException;
@@ -6,6 +22,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.SpringBootTest;
@@ -15,54 +32,56 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertFalse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
properties = "spring.application.name:bad", webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = Application.class, properties = "spring.application.name:bad", webEnvironment = RANDOM_PORT)
public class ServerNativeApplicationTests {
private static int configPort = 0;
private static ConfigurableApplicationContext server;
@Autowired
private ConfigurableEnvironment environment;
@LocalServerPort
private int port;
private static ConfigurableApplicationContext server;
@BeforeClass
public static void startConfigServer() throws IOException {
String repo = ConfigServerTestUtils.prepareLocalRepo();
server = SpringApplication.run(
org.springframework.cloud.config.server.ConfigServerApplication.class,
"--server.port=" + configPort, "--spring.config.name=server",
"--spring.cloud.config.server.git.uri=" + repo, "--spring.profiles.active=native");
/*FIXME configPort = ((EmbeddedWebApplicationContext) server)
.getEmbeddedServletContainer().getPort();*/
"--spring.cloud.config.server.git.uri=" + repo,
"--spring.profiles.active=native");
/*
* FIXME configPort = ((EmbeddedWebApplicationContext) server)
* .getEmbeddedServletContainer().getPort();
*/
System.setProperty("config.port", "" + configPort);
}
@AfterClass
public static void close() {
System.clearProperty("config.port");
if (server!=null) {
if (server != null) {
server.close();
}
}
@Test
public void contextLoads() {
// The remote config was bad so there is no bootstrap
assertFalse(this.environment.getPropertySources().contains("bootstrap"));
}
public static void main(String[] args) throws IOException {
configPort = 8888;
startConfigServer();
SpringApplication.run(Application.class, args);
}
@Test
public void contextLoads() {
// The remote config was bad so there is no bootstrap
assertThat(this.environment.getPropertySources().contains("bootstrap")).isFalse();
}
}