FetchNodesByPathAndDepthQuery query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId,
0);
List<NodeMongo> result = query.execute();
List<Node> actuals = NodeMongo.toNode(result);
Node expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : {} }", firstRevisionId));
Set<Node> expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, 0);
result = query.execute();
actuals = NodeMongo.toNode(result);
expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : {} }", firstRevisionId));
expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId, 1);
result = query.execute();
actuals = NodeMongo.toNode(result);
expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 } } }",
firstRevisionId));
expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, 1);
result = query.execute();
actuals = NodeMongo.toNode(result);
expected = NodeBuilder.build(String.format(
"{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" : 0.123 } } }", firstRevisionId,
secondRevisionId));
expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId, 2);
result = query.execute();
actuals = NodeMongo.toNode(result);
expected = NodeBuilder
.build(String
.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1, \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
firstRevisionId));
expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, 2);
result = query.execute();
actuals = NodeMongo.toNode(result);
expected = NodeBuilder
.build(String
.format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" : 0.123 , \"b#%2$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null } } } }",
firstRevisionId, secondRevisionId));
expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId, -1);
result = query.execute();
actuals = NodeMongo.toNode(result);
expected = NodeBuilder
.build(String
.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
firstRevisionId));
expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, -1);
result = query.execute();
actuals = NodeMongo.toNode(result);
expected = NodeBuilder
.build(String
.format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" : 0.123 , \"b#%2$s\" : { \"string\" : \"foo\", \"e#%2$s\" : { \"array\" : [ 123, null, 123.456, \"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null } } } }",
firstRevisionId, secondRevisionId));
expecteds = expected.getDescendants(true);
NodeAssert.assertEquals(expecteds, actuals);
}