Migrate to MockRestServiceServer

Migrate `RestClientTestWithoutJacksonIntegrationTests` to use
Spring's `MockRestServiceServer`.

See gh-17491
This commit is contained in:
dreis2211 2019-07-14 17:32:03 +01:00 committed by Phillip Webb
parent 1bc9c8544e
commit ca1808ecae
1 changed files with 16 additions and 7 deletions

View File

@ -17,15 +17,18 @@
package org.springframework.boot.test.autoconfigure.web.client;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.http.MediaType;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
/**
* Tests for {@link RestClientTest @RestClientTest} without Jackson.
@ -34,15 +37,21 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("jackson-*.jar")
@RestClientTest(ExampleRestClient.class)
public class RestClientTestWithoutJacksonIntegrationTests {
@Autowired
private MockRestServiceServer server;
@Autowired
private ExampleRestClient client;
@Test
public void restClientTestCanBeUsedWhenJacksonIsNotOnTheClassPath() {
assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", getClass().getClassLoader()))
.isFalse();
Result result = JUnitCore.runClasses(RestClientTestWithComponentIntegrationTests.class);
assertThat(result.getFailureCount()).isEqualTo(0);
assertThat(result.getRunCount()).isGreaterThan(0);
ClassLoader classLoader = getClass().getClassLoader();
assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", classLoader)).isFalse();
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
assertThat(this.client.test()).isEqualTo("hello");
}
}