MetadataExtractor { public QueryKeys extractQueryKeys( Map<String,Value> metadata ) { Value keysValue = metadata.get( "fields" ); if ( keysValue != null ) { if ( !keysValue.isEmpty() ) { QueryKeys keys = new QueryKeys( keysValue.size() ); for ( Value value : keysValue.values() ) { keys.add( value.asString() ); } return keys; } } return QueryKeys.empty(); } MetadataExtractor( String resultAvailableAfterMetadataKey, String resultConsumedAfterMetadataKey ); QueryKeys extractQueryKeys( Map<String,Value> metadata ); long extractQueryId( Map<String,Value> metadata ); long extractResultAvailableAfter( Map<String,Value> metadata ); ResultSummary extractSummary(Query query, Connection connection, long resultAvailableAfter, Map<String,Value> metadata ); static DatabaseInfo extractDatabaseInfo( Map<String,Value> metadata ); static Bookmark extractBookmarks( Map<String,Value> metadata ); static ServerVersion extractNeo4jServerVersion( Map<String,Value> metadata ); static final int ABSENT_QUERY_ID; }
@Test void shouldExtractQueryKeys() { List<String> keys = asList( "hello", " ", "world", "!" ); Map<String, Integer> keyIndex = new HashMap<>(); keyIndex.put( "hello", 0 ); keyIndex.put( " ", 1 ); keyIndex.put( "world", 2 ); keyIndex.put( "!", 3 ); QueryKeys extracted = extractor.extractQueryKeys( singletonMap( "fields", value( keys ) ) ); assertEquals( keys, extracted.keys() ); assertEquals( keyIndex, extracted.keyIndex() ); }
@Test void shouldExtractEmptyQueryKeysWhenNoneInMetadata() { QueryKeys extracted = extractor.extractQueryKeys( emptyMap() ); assertEquals( emptyList(), extracted.keys() ); assertEquals( emptyMap(), extracted.keyIndex() ); }