Formatting and cleanup
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package sample.actuator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -34,6 +30,10 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Integration tests for endpoints configuration.
|
||||
*
|
||||
@@ -42,7 +42,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest({"server.port=0", "management.context_path=/admin"})
|
||||
@IntegrationTest({ "server.port=0", "management.context_path=/admin" })
|
||||
@DirtiesContext
|
||||
public class ManagementPathSampleActuatorApplicationTests {
|
||||
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package sample.actuator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -34,6 +30,10 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Integration tests for endpoints configuration.
|
||||
*
|
||||
@@ -42,7 +42,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest({"server.port=0", "server.servletPath=/spring"})
|
||||
@IntegrationTest({ "server.port=0", "server.servletPath=/spring" })
|
||||
@DirtiesContext
|
||||
public class ServletPathSampleActuatorApplicationTests {
|
||||
|
||||
@@ -53,7 +53,8 @@ public class ServletPathSampleActuatorApplicationTests {
|
||||
public void testErrorPath() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", "password")
|
||||
.getForEntity("http://localhost:" + this.port + "/spring/error", Map.class);
|
||||
.getForEntity("http://localhost:" + this.port + "/spring/error",
|
||||
Map.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package sample.actuator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -33,6 +30,9 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* Integration tests for unsecured service endpoints (even with Spring Security on
|
||||
* classpath).
|
||||
@@ -42,7 +42,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest({ "server.port:0", "security.basic.enabled:false", "server.servletPath:/spring" })
|
||||
@IntegrationTest({ "server.port:0", "security.basic.enabled:false",
|
||||
"server.servletPath:/spring" })
|
||||
@DirtiesContext
|
||||
public class ServletPathUnsecureSampleActuatorApplicationTests {
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package sample.data.elasticsearch;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.ConnectException;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -25,9 +23,11 @@ import org.junit.Test;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.core.NestedCheckedException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleElasticsearchApplication}.
|
||||
*
|
||||
*
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
public class SampleElasticsearchApplicationTests {
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package sample.ui.secure;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -42,6 +38,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
*
|
||||
@@ -65,8 +65,8 @@ public class SampleSecureApplicationTests {
|
||||
"http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(
|
||||
headers), String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/login"));
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(), entity.getHeaders()
|
||||
.getLocation().toString().endsWith(port + "/login"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,8 +74,8 @@ public class SampleSecureApplicationTests {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.GET, new HttpEntity<Void>(
|
||||
headers), String.class);
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong content:\n" + entity.getBody(),
|
||||
entity.getBody().contains("_csrf"));
|
||||
@@ -94,8 +94,8 @@ public class SampleSecureApplicationTests {
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/"));
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(), entity.getHeaders()
|
||||
.getLocation().toString().endsWith(port + "/"));
|
||||
assertNotNull("Missing cookie:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().get("Set-Cookie"));
|
||||
}
|
||||
@@ -107,8 +107,8 @@ public class SampleSecureApplicationTests {
|
||||
assertEquals(HttpStatus.OK, page.getStatusCode());
|
||||
String cookie = page.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*").matcher(
|
||||
page.getBody());
|
||||
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*")
|
||||
.matcher(page.getBody());
|
||||
assertTrue("No csrf token: " + page.getBody(), matcher.matches());
|
||||
headers.set("X-CSRF-TOKEN", matcher.group(1));
|
||||
return headers;
|
||||
|
||||
Reference in New Issue
Block a user