MetadataExtractor { public static DatabaseInfo extractDatabaseInfo( Map<String,Value> metadata ) { Value dbValue = metadata.get( "db" ); if ( dbValue == null || dbValue.isNull() ) { return DEFAULT_DATABASE_INFO; } else { return new InternalDatabaseInfo( dbValue.asString() ); } } 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 shouldExtractDatabase() { Map<String,Value> metadata = singletonMap( "db", value( "MyAwesomeDatabase" ) ); DatabaseInfo db = extractDatabaseInfo( metadata ); assertEquals( "MyAwesomeDatabase", db.name() ); }
@Test void shouldDefaultToNullDatabaseName() { Map<String,Value> metadata = singletonMap( "no_db", value( "no_db" ) ); DatabaseInfo db = extractDatabaseInfo( metadata ); assertNull( db.name() ); }
@Test void shouldErrorWhenTypeIsWrong() { Map<String,Value> metadata = singletonMap( "db", value( 10L ) ); Uncoercible error = assertThrows( Uncoercible.class, () -> extractDatabaseInfo( metadata ) ); assertThat( error.getMessage(), startsWith( "Cannot coerce INTEGER to Java String" ) ); }