Search in sources :

Example 1 with Header

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));
}
Also used : Applications(com.netflix.discovery.shared.Applications) Header(org.mockserver.model.Header) List(java.util.List) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Header

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);
}
Also used : FileSizeUtilities(org.phoenicis.tools.files.FileSizeUtilities) Header(org.mockserver.model.Header) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 3 with Header

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);
}
Also used : FileSizeUtilities(org.phoenicis.tools.files.FileSizeUtilities) Header(org.mockserver.model.Header) Test(org.junit.Test)

Example 4 with Header

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));
}
Also used : Applications(com.netflix.discovery.shared.Applications) Header(org.mockserver.model.Header) List(java.util.List) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Header (org.mockserver.model.Header)4 Applications (com.netflix.discovery.shared.Applications)2 IOException (java.io.IOException)2 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 FileSizeUtilities (org.phoenicis.tools.files.FileSizeUtilities)2 File (java.io.File)1 FileReader (java.io.FileReader)1