use of org.hamcrest.Description in project neo4j by neo4j.
the class MessageMatchers method msgFailure.
public static Matcher<ResponseMessage> msgFailure(final Status status, final String message) {
return new TypeSafeMatcher<ResponseMessage>() {
@Override
protected boolean matchesSafely(ResponseMessage t) {
assertThat(t, instanceOf(FailureMessage.class));
FailureMessage msg = (FailureMessage) t;
assertThat(msg.status(), equalTo(status));
assertThat(msg.message(), containsString(message));
return true;
}
@Override
public void describeTo(Description description) {
description.appendText("FAILURE");
}
};
}
use of org.hamcrest.Description in project neo4j by neo4j.
the class MessageMatchers method msgRecord.
public static Matcher<ResponseMessage> msgRecord(final Matcher<Record> matcher) {
return new TypeSafeMatcher<ResponseMessage>() {
@Override
protected boolean matchesSafely(ResponseMessage t) {
assertThat(t, instanceOf(RecordMessage.class));
RecordMessage msg = (RecordMessage) t;
assertThat(msg.record(), matcher);
return true;
}
@Override
public void describeTo(Description description) {
description.appendText("RECORD ");
description.appendDescriptionOf(matcher);
}
};
}
use of org.hamcrest.Description in project neo4j by neo4j.
the class BoltMatchers method hasTransaction.
public static Matcher<BoltStateMachine> hasTransaction() {
return new BaseMatcher<BoltStateMachine>() {
@Override
public boolean matches(final Object item) {
final BoltStateMachine machine = (BoltStateMachine) item;
final StatementProcessor statementProcessor = machine.statementProcessor();
return statementProcessor != null && statementProcessor.hasTransaction();
}
@Override
public void describeTo(Description description) {
description.appendText("no transaction");
}
};
}
use of org.hamcrest.Description in project neo4j by neo4j.
the class TransactionMatchers method rowContainsDeletedEntities.
public static Matcher<? super HTTP.Response> rowContainsDeletedEntities(final int nodes, final int rels) {
return new TypeSafeMatcher<HTTP.Response>() {
@Override
protected boolean matchesSafely(HTTP.Response response) {
try {
Iterator<JsonNode> meta = getJsonNodeWithName(response, "meta").iterator();
int nodeCounter = 0;
int relCounter = 0;
for (int i = 0; i < nodes + rels; ++i) {
assertTrue(meta.hasNext());
JsonNode node = meta.next();
assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
String type = node.get("type").getTextValue();
switch(type) {
case "node":
++nodeCounter;
break;
case "relationship":
++relCounter;
break;
default:
fail("Unexpected type: " + type);
break;
}
}
assertEquals(nodes, nodeCounter);
assertEquals(rels, relCounter);
while (meta.hasNext()) {
JsonNode node = meta.next();
assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.FALSE));
}
return true;
} catch (JsonParseException e) {
return false;
}
}
@Override
public void describeTo(Description description) {
}
};
}
use of org.hamcrest.Description in project neo4j by neo4j.
the class TransactionMatchers method graphContainsDeletedRelationships.
public static Matcher<? super HTTP.Response> graphContainsDeletedRelationships(final int amount) {
return new TypeSafeMatcher<HTTP.Response>() {
@Override
protected boolean matchesSafely(HTTP.Response response) {
try {
Iterator<JsonNode> relationships = getJsonNodeWithName(response, "graph").get("relationships").iterator();
for (int i = 0; i < amount; ++i) {
assertTrue(relationships.hasNext());
JsonNode node = relationships.next();
assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
}
if (relationships.hasNext()) {
JsonNode node = relationships.next();
fail("Expected no more nodes, but got a node with id " + node.get("id"));
}
return true;
} catch (JsonParseException e) {
return false;
}
}
@Override
public void describeTo(Description description) {
}
};
}
Aggregations