This commit is contained in:
Phillip Webb
2014-05-20 13:13:39 +01:00
parent e40acd81e4
commit 8bcda1bcbe
91 changed files with 477 additions and 438 deletions

View File

@@ -22,8 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;

View File

@@ -67,6 +67,7 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/admin/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertTrue("Wrong body: " + entity.getBody(), entity.getBody().contains("\"status\":\"ok\""));
assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains("\"status\":\"ok\""));
}
}

View File

@@ -72,7 +72,8 @@ public class ManagementAddressActuatorApplicationTests {
"http://localhost:" + this.managementPort + "/admin/health",
String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertTrue("Wrong body: " + entity.getBody(), entity.getBody().contains("\"status\":\"ok\""));
assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains("\"status\":\"ok\""));
}
}

View File

@@ -81,7 +81,8 @@ public class ManagementPortSampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertTrue("Wrong body: " + entity.getBody(), entity.getBody().contains("\"status\":\"ok\""));
assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains("\"status\":\"ok\""));
}
@Test

View File

@@ -130,7 +130,8 @@ public class SampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertTrue("Wrong body: " + entity.getBody(), entity.getBody().contains("\"status\":\"ok\""));
assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains("\"status\":\"ok\""));
}
@Test

View File

