protected void assertExpectedMapping(String alias, String cypher, Map<String, Object> params) throws Exception {
getTransactionManager().begin();
ResourceIterator<Object> columnAs = executeCypherQuery( "MATCH " + cypher + " RETURN " + alias, params ).columnAs( alias );
assertThat( columnAs.hasNext() ).as( cypher + " not found, cannot count properties" ).isTrue();
PropertyContainer propertyContainer = (PropertyContainer) columnAs.next();
Iterable<String> propertyKeys = propertyContainer.getPropertyKeys();
List<String> unexpectedProperties = new ArrayList<String>();
Set<String> expectedProperties = null;
@SuppressWarnings("unchecked")
Map<String, Object> expectedPropertiesMap = (Map<String, Object>) params.get( alias );
if (expectedPropertiesMap != null) {
expectedProperties = expectedPropertiesMap.keySet();
}
for ( Iterator<String> iterator = propertyKeys.iterator(); iterator.hasNext(); ) {
String actual = iterator.next();
if ( !expectedProperties.contains( actual ) ) {
unexpectedProperties.add( actual );
}
}
List<String> missingProperties = new ArrayList<String>();
if ( expectedProperties != null ) {
for ( String expected : expectedProperties ) {
if ( !propertyContainer.hasProperty( expected ) ) {
missingProperties.add( expected );
}
}
}
assertThat( unexpectedProperties ).as( "Unexpected properties for " + cypher ).isEmpty();