This commit is contained in:
Phillip Webb
2015-02-23 19:21:37 -08:00
parent 1f0d45d795
commit 56e31a8c6b
20 changed files with 74 additions and 77 deletions

View File

@@ -49,15 +49,18 @@ public abstract class AbstractHttpClientMockTests {
protected final CloseableHttpClient http = mock(CloseableHttpClient.class);
protected void mockSuccessfulMetadataTextGet() throws IOException {
mockSuccessfulMetadataGet("metadata/service-metadata-2.1.0.txt", "text/plain", true);
mockSuccessfulMetadataGet("metadata/service-metadata-2.1.0.txt", "text/plain",
true);
}
protected void mockSuccessfulMetadataGet(boolean serviceCapabilities) throws IOException {
protected void mockSuccessfulMetadataGet(boolean serviceCapabilities)
throws IOException {
mockSuccessfulMetadataGet("metadata/service-metadata-2.1.0.json",
"application/vnd.initializr.v2.1+json", serviceCapabilities);
}
protected void mockSuccessfulMetadataGetV2(boolean serviceCapabilities) throws IOException {
protected void mockSuccessfulMetadataGetV2(boolean serviceCapabilities)
throws IOException {
mockSuccessfulMetadataGet("metadata/service-metadata-2.0.0.json",
"application/vnd.initializr.v2+json", serviceCapabilities);
}
@@ -68,7 +71,8 @@ public abstract class AbstractHttpClientMockTests {
byte[] content = readClasspathResource(contentPath);
mockHttpEntity(response, content, contentType);
mockStatus(response, 200);
given(this.http.execute(argThat(getForMetadata(serviceCapabilities)))).willReturn(response);
given(this.http.execute(argThat(getForMetadata(serviceCapabilities))))
.willReturn(response);
}
protected byte[] readClasspathResource(String contentPath) throws IOException {
@@ -137,12 +141,10 @@ public abstract class AbstractHttpClientMockTests {
}
private Matcher<HttpGet> getForMetadata(boolean serviceCapabilities) {
if (serviceCapabilities) {
return new HasAcceptHeader(InitializrService.ACCEPT_SERVICE_CAPABILITIES, true);
}
else {
if (!serviceCapabilities) {
return new HasAcceptHeader(InitializrService.ACCEPT_META_DATA, true);
}
return new HasAcceptHeader(InitializrService.ACCEPT_SERVICE_CAPABILITIES, true);
}
private Matcher<HttpGet> getForNonMetadata() {
@@ -206,6 +208,7 @@ public abstract class AbstractHttpClientMockTests {
}
return acceptHeader == null || !this.value.equals(acceptHeader.getValue());
}
}
}

View File

@@ -37,7 +37,8 @@ public class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientM
@Test
public void listMetadataFromServer() throws IOException {
mockSuccessfulMetadataTextGet();
String expected = new String(readClasspathResource("metadata/service-metadata-2.1.0.txt"));
String expected = new String(
readClasspathResource("metadata/service-metadata-2.1.0.txt"));
String content = this.command.generate("http://localhost");
assertThat(content, equalTo(expected));
}