Samples cleanup

- Modifying dependencies to starter-web with tomcat exclusion plus
  alternative servlet container instead of manual dependency on
  spring-webmvc as it is the preferrable way to use alternative servlet
  container
- Previously RestTemplate with ssl was configured manually in tests - now
  it rellies on autoconfiguration - changed this for multi-connector test
  and added test to ensure that ssl autoconfiguration is working
- Most samples with alterntative servlet containers used some kind of
  service reading property and returning default since it wasn't
  configured - removed it, since it is not specific to using alternative
  servlet containers.

See gh-10548
This commit is contained in:
Ivan Sopov
2017-11-08 16:13:15 +03:00
committed by Stephane Nicoll
parent 792de8f42a
commit d8fa71bc97
63 changed files with 91 additions and 377 deletions

View File

@@ -19,14 +19,13 @@ package sample.jetty.ssl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.client.TestRestTemplate.HttpClientOption;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,19 +37,22 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class SampleJettySslApplicationTests {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private AbstractConfigurableWebServerFactory webServerFactory;
@Test
public void testSsl() {
assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue();
}
@Test
public void testHome() throws Exception {
TestRestTemplate testRestTemplate = new TestRestTemplate(HttpClientOption.SSL);
ResponseEntity<String> entity = testRestTemplate
.getForEntity("https://localhost:" + this.port, String.class);
ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("Hello World");
}
}