JAVA-3498 Fix integration test in spring-cloud-zuul (fix imports)
This commit is contained in:
parent
47ada8bdca
commit
bef161cc5d
|
@ -10,6 +10,9 @@ import static org.hamcrest.Matchers.both;
|
||||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS;
|
import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS;
|
||||||
|
|
||||||
|
@ -47,15 +50,15 @@ public class GreetingControllerIntegrationTest {
|
||||||
String remaining = headers.getFirst(HEADER_REMAINING + key);
|
String remaining = headers.getFirst(HEADER_REMAINING + key);
|
||||||
String reset = headers.getFirst(HEADER_RESET + key);
|
String reset = headers.getFirst(HEADER_RESET + key);
|
||||||
|
|
||||||
Assert.assertEquals("5", limit);
|
assertEquals("5", limit);
|
||||||
Assert.assertEquals(remaining, "4", remaining);
|
assertEquals(remaining, "4", remaining);
|
||||||
Assert.assertNotNull(reset);
|
assertNotNull(reset);
|
||||||
Assert.assertThat(
|
assertThat(
|
||||||
parseInt(reset),
|
parseInt(reset),
|
||||||
is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(60000)))
|
is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(60000)))
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.assertEquals(OK, response.getStatusCode());
|
assertEquals(OK, response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -64,7 +67,7 @@ public class GreetingControllerIntegrationTest {
|
||||||
HttpHeaders headers = response.getHeaders();
|
HttpHeaders headers = response.getHeaders();
|
||||||
String key = "rate-limit-application_serviceAdvanced_127.0.0.1";
|
String key = "rate-limit-application_serviceAdvanced_127.0.0.1";
|
||||||
assertHeaders(headers, key, false, false);
|
assertHeaders(headers, key, false, false);
|
||||||
Assert.assertEquals(OK, response.getStatusCode());
|
assertEquals(OK, response.getStatusCode());
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class);
|
response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class);
|
||||||
|
@ -75,18 +78,18 @@ public class GreetingControllerIntegrationTest {
|
||||||
String remaining = headers.getFirst(HEADER_REMAINING + key);
|
String remaining = headers.getFirst(HEADER_REMAINING + key);
|
||||||
String reset = headers.getFirst(HEADER_RESET + key);
|
String reset = headers.getFirst(HEADER_RESET + key);
|
||||||
|
|
||||||
Assert.assertEquals(limit, "1");
|
assertEquals(limit, "1");
|
||||||
Assert.assertEquals(remaining, "0");
|
assertEquals(remaining, "0");
|
||||||
Assert.assertNotEquals(reset, "2000");
|
Assert.assertNotEquals(reset, "2000");
|
||||||
|
|
||||||
Assert.assertEquals(TOO_MANY_REQUESTS, response.getStatusCode());
|
assertEquals(TOO_MANY_REQUESTS, response.getStatusCode());
|
||||||
|
|
||||||
TimeUnit.SECONDS.sleep(2);
|
TimeUnit.SECONDS.sleep(2);
|
||||||
|
|
||||||
response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class);
|
response = this.restTemplate.getForEntity(ADVANCED_GREETING, String.class);
|
||||||
headers = response.getHeaders();
|
headers = response.getHeaders();
|
||||||
assertHeaders(headers, key, false, false);
|
assertHeaders(headers, key, false, false);
|
||||||
Assert.assertEquals(OK, response.getStatusCode());
|
assertEquals(OK, response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertHeaders(HttpHeaders headers, String key, boolean nullable, boolean quotaHeaders) {
|
private void assertHeaders(HttpHeaders headers, String key, boolean nullable, boolean quotaHeaders) {
|
||||||
|
@ -107,13 +110,13 @@ public class GreetingControllerIntegrationTest {
|
||||||
Assert.assertNull(reset);
|
Assert.assertNull(reset);
|
||||||
} else {
|
} else {
|
||||||
if (quotaHeaders) {
|
if (quotaHeaders) {
|
||||||
Assert.assertNotNull(quota);
|
assertNotNull(quota);
|
||||||
Assert.assertNotNull(remainingQuota);
|
assertNotNull(remainingQuota);
|
||||||
} else {
|
} else {
|
||||||
Assert.assertNotNull(limit);
|
assertNotNull(limit);
|
||||||
Assert.assertNotNull(remaining);
|
assertNotNull(remaining);
|
||||||
}
|
}
|
||||||
Assert.assertNotNull(reset);
|
assertNotNull(reset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue