use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class UniquenessOfPathsDocTest method pathUniquenessExample.
@Graph({ "Pet0 descendant Pet1", "Pet0 descendant Pet2", "Pet0 descendant Pet3", "Principal1 owns Pet1", "Principal2 owns Pet2", "Principal1 owns Pet3" })
@Test
@Documented(UNIQUENESS_OF_PATHS_DOC)
public void pathUniquenessExample() {
Node start = data.get().get("Pet0");
gen.get().addSnippet("graph", createGraphVizWithNodeId("Descendants example graph", graphdb(), gen.get().getTitle()));
gen.get();
gen.get().addTestSourceSnippets(this.getClass(), "traverser", "traverseNodeGlobal");
// tag::traverser[]
Node dataTarget = data.get().get("Principal1");
String output = "";
int count = 0;
try (Transaction transaction = graphdb().beginTx()) {
start = transaction.getNodeById(start.getId());
final Node target = transaction.getNodeById(dataTarget.getId());
TraversalDescription td = transaction.traversalDescription().uniqueness(Uniqueness.NODE_PATH).evaluator(new Evaluator() {
@Override
public Evaluation evaluate(Path path) {
boolean endNodeIsTarget = path.endNode().equals(target);
return Evaluation.of(endNodeIsTarget, !endNodeIsTarget);
}
});
Traverser results = td.traverse(start);
for (Path path : results) {
count++;
output += path.toString() + "\n";
}
}
gen.get().addSnippet("output", createOutputSnippet(output));
assertEquals(2, count);
String output2 = "";
count = 0;
try (Transaction tx = graphdb().beginTx()) {
start = tx.getNodeById(start.getId());
final Node target = tx.getNodeById(dataTarget.getId());
// tag::traverseNodeGlobal[]
TraversalDescription nodeGlobalTd = tx.traversalDescription().uniqueness(Uniqueness.NODE_PATH).evaluator(new Evaluator() {
@Override
public Evaluation evaluate(Path path) {
boolean endNodeIsTarget = path.endNode().equals(target);
return Evaluation.of(endNodeIsTarget, !endNodeIsTarget);
}
}).uniqueness(Uniqueness.NODE_GLOBAL);
Traverser results = nodeGlobalTd.traverse(start);
// we should get two paths back, through Pet1 and Pet3
for (Path path : results) {
count++;
output2 += path.toString() + "\n";
}
}
gen.get().addSnippet("outNodeGlobal", createOutputSnippet(output2));
assertEquals(1, count);
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TestData method apply.
@Override
public Statement apply(final Statement base, final Description description) {
final Title title = description.getAnnotation(Title.class);
final Documented doc = description.getAnnotation(Documented.class);
GraphDescription.Graph g = description.getAnnotation(GraphDescription.Graph.class);
if (g == null) {
g = description.getTestClass().getAnnotation(GraphDescription.Graph.class);
}
final GraphDescription graph = GraphDescription.create(g);
return new Statement() {
@Override
public void evaluate() throws Throwable {
product.set(create(graph, title == null ? null : title.value(), doc == null ? null : doc.value(), description.getMethodName()));
try {
base.evaluate();
} finally {
product.set(null);
}
}
};
}
use of org.neo4j.annotations.documented.Documented in project neo4j by neo4j.
the class TestData method apply.
@Override
public Statement apply(final Statement base, final Description description) {
final Title title = description.getAnnotation(Title.class);
final Documented doc = description.getAnnotation(Documented.class);
GraphDescription.Graph g = description.getAnnotation(GraphDescription.Graph.class);
if (g == null) {
g = description.getTestClass().getAnnotation(GraphDescription.Graph.class);
}
final GraphDescription graph = GraphDescription.create(g);
return new Statement() {
@Override
public void evaluate() throws Throwable {
product.set(create(graph, title == null ? null : title.value(), doc == null ? null : doc.value(), description.getMethodName()));
try {
base.evaluate();
} finally {
product.set(null);
}
}
};
}
use of org.neo4j.annotations.documented.Documented in project neo4j by neo4j.
the class AuthenticationIT method successful_authentication.
@Test
@Documented("Authenticate to access the server\n" + "\n" + "Authenticate by sending a username and a password to Neo4j using HTTP Basic Auth.\n" + "Requests should include an +Authorization+ header, with a value of +Basic <payload>+,\n" + "where \"payload\" is a base64 encoded string of \"username:password\".")
public void successful_authentication() throws JsonParseException, IOException {
// Given
startServerWithConfiguredUser();
// Then
HTTP.Response response = HTTP.withBasicAuth("neo4j", "secret").POST(txCommitURL("system"), query("SHOW USERS"));
assertThat(response.status()).isEqualTo(200);
final JsonNode jsonNode = getResultRow(response);
assertThat(jsonNode.get(0).asText()).isEqualTo("neo4j");
assertThat(jsonNode.get(1).asBoolean()).isEqualTo(false);
}
use of org.neo4j.annotations.documented.Documented in project neo4j by neo4j.
the class AuthenticationIT method missing_authorization.
@Test
@Documented("Missing authorization\n" + "\n" + "If an +Authorization+ header is not supplied, the server will reply with an error.")
public void missing_authorization() throws JsonParseException, IOException {
// Given
startServerWithConfiguredUser();
// Document
RESTRequestGenerator.ResponseEntity response = gen.get().expectedStatus(401).expectedHeader("WWW-Authenticate", "Basic realm=\"Neo4j\"").get(databaseURL());
// Then
JsonNode data = JsonHelper.jsonNode(response.entity());
JsonNode firstError = data.get("errors").get(0);
assertThat(firstError.get("code").asText()).isEqualTo(Status.Security.Unauthorized.code().serialize());
assertThat(firstError.get("message").asText()).isEqualTo("No authentication header supplied.");
}
Aggregations