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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 { public class ReactiveWebServerFactoryAutoConfigurationTests {
private ReactiveWebApplicationContextRunner contextRunner = private ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner(
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new) AnnotationConfigReactiveWebServerApplicationContext::new)
.withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)); .withConfiguration(AutoConfigurations
.of(ReactiveWebServerFactoryAutoConfiguration.class));
@Test @Test
public void createFromConfigClass() { public void createFromConfigClass() {
this.contextRunner this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class,
.withUserConfiguration(MockWebServerAutoConfiguration.class, HttpHandlerConfiguration.class).run((context) -> {
HttpHandlerConfiguration.class)
.run(context -> {
assertThat(context.getBeansOfType(ReactiveWebServerFactory.class)) assertThat(context.getBeansOfType(ReactiveWebServerFactory.class))
.hasSize(1); .hasSize(1);
assertThat(context.getBeansOfType(WebServerFactoryCustomizer.class)) assertThat(context.getBeansOfType(WebServerFactoryCustomizer.class))
.hasSize(1); .hasSize(1);
assertThat(context.getBeansOfType(ReactiveWebServerFactoryCustomizer.class)) assertThat(context
.hasSize(1); .getBeansOfType(ReactiveWebServerFactoryCustomizer.class))
.hasSize(1);
}); });
} }
@Test @Test
public void missingHttpHandler() { public void missingHttpHandler() {
this.contextRunner this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class)
.withUserConfiguration(MockWebServerAutoConfiguration.class) .run((context) -> assertThat(context.getStartupFailure())
.run(context -> { .isInstanceOf(ApplicationContextException.class)
assertThat(context.getStartupFailure()) .hasMessageContaining("missing HttpHandler bean"));
.isInstanceOf(ApplicationContextException.class)
.hasMessageContaining("missing HttpHandler bean");
});
} }
@Test @Test
@ -75,34 +72,27 @@ public class ReactiveWebServerFactoryAutoConfigurationTests {
this.contextRunner this.contextRunner
.withUserConfiguration(MockWebServerAutoConfiguration.class, .withUserConfiguration(MockWebServerAutoConfiguration.class,
HttpHandlerConfiguration.class, TooManyHttpHandlers.class) HttpHandlerConfiguration.class, TooManyHttpHandlers.class)
.run(context -> { .run((context) -> assertThat(context.getStartupFailure())
assertThat(context.getStartupFailure()) .isInstanceOf(ApplicationContextException.class)
.isInstanceOf(ApplicationContextException.class) .hasMessageContaining("multiple HttpHandler beans : "
.hasMessageContaining("multiple HttpHandler beans : " + + "httpHandler,additionalHttpHandler"));
"httpHandler,additionalHttpHandler");
});
} }
@Test @Test
public void customizeReactiveWebServer() { public void customizeReactiveWebServer() {
this.contextRunner this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class,
.withUserConfiguration(MockWebServerAutoConfiguration.class, HttpHandlerConfiguration.class, ReactiveWebServerCustomization.class)
HttpHandlerConfiguration.class, ReactiveWebServerCustomization.class) .run((context) -> assertThat(
.run(context -> { context.getBean(MockReactiveWebServerFactory.class).getPort())
assertThat(context.getBean(MockReactiveWebServerFactory.class).getPort()) .isEqualTo(9000));
.isEqualTo(9000);
});
} }
@Test @Test
public void defaultWebServerIsTomcat() { public void defaultWebServerIsTomcat() {
// Tomcat should be chosen over Netty if the Tomcat library is present. // Tomcat should be chosen over Netty if the Tomcat library is present.
this.contextRunner this.contextRunner.withUserConfiguration(HttpHandlerConfiguration.class).run(
.withUserConfiguration(HttpHandlerConfiguration.class) (context) -> assertThat(context.getBean(ReactiveWebServerFactory.class))
.run(context -> { .isInstanceOf(TomcatReactiveWebServerFactory.class));
assertThat(context.getBean(ReactiveWebServerFactory.class))
.isInstanceOf(TomcatReactiveWebServerFactory.class);
});
} }
@Configuration @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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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() { public String toString() {
return getName() + "," + getState() + "," + getCountry(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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() { public String getZip() {
return this.zip; return this.zip;
} }
} }

@ -17,5 +17,7 @@
package sample.data.jpa.domain; package sample.data.jpa.domain;
public enum Rating { public enum Rating {
TERRIBLE, POOR, AVERAGE, GOOD, EXCELLENT 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public void setDetails(String details) {
this.details = 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public void setDetails(String details) {
this.details = 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,5 +17,7 @@
package sample.data.jpa.domain; package sample.data.jpa.domain;
public enum TripType { public enum TripType {
BUSINESS, COUPLES, FAMILY, FRIENDS, SOLO 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public void setName(String name) {
this.name = 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); Assert.notNull(city, "City must not be null");
return this.hotelRepository.findByCity(city, pageable); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); Long count = this.ratingCount.get(rating);
return count == null ? 0 : count; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,8 +41,8 @@ public class CityRepositoryIntegrationTests {
@Test @Test
public void findsFirstPageOfCities() { public void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(PageRequest.of(0, 10)); Page<City> cities = this.repository.findAll(PageRequest.of(0, 10));
assertThat(cities.getTotalElements()).isGreaterThan(20L); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,6 +45,7 @@ public class HotelRepositoryIntegrationTests {
@Autowired @Autowired
CityRepository cityRepository; CityRepository cityRepository;
@Autowired @Autowired
HotelRepository repository; HotelRepository repository;
@ -53,16 +54,15 @@ public class HotelRepositoryIntegrationTests {
City city = this.cityRepository City city = this.cityRepository
.findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0); .findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0);
assertThat(city.getName()).isEqualTo("Atlanta"); assertThat(city.getName()).isEqualTo("Atlanta");
Page<HotelSummary> hotels = this.repository.findByCity(city, Page<HotelSummary> hotels = this.repository.findByCity(city,
PageRequest.of(0, 10, Direction.ASC, "name")); PageRequest.of(0, 10, Direction.ASC, "name"));
Hotel hotel = this.repository.findByCityAndName(city, Hotel hotel = this.repository.findByCityAndName(city,
hotels.getContent().get(0).getName()); hotels.getContent().get(0).getName());
assertThat(hotel.getName()).isEqualTo("Doubletree"); assertThat(hotel.getName()).isEqualTo("Doubletree");
List<RatingCount> counts = this.repository.findRatingCounts(hotel); List<RatingCount> counts = this.repository.findRatingCounts(hotel);
assertThat(counts).hasSize(1); assertThat(counts).hasSize(1);
assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE); assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE);
assertThat(counts.get(0).getCount()).isGreaterThan(1L); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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() { public String toString() {
return getName() + "," + getState() + "," + getCountry(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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() { public String getZip() {
return this.zip; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }

@ -58,14 +58,12 @@ public class SampleDataRestApplicationTests {
@Test @Test
public void testHome() throws Exception { public void testHome() throws Exception {
this.mvc.perform(get("/api")).andExpect(status().isOk()) this.mvc.perform(get("/api")).andExpect(status().isOk())
.andExpect(content().string(containsString("hotels"))); .andExpect(content().string(containsString("hotels")));
} }
@Test @Test
public void findByNameAndCountry() throws Exception { public void findByNameAndCountry() throws Exception {
this.mvc.perform(get( this.mvc.perform(get(
"/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia")) "/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia"))
.andExpect(status().isOk()) .andExpect(status().isOk())
@ -75,10 +73,10 @@ public class SampleDataRestApplicationTests {
@Test @Test
public void findByContaining() throws Exception { public void findByContaining() throws Exception {
this.mvc.perform(get( this.mvc.perform(get(
"/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK")) "/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("_embedded.cities", hasSize(3))); .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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,6 @@ public class CityRepositoryIntegrationTests {
@Test @Test
public void findsFirstPageOfCities() { public void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(PageRequest.of(0, 10)); Page<City> cities = this.repository.findAll(PageRequest.of(0, 10));
assertThat(cities.getTotalElements()).isGreaterThan(20L); assertThat(cities.getTotalElements()).isGreaterThan(20L);
} }
@ -63,4 +62,5 @@ public class CityRepositoryIntegrationTests {
PageRequest.of(0, 10)); PageRequest.of(0, 10));
assertThat(cities.getTotalElements()).isEqualTo(3L); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,6 @@ public class SampleSolrApplicationTests {
@Test @Test
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
try { try {
SampleSolrApplication.main(new String[0]); SampleSolrApplication.main(new String[0]);
} }
@ -44,9 +43,8 @@ public class SampleSolrApplicationTests {
assertThat(output).contains("name=Sony Playstation"); assertThat(output).contains("name=Sony Playstation");
} }
@SuppressWarnings("serial")
private boolean serverNotRunning(IllegalStateException ex) { private boolean serverNotRunning(IllegalStateException ex) {
@SuppressWarnings("serial")
NestedCheckedException nested = new NestedCheckedException("failed", ex) { NestedCheckedException nested = new NestedCheckedException("failed", ex) {
}; };
Throwable root = nested.getRootCause(); Throwable root = nested.getRootCause();

Loading…
Cancel
Save