use of org.hamcrest.Matcher in project crate by crate.
the class SymbolMatchers method isFunction.
public static Matcher<Symbol> isFunction(final String name, @Nullable final List<DataType> argumentTypes) {
if (argumentTypes == null) {
return isFunction(name);
}
Matcher[] argMatchers = new Matcher[argumentTypes.size()];
ListIterator<DataType> it = argumentTypes.listIterator();
while (it.hasNext()) {
int i = it.nextIndex();
DataType type = it.next();
argMatchers[i] = hasDataType(type);
}
//noinspection unchecked
return isFunction(name, argMatchers);
}
use of org.hamcrest.Matcher in project elasticsearch by elastic.
the class DeprecationHttpIT method testUniqueDeprecationResponsesMergedTogether.
/**
* Attempts to do a scatter/gather request that expects unique responses per sub-request.
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/19222")
public void testUniqueDeprecationResponsesMergedTogether() throws IOException {
final String[] indices = new String[randomIntBetween(2, 5)];
// add at least one document for each index
for (int i = 0; i < indices.length; ++i) {
indices[i] = "test" + i;
// create indices with a single shard to reduce noise; the query only deprecates uniquely by index anyway
assertTrue(prepareCreate(indices[i]).setSettings(Settings.builder().put("number_of_shards", 1)).get().isAcknowledged());
int randomDocCount = randomIntBetween(1, 2);
for (int j = 0; j < randomDocCount; ++j) {
index(indices[i], "type", Integer.toString(j), "{\"field\":" + j + "}");
}
}
refresh(indices);
final String commaSeparatedIndices = Stream.of(indices).collect(Collectors.joining(","));
final String body = "{\"query\":{\"bool\":{\"filter\":[{\"" + TestDeprecatedQueryBuilder.NAME + "\":{}}]}}}";
// trigger all index deprecations
Response response = getRestClient().performRequest("GET", "/" + commaSeparatedIndices + "/_search", Collections.emptyMap(), new StringEntity(body, ContentType.APPLICATION_JSON));
assertThat(response.getStatusLine().getStatusCode(), equalTo(OK.getStatus()));
final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
final List<Matcher<String>> headerMatchers = new ArrayList<>(indices.length);
for (String index : indices) {
headerMatchers.add(containsString(LoggerMessageFormat.format("[{}] index", (Object) index)));
}
assertThat(deprecatedWarnings, hasSize(headerMatchers.size()));
for (Matcher<String> headerMatcher : headerMatchers) {
assertThat(deprecatedWarnings, hasItem(headerMatcher));
}
}
use of org.hamcrest.Matcher in project freud by LMAX-Exchange.
the class ClassByteCodeMethodMatchers method methodInvokedWithParams.
public static FreudExtendedMatcher<ClassByteCodeMethod> methodInvokedWithParams(final Class expectedOwner, final String expectedMethodName, final Matcher<OperandStack>... expectedParamsPassed) {
return new FreudExtendedMatcher<ClassByteCodeMethod>() {
private String expectedOwnerName;
{
expectedOwnerName = typeEncoding(expectedOwner);
}
@Override
protected boolean matchesSafely(final ClassByteCodeMethod item) {
final boolean[] found = new boolean[1];
found[0] = false;
item.findInstruction(new AbstractInstructionVisitor() {
@Override
public void methodInvocation(final Instruction instruction, final String owner, final String methodName, final String... args) {
if (!found[0] && expectedOwnerName.equals(owner) && expectedMethodName.equals(methodName)) {
Instruction prevInstruction = item.getInstruction(instruction.getInstructionIndex() - 1);
OperandStack operandStack = prevInstruction.getOperandStack();
found[0] = true;
for (int i = expectedParamsPassed.length - 1; i >= 0; i--) {
Matcher<OperandStack> matcher = expectedParamsPassed[i];
if (!matcher.matches(operandStack)) {
found[0] = false;
break;
}
operandStack = operandStack.next();
}
}
}
});
return found[0];
}
@Override
public void describeTo(final Description description) {
description.appendText("methodInvokedWithParams(" + expectedOwner.getName() + ", " + expectedMethodName + ")");
}
};
}
use of org.hamcrest.Matcher in project neo4j by neo4j.
the class StreamMatchers method equalsStream.
public static Matcher<BoltResult> equalsStream(final String[] fieldNames, final Matcher... records) {
return new TypeSafeMatcher<BoltResult>() {
@Override
protected boolean matchesSafely(BoltResult item) {
if (!Arrays.equals(fieldNames, item.fieldNames())) {
return false;
}
final Iterator<Matcher> expected = asList(records).iterator();
final AtomicBoolean matched = new AtomicBoolean(true);
try {
item.accept(new BoltResult.Visitor() {
@Override
public void visit(Record record) {
if (!expected.hasNext() || !expected.next().matches(record)) {
matched.set(false);
}
}
@Override
public void addMetadata(String key, Object value) {
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
// All records matched, and there are no more expected records.
return matched.get() && !expected.hasNext();
}
@Override
public void describeTo(Description description) {
description.appendText("Stream[").appendValueList(" fieldNames=[", ",", "]", fieldNames).appendList(", records=[", ",", "]", asList(records));
}
};
}
use of org.hamcrest.Matcher in project spring-boot by spring-projects.
the class EndpointWebMvcAutoConfigurationTests method assertContent.
private void assertContent(String scheme, String url, int port, Object expected) throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
ClientHttpRequest request = requestFactory.createRequest(new URI(scheme + "://localhost:" + port + url), HttpMethod.GET);
try {
ClientHttpResponse response = request.execute();
if (HttpStatus.NOT_FOUND.equals(response.getStatusCode())) {
throw new FileNotFoundException();
}
try {
String actual = StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"));
if (expected instanceof Matcher) {
assertThat(actual).is(Matched.by((Matcher<?>) expected));
} else {
assertThat(actual).isEqualTo(expected);
}
} finally {
response.close();
}
} catch (Exception ex) {
if (expected == null) {
if (SocketException.class.isInstance(ex) || FileNotFoundException.class.isInstance(ex)) {
return;
}
}
throw ex;
}
}
Aggregations