[TEST] remove status matcher and hasStatus assertion
All it does is checking the status code of a response, which can be done with a single line in each test
This commit is contained in:
parent
f17f0f9247
commit
b891c46657
|
@ -30,9 +30,6 @@ import org.elasticsearch.test.ESIntegTestCase.Scope;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasStatus;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
|
@ -60,13 +57,13 @@ public class ResponseHeaderPluginIT extends ESIntegTestCase {
|
|||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
assertThat(response, hasStatus(UNAUTHORIZED));
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(401));
|
||||
assertThat(response.getHeader("Secret"), equalTo("required"));
|
||||
}
|
||||
|
||||
try (ElasticsearchResponse authResponse = getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null,
|
||||
new BasicHeader("Secret", "password"))) {
|
||||
assertThat(authResponse, hasStatus(OK));
|
||||
assertThat(authResponse.getStatusLine().getStatusCode(), equalTo(200));
|
||||
assertThat(authResponse.getHeader("Secret"), equalTo("granted"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,12 +63,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasStatus;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
@ -222,7 +221,7 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase {
|
|||
try (ElasticsearchResponse response = getRestClient().performRequest(
|
||||
"GET", "/" + queryIndex + "/_search", Collections.emptyMap(), null,
|
||||
new BasicHeader(randomHeaderKey, randomHeaderValue), new BasicHeader(relevantHeaderName, randomHeaderValue))) {
|
||||
assertThat(response, hasStatus(OK));
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||
List<RequestAndHeaders> searchRequests = getRequests(SearchRequest.class);
|
||||
assertThat(searchRequests, hasSize(greaterThan(0)));
|
||||
for (RequestAndHeaders requestAndHeaders : searchRequests) {
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.elasticsearch.action.search.ShardSearchFailure;
|
|||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||
|
@ -486,10 +485,6 @@ public class ElasticsearchAssertions {
|
|||
return new ElasticsearchMatchers.SearchHitHasScoreMatcher(score);
|
||||
}
|
||||
|
||||
public static Matcher<ElasticsearchResponse> hasStatus(RestStatus restStatus) {
|
||||
return new ElasticsearchMatchers.ElasticsearchResponseHasStatusMatcher(restStatus);
|
||||
}
|
||||
|
||||
public static <T extends Query> T assertBooleanSubQuery(Query query, Class<T> subqueryType, int i) {
|
||||
assertThat(query, instanceOf(BooleanQuery.class));
|
||||
BooleanQuery q = (BooleanQuery) query;
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.elasticsearch.test.hamcrest;
|
||||
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
@ -117,28 +115,4 @@ public class ElasticsearchMatchers {
|
|||
description.appendText("searchHit score should be ").appendValue(score);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ElasticsearchResponseHasStatusMatcher extends TypeSafeMatcher<ElasticsearchResponse> {
|
||||
|
||||
private RestStatus restStatus;
|
||||
|
||||
public ElasticsearchResponseHasStatusMatcher(RestStatus restStatus) {
|
||||
this.restStatus = restStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesSafely(ElasticsearchResponse response) {
|
||||
return response.getStatusLine().getStatusCode() == restStatus.getStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeMismatchSafely(final ElasticsearchResponse response, final Description mismatchDescription) {
|
||||
mismatchDescription.appendText(" was ").appendValue(response.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(final Description description) {
|
||||
description.appendText("Elasticsearch response status code should be ").appendValue(restStatus.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue