Moving an ignored test to samples

since the releaser ignores the modules that do not get deployed, then it's safe to bring back this test

fixes gh-626
This commit is contained in:
Marcin Grzejszczak
2018-10-18 08:21:17 +02:00
parent 50d62b6ee8
commit bd4783eefd
10 changed files with 637 additions and 10 deletions

View File

@@ -0,0 +1,91 @@
package com.example;
import java.net.URI;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@Configuration
@EnableAutoConfiguration
@Import({ Service.class, Controller.class })
public class WiremockTestsApplication {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(WiremockTestsApplication.class, args);
}
}
@RestController
class Controller {
private final Service service;
public Controller(Service service) {
this.service = service;
}
@RequestMapping("/")
public String home() {
return this.service.go();
}
}
@Component
class Service {
@Value("${app.baseUrl:http://example.org}")
String base;
private RestTemplate restTemplate;
public Service(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public String go() {
return this.restTemplate.getForEntity(this.base + "/test", String.class)
.getBody();
}
public String pom() {
return this.restTemplate
.exchange(RequestEntity.get(URI.create(this.base + "/pom.xml"))
.accept(mediaTypes()).build(), String.class)
.getBody();
}
private MediaType[] mediaTypes() {
return Stream
.of("text/plain", "text/plain", "application/json", "application/json",
"application/*+json", "application/*+json", "*/*", "*/*")
.map(MediaType::valueOf).toArray(MediaType[]::new);
}
public String go2() {
return this.restTemplate.getForEntity(this.base + "/test2", String.class)
.getBody();
}
public void setBase(String base) {
this.base = base;
}
}

View File

@@ -0,0 +1 @@
server.port=0

View File

@@ -0,0 +1,29 @@
package com.example;
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.cloud.contract.wiremock.AutoConfigureWireMock;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = WiremockTestsApplication.class,
properties = "app.baseUrl=http://localhost:${wiremock.server.port}",
webEnvironment = WebEnvironment.NONE)
// resource from a Initilizr stubs jar
@AutoConfigureWireMock(port = 0,
files = "classpath*:META-INF/io.spring.initializr/initializr-web/0.4.0.BUILD-SNAPSHOT")
public class AutoConfigureWireMockFilesApplicationWithUrlResourceTests {
@Autowired private Service service;
@Test public void contextLoads() throws Exception {
assertThat(this.service.pom())
.contains("<artifactId>spring-boot-starter-parent</artifactId>");
}
}