@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
/**
* Tests for {@link SampleMongoApplication}.
*
*
* @author Dave Syer
*/
public class SampleMongoApplicationTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -39,7 +39,7 @@ public class SampleFlywayApplication implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.err.println(repository.findAll());
System.err.println(this.repository.findAll());
}
public static void main(String[] args) throws Exception {
@@ -61,7 +61,7 @@ class Person {
private String lastName;
public String getFirstName() {
return firstName;
return this.firstName;
}
public void setFirstName(String firstName) {
@@ -69,7 +69,7 @@ class Person {
}
public String getLastName() {
return lastName;
return this.lastName;
}
public void setLastName(String lastname) {
@@ -78,7 +78,7 @@ class Person {
@Override
public String toString() {
return "Person [firstName=" + firstName + ", lastName=" + lastName
return "Person [firstName=" + this.firstName + ", lastName=" + this.lastName
+ "]";
}
}

View File

@@ -16,8 +16,6 @@
package sample.flyway;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,16 +23,19 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleFlywayApplication.class)
@SpringApplicationConfiguration(classes = SampleFlywayApplication.class)
public class SampleFlywayApplicationTests {
@Autowired
private JdbcTemplate template;
@Test
public void testDefaultSettings() throws Exception {
assertEquals(new Integer(1), template.queryForObject("SELECT COUNT(*) from PERSON", Integer.class));
assertEquals(new Integer(1), this.template.queryForObject(
"SELECT COUNT(*) from PERSON", Integer.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -29,4 +29,5 @@ public class SampleLiquibaseApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleLiquibaseApplication.class, args);
}
}

View File

@@ -41,14 +41,20 @@ public class SampleLiquibaseApplicationTests {
}
}
String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output,
output.contains("Successfully acquired change log lock") &&
output.contains("Creating database history table with name: PUBLIC.DATABASECHANGELOG") &&
output.contains("Table person created") &&
output.contains("ChangeSet classpath:/db/changelog/db.changelog-master.yaml::1::marceloverdijk ran successfully") &&
output.contains("New row inserted into person") &&
output.contains("ChangeSet classpath:/db/changelog/db.changelog-master.yaml::2::marceloverdijk ran successfully") &&
output.contains("Successfully released change log lock"));
assertTrue(
"Wrong output: " + output,
output.contains("Successfully acquired change log lock")
&& output.contains("Creating database history "
+ "table with name: PUBLIC.DATABASECHANGELOG")
&& output.contains("Table person created")
&& output.contains("ChangeSet classpath:/db/"
+ "changelog/db.changelog-master.yaml::1::"
+ "marceloverdijk ran successfully")
&& output.contains("New row inserted into person")
&& output.contains("ChangeSet classpath:/db/changelog/"
+ "db.changelog-master.yaml::2::"
+ "marceloverdijk ran successfully")
&& output.contains("Successfully released change log lock"));
}
private boolean serverNotRunning(IllegalStateException ex) {

View File

@@ -39,7 +39,7 @@ import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for FreeMarker application.
*
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
@@ -69,8 +69,8 @@ public class SampleWebFreeMarkerApplicationTests {
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> responseEntity = new TestRestTemplate().exchange(
"http://localhost:" +port+ "/does-not-exist", HttpMethod.GET, requestEntity,
String.class);
"http://localhost:" + port + "/does-not-exist", HttpMethod.GET,
requestEntity, String.class);
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -20,9 +20,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author Dave Syer
*/
public class InMemoryMessageRespository implements MessageRepository {
private static AtomicLong counter = new AtomicLong();

View File

@@ -1,14 +1,17 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2014 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
* 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
* 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.
* 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.ui;
@@ -17,9 +20,6 @@ import java.util.Date;
import org.hibernate.validator.constraints.NotEmpty;
/**
* @author Rob Winch
*/
public class Message {
private Long id;

View File

@@ -1,21 +1,21 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2014 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
* 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
* 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.
* 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.ui;
/**
* @author Rob Winch
*/
public interface MessageRepository {
Iterable<Message> findAll();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@@ -1,16 +1,18 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2014 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
* 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
* 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.
* 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.ui.mvc;
import java.util.HashMap;
@@ -33,9 +35,6 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import sample.ui.Message;
import sample.ui.MessageRepository;
/**
* @author Rob Winch
*/
@Controller
@RequestMapping("/")
public class MessageController {
@@ -81,7 +80,7 @@ public class MessageController {
for (FieldError error : result.getFieldErrors()) {
map.put(error.getField(), error);
}
return map ;
return map;
}
@RequestMapping("foo")

View File

@@ -16,13 +16,6 @@
package sample.ui;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.regex.Pattern;
import org.hamcrest.Description;
@@ -39,6 +32,13 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* A Basic Spring MVC Test for the Sample Controller"
*

View File

@@ -16,10 +16,6 @@
package sample.ui;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.net.URI;
import org.junit.Test;
@@ -36,6 +32,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.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for demo application.
*

View File

@@ -59,8 +59,7 @@ public class SampleMethodSecurityApplication extends WebMvcConfigurerAdapter {
}
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(SampleMethodSecurityApplication.class)
.run(args);
new SpringApplicationBuilder(SampleMethodSecurityApplication.class).run(args);
}
@Override
@@ -83,26 +82,23 @@ public class SampleMethodSecurityApplication extends WebMvcConfigurerAdapter {
public void init(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth.inMemoryAuthentication().withUser("admin").password("admin")
.roles("ADMIN", "USER").and().withUser("user")
.password("user").roles("USER");
.roles("ADMIN", "USER").and().withUser("user").password("user")
.roles("USER");
// @formatter:on
}
}
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class ApplicationSecurity extends
WebSecurityConfigurerAdapter {
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.authorizeRequests().antMatchers("/login").permitAll()
.anyRequest().fullyAuthenticated().and().formLogin()
.loginPage("/login").failureUrl("/login?error").and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.and().exceptionHandling()
.accessDeniedPage("/access?error");
http.authorizeRequests().antMatchers("/login").permitAll().anyRequest()
.fullyAuthenticated().and().formLogin().loginPage("/login")
.failureUrl("/login?error").and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).and()
.exceptionHandling().accessDeniedPage("/access?error");
// @formatter:on
}

View File

@@ -16,9 +16,6 @@
package sample.ui.method;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -41,6 +38,9 @@ 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.assertTrue;
/**
* Basic integration tests for demo application.
*

View File

@@ -52,8 +52,8 @@ public class SampleWebSecureApplication extends WebMvcConfigurerAdapter {
public static void main(String[] args) throws Exception {
// Set user password to "password" for demo purposes only
new SpringApplicationBuilder(SampleWebSecureApplication.class)
.properties("security.user.password=password").run(args);
new SpringApplicationBuilder(SampleWebSecureApplication.class).properties(
"security.user.password=password").run(args);
}
@Override
@@ -67,13 +67,11 @@ public class SampleWebSecureApplication extends WebMvcConfigurerAdapter {
}
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class ApplicationSecurity extends
WebSecurityConfigurerAdapter {
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated().and()
.formLogin().loginPage("/login").failureUrl("/login?error")
.permitAll();
http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin()
.loginPage("/login").failureUrl("/login?error").permitAll();
}
}

View File

@@ -39,7 +39,7 @@ import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for Velocity application.
*
*
* @author Phillip Webb
* @author Andy Wilkinson
*/