use of org.structr.core.graph.BulkSetNodePropertiesCommand in project structr by structr.
the class MaintenanceTest method testBulkSetNodePropertiesCommand.
@Test
public void testBulkSetNodePropertiesCommand() {
final Integer one = 1;
try {
// create test nodes first
createTestNodes(TestOne.class, 100);
try {
// test failure with wrong type
app.command(BulkSetNodePropertiesCommand.class).execute(toMap("type", "NonExistingType"));
fail("Using BulkSetNodePropertiesCommand with a non-existing type should throw an exception.");
} catch (FrameworkException fex) {
// status: 422
assertEquals(422, fex.getStatus());
assertEquals("Invalid type NonExistingType", fex.getMessage());
}
try {
// test failure without type
app.command(BulkSetNodePropertiesCommand.class).execute(toMap("anInt", 1));
fail("Using BulkSetNodePropertiesCommand without a type property should throw an exception.");
} catch (FrameworkException fex) {
// status: 422
assertEquals(422, fex.getStatus());
assertEquals("Type must not be empty", fex.getMessage());
}
// test success
app.command(BulkSetNodePropertiesCommand.class).execute(toMap("type", "TestOne", "anInt", 1, "aString", "one"));
try (final Tx tx = app.tx()) {
// check nodes, we should find 100 TestOnes here, and none TestTwos
assertEquals(0, app.nodeQuery(TestTwo.class).getResult().size());
assertEquals(100, app.nodeQuery(TestOne.class).getResult().size());
// check nodes
for (final TestOne test : app.nodeQuery(TestOne.class)) {
assertEquals(one, test.getProperty(TestOne.anInt));
assertEquals("one", test.getProperty(TestOne.aString));
}
}
// advanced: modify type
app.command(BulkSetNodePropertiesCommand.class).execute(toMap("type", "TestOne", "newType", "TestTwo"));
try (final Tx tx = app.tx()) {
// check nodes, we should find 100 TestTwos here, and none TestOnes
assertEquals(0, app.nodeQuery(TestOne.class).getResult().size());
assertEquals(100, app.nodeQuery(TestTwo.class).getResult().size());
}
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
Aggregations