MetadataExtractor { public static ServerVersion extractNeo4jServerVersion( Map<String,Value> metadata ) { Value versionValue = metadata.get( "server" ); if ( versionValue == null || versionValue.isNull() ) { throw new UntrustedServerException( "Server provides no product identifier" ); } else { ServerVersion server = ServerVersion.version( versionValue.asString() ); if ( ServerVersion.NEO4J_PRODUCT.equalsIgnoreCase( server.product() ) ) { return server; } else { throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + server.product() + "'" ); } } } 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 shouldExtractServerVersion() { Map<String,Value> metadata = singletonMap( "server", value( "Neo4j/3.5.0" ) ); ServerVersion version = extractNeo4jServerVersion( metadata ); assertEquals( ServerVersion.v3_5_0, version ); }
@Test void shouldFailToExtractServerVersionWhenMetadataDoesNotContainIt() { assertThrows( UntrustedServerException.class, () -> extractNeo4jServerVersion( singletonMap( "server", Values.NULL ) ) ); assertThrows( UntrustedServerException.class, () -> extractNeo4jServerVersion( singletonMap( "server", null ) ) ); }
@Test void shouldFailToExtractServerVersionFromNonNeo4jProduct() { assertThrows( UntrustedServerException.class, () -> extractNeo4jServerVersion( singletonMap( "server", value( "NotNeo4j/1.2.3" ) ) ) ); }