pull/12202/head
Phillip Webb 7 years ago
parent 80ac4f85c9
commit cd5266ac03

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

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

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

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

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

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

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

@ -40,34 +40,31 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class ReactiveWebServerFactoryAutoConfigurationTests {
private ReactiveWebApplicationContextRunner contextRunner =
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new)
.withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class));
private ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner(
AnnotationConfigReactiveWebServerApplicationContext::new)
.withConfiguration(AutoConfigurations
.of(ReactiveWebServerFactoryAutoConfiguration.class));
@Test
public void createFromConfigClass() {
this.contextRunner
.withUserConfiguration(MockWebServerAutoConfiguration.class,
HttpHandlerConfiguration.class)
.run(context -> {
this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class,
HttpHandlerConfiguration.class).run((context) -> {
assertThat(context.getBeansOfType(ReactiveWebServerFactory.class))
.hasSize(1);
assertThat(context.getBeansOfType(WebServerFactoryCustomizer.class))
.hasSize(1);
assertThat(context.getBeansOfType(ReactiveWebServerFactoryCustomizer.class))
assertThat(context
.getBeansOfType(ReactiveWebServerFactoryCustomizer.class))
.hasSize(1);
});
}
@Test
public void missingHttpHandler() {
this.contextRunner
.withUserConfiguration(MockWebServerAutoConfiguration.class)
.run(context -> {
assertThat(context.getStartupFailure())
this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class)
.run((context) -> assertThat(context.getStartupFailure())
.isInstanceOf(ApplicationContextException.class)
.hasMessageContaining("missing HttpHandler bean");
});
.hasMessageContaining("missing HttpHandler bean"));
}
@Test
@ -75,34 +72,27 @@ public class ReactiveWebServerFactoryAutoConfigurationTests {
this.contextRunner
.withUserConfiguration(MockWebServerAutoConfiguration.class,
HttpHandlerConfiguration.class, TooManyHttpHandlers.class)
.run(context -> {
assertThat(context.getStartupFailure())
.run((context) -> assertThat(context.getStartupFailure())
.isInstanceOf(ApplicationContextException.class)
.hasMessageContaining("multiple HttpHandler beans : " +
"httpHandler,additionalHttpHandler");
});
.hasMessageContaining("multiple HttpHandler beans : "
+ "httpHandler,additionalHttpHandler"));
}
@Test
public void customizeReactiveWebServer() {
this.contextRunner
.withUserConfiguration(MockWebServerAutoConfiguration.class,
this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class,
HttpHandlerConfiguration.class, ReactiveWebServerCustomization.class)
.run(context -> {
assertThat(context.getBean(MockReactiveWebServerFactory.class).getPort())
.isEqualTo(9000);
});
.run((context) -> assertThat(
context.getBean(MockReactiveWebServerFactory.class).getPort())
.isEqualTo(9000));
}
@Test
public void defaultWebServerIsTomcat() {
// Tomcat should be chosen over Netty if the Tomcat library is present.
this.contextRunner
.withUserConfiguration(HttpHandlerConfiguration.class)
.run(context -> {
assertThat(context.getBean(ReactiveWebServerFactory.class))
.isInstanceOf(TomcatReactiveWebServerFactory.class);
});
this.contextRunner.withUserConfiguration(HttpHandlerConfiguration.class).run(
(context) -> assertThat(context.getBean(ReactiveWebServerFactory.class))
.isInstanceOf(TomcatReactiveWebServerFactory.class));
}
@Configuration

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

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

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

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -74,4 +74,5 @@ public class City implements Serializable {
public String toString() {
return getName() + "," + getState() + "," + getCountry();
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -80,4 +80,5 @@ public class Hotel implements Serializable {
public String getZip() {
return this.zip;
}
}

@ -17,5 +17,7 @@
package sample.data.jpa.domain;
public enum Rating {
TERRIBLE, POOR, AVERAGE, GOOD, EXCELLENT
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -128,4 +128,5 @@ public class Review implements Serializable {
public void setDetails(String details) {
this.details = details;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2018 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.
@ -75,4 +75,5 @@ public class ReviewDetails implements Serializable {
public void setDetails(String details) {
this.details = details;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2018 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.
@ -17,5 +17,7 @@
package sample.data.jpa.domain;
public enum TripType {
BUSINESS, COUPLES, FAMILY, FRIENDS, SOLO
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2018 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.
@ -41,4 +41,5 @@ public class CitySearchCriteria implements Serializable {
public void setName(String name) {
this.name = name;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2018 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.
@ -75,4 +75,5 @@ class CityServiceImpl implements CityService {
Assert.notNull(city, "City must not be null");
return this.hotelRepository.findByCity(city, pageable);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -94,5 +94,7 @@ class HotelServiceImpl implements HotelService {
Long count = this.ratingCount.get(rating);
return count == null ? 0 : count;
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -41,8 +41,8 @@ public class CityRepositoryIntegrationTests {
@Test
public void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(PageRequest.of(0, 10));
assertThat(cities.getTotalElements()).isGreaterThan(20L);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -45,6 +45,7 @@ public class HotelRepositoryIntegrationTests {
@Autowired
CityRepository cityRepository;
@Autowired
HotelRepository repository;
@ -53,16 +54,15 @@ public class HotelRepositoryIntegrationTests {
City city = this.cityRepository
.findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0);
assertThat(city.getName()).isEqualTo("Atlanta");
Page<HotelSummary> hotels = this.repository.findByCity(city,
PageRequest.of(0, 10, Direction.ASC, "name"));
Hotel hotel = this.repository.findByCityAndName(city,
hotels.getContent().get(0).getName());
assertThat(hotel.getName()).isEqualTo("Doubletree");
List<RatingCount> counts = this.repository.findRatingCounts(hotel);
assertThat(counts).hasSize(1);
assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE);
assertThat(counts.get(0).getCount()).isGreaterThan(1L);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -74,4 +74,5 @@ public class City implements Serializable {
public String toString() {
return getName() + "," + getState() + "," + getCountry();
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -74,4 +74,5 @@ public class Hotel implements Serializable {
public String getZip() {
return this.zip;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2018 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.
@ -41,4 +41,5 @@ public class CitySearchCriteria implements Serializable {
public void setName(String name) {
this.name = name;
}
}

@ -58,14 +58,12 @@ public class SampleDataRestApplicationTests {
@Test
public void testHome() throws Exception {
this.mvc.perform(get("/api")).andExpect(status().isOk())
.andExpect(content().string(containsString("hotels")));
}
@Test
public void findByNameAndCountry() throws Exception {
this.mvc.perform(get(
"/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia"))
.andExpect(status().isOk())
@ -75,10 +73,10 @@ public class SampleDataRestApplicationTests {
@Test
public void findByContaining() throws Exception {
this.mvc.perform(get(
"/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.cities", hasSize(3)));
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -43,7 +43,6 @@ public class CityRepositoryIntegrationTests {
@Test
public void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(PageRequest.of(0, 10));
assertThat(cities.getTotalElements()).isGreaterThan(20L);
}
@ -63,4 +62,5 @@ public class CityRepositoryIntegrationTests {
PageRequest.of(0, 10));
assertThat(cities.getTotalElements()).isEqualTo(3L);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2018 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.
@ -31,7 +31,6 @@ public class SampleSolrApplicationTests {
@Test
public void testDefaultSettings() throws Exception {
try {
SampleSolrApplication.main(new String[0]);
}
@ -44,9 +43,8 @@ public class SampleSolrApplicationTests {
assertThat(output).contains("name=Sony Playstation");
}
private boolean serverNotRunning(IllegalStateException ex) {
@SuppressWarnings("serial")
private boolean serverNotRunning(IllegalStateException ex) {
NestedCheckedException nested = new NestedCheckedException("failed", ex) {
};
Throwable root = nested.getRootCause();

Loading…
Cancel
Save