use of org.mockserver.model.Header in project eureka by Netflix.
the class DiscoveryClientRedirectTest method testClientFallsBackToOriginalServerOnError.
@Test
public void testClientFallsBackToOriginalServerOnError() throws Exception {
Applications fullFetchApps1 = dataGenerator.takeDelta(1);
String fullFetchJson1 = toJson(fullFetchApps1);
Applications fullFetchApps2 = EurekaEntityFunctions.mergeApplications(fullFetchApps1, dataGenerator.takeDelta(1));
String fullFetchJson2 = toJson(fullFetchApps2);
redirectServerMockClient.when(request().withMethod("GET").withPath("/eureka/v2/apps/")).respond(response().withStatusCode(302).withHeader(new Header("Location", targetServerBaseUri + "/eureka/v2/apps/")));
targetServerMockClient.client.when(request().withMethod("GET").withPath("/eureka/v2/apps/"), Times.exactly(1)).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(fullFetchJson1));
targetServerMockClient.client.when(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), Times.exactly(1)).respond(response().withStatusCode(500));
redirectServerMockClient.when(request().withMethod("GET").withPath("/eureka/v2/apps/delta")).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(fullFetchJson2));
final EurekaClient client = registryFetchClientRule.getClient();
await(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
List<Application> applicationList = client.getApplications().getRegisteredApplications();
return !applicationList.isEmpty() && applicationList.get(0).getInstances().size() == 2;
}
}, 1, TimeUnit.MINUTES);
redirectServerMockClient.verify(request().withMethod("GET").withPath("/eureka/v2/apps/"), exactly(1));
redirectServerMockClient.verify(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), exactly(1));
targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/"), exactly(1));
targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), exactly(1));
}
use of org.mockserver.model.Header in project POL-POM-5 by PlayOnLinux.
the class DownloaderTest method testGet_DownloadFile_FileIsDownloaded.
@Test
public void testGet_DownloadFile_FileIsDownloaded() throws Exception {
mockServer.when(request().withMethod("GET").withPath("/test.txt")).respond(response().withStatusCode(200).withHeaders(new Header("Content-Type", "application/config")).withBody("Content file to download"));
File temporaryFile = File.createTempFile("test", "txt");
temporaryFile.deleteOnExit();
new Downloader(new FileSizeUtilities()).get(mockServerURL, temporaryFile, e -> {
});
String fileContent = IOUtils.toString(new FileReader(temporaryFile));
assertEquals("Content file to download", fileContent);
}
use of org.mockserver.model.Header in project POL-POM-5 by PlayOnLinux.
the class DownloaderTest method testGet_DownloadFileInAString_FileIsDownloaded.
@Test
public void testGet_DownloadFileInAString_FileIsDownloaded() throws Exception {
mockServer.when(request().withMethod("GET").withPath("/test2.txt")).respond(response().withStatusCode(200).withHeaders(new Header("Content-Type", "application/config")).withBody("Content file to download 2"));
String result = new Downloader(new FileSizeUtilities()).get(mockServerURLFile2, e -> {
});
assertEquals("Content file to download 2", result);
}
use of org.mockserver.model.Header in project eureka by Netflix.
the class DiscoveryClientRedirectTest method testClientQueryFollowsRedirectsAndPinsToTargetServer.
@Test
public void testClientQueryFollowsRedirectsAndPinsToTargetServer() throws Exception {
Applications fullFetchApps = dataGenerator.takeDelta(1);
String fullFetchJson = toJson(fullFetchApps);
Applications deltaFetchApps = dataGenerator.takeDelta(1);
String deltaFetchJson = toJson(deltaFetchApps);
redirectServerMockClient.when(request().withMethod("GET").withPath("/eureka/v2/apps/")).respond(response().withStatusCode(302).withHeader(new Header("Location", targetServerBaseUri + "/eureka/v2/apps/")));
targetServerMockClient.client.when(request().withMethod("GET").withPath("/eureka/v2/apps/")).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(fullFetchJson));
targetServerMockClient.client.when(request().withMethod("GET").withPath("/eureka/v2/apps/delta")).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(deltaFetchJson));
final EurekaClient client = registryFetchClientRule.getClient();
await(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
List<Application> applicationList = client.getApplications().getRegisteredApplications();
return !applicationList.isEmpty() && applicationList.get(0).getInstances().size() == 2;
}
}, 1, TimeUnit.MINUTES);
redirectServerMockClient.verify(request().withMethod("GET").withPath("/eureka/v2/apps/"), exactly(1));
redirectServerMockClient.verify(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), exactly(0));
targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/"), exactly(1));
targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), atLeast(1));
}
Aggregations