diff --git a/jruby/neo4j/driver/ext/config_converter.rb b/jruby/neo4j/driver/ext/config_converter.rb index 53cc5bdc..64ed28d7 100644 --- a/jruby/neo4j/driver/ext/config_converter.rb +++ b/jruby/neo4j/driver/ext/config_converter.rb @@ -68,14 +68,14 @@ def trust_strategy(**config) def notification_config(minimum_severity: nil, disabled_categories: nil) org.neo4j.driver.internal.InternalNotificationConfig.new( - value_of(org.neo4j.driver.internal.InternalNotificationSeverity, minimum_severity), + value_of(org.neo4j.driver.internal.InternalNotificationSeverity, minimum_severity).or_else(nil), disabled_categories - &.map { |value| value_of(org.neo4j.driver.internal.InternalNotificationCategory, value) } + &.map { |value| value_of(org.neo4j.driver.NotificationClassification, value) } &.then(&java.util.HashSet.method(:new))) end def value_of(klass, value) - klass.value_of(value&.to_s&.upcase).or_else(nil) + klass.value_of(value&.to_s&.upcase) end end end diff --git a/ruby/neo4j/driver/notification_classification.rb b/ruby/neo4j/driver/notification_classification.rb new file mode 100644 index 00000000..550abf5d --- /dev/null +++ b/ruby/neo4j/driver/notification_classification.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Neo4j + module Driver + module NotificationClassification + DEPRECATION = :deprecation + GENERIC = :generic + HINT = :hint + PERFORMANCE = :performance + SCHEMA = :schema + SECURITY = :security + TOPOLOGY = :topology + UNRECOGNIZED = :unrecognized + UNSUPPORTED = :unsupported + end + end +end diff --git a/ruby/neo4j/driver/notification_severity.rb b/ruby/neo4j/driver/notification_severity.rb new file mode 100644 index 00000000..7cb60b5b --- /dev/null +++ b/ruby/neo4j/driver/notification_severity.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Neo4j + module Driver + module NotificationSeverity + INFORMATION = :information + OFF = :off + WARNING = :warning + end + end +end diff --git a/spec/neo4j/driver/dev_manual_examples_spec.rb b/spec/neo4j/driver/dev_manual_examples_spec.rb index d900ecb0..9b46c837 100644 --- a/spec/neo4j/driver/dev_manual_examples_spec.rb +++ b/spec/neo4j/driver/dev_manual_examples_spec.rb @@ -87,9 +87,15 @@ it { is_expected.to be true } end + + context 'Example 2.12. Notification config' do + let(:config) { { notification_config: { minimum_severity: :warning, disabled_categories: [:hint, :generic] } } } + + it { is_expected.to be true } + end end - context 'Example 2.12. Service unavailable' do + context 'Example 2.13. Service unavailable' do def add_item(driver) session = driver.session session.execute_write { |tx| tx.run('CREATE (a:Item)') } @@ -293,4 +299,35 @@ def match_person_nodes(tx) expect(add_employees('abc')).to eq(2) end end + + context '5. Notification config', version: '>=5', concurrency: true do + subject do + driver.session do |session| + result = session.run( + 'MATCH p=shortestPath((:Person {name: $start})-[*]->(:Person {name: $end})) RETURN p', + start: 'Alice', + end: 'Bob' + ) + result.consume.notifications.map(&:code) + end + end + + let(:host) { 'localhost' } # work around for https://github.com/neo4j/neo4j-java-driver/issues/1652 + let(:neo4j_user) { ENV.fetch('TEST_NEO4J_USER', 'neo4j') } + let(:neo4j_password) { ENV.fetch('TEST_NEO4J_PASS', 'password') } + let(:auth_tokens) { Neo4j::Driver::AuthTokens.basic(neo4j_user, neo4j_password) } + let(:driver) { Neo4j::Driver::GraphDatabase.driver(uri, auth_tokens, **config) } + + context 'Example 5.1. Default severity and categories' do + let(:config) { {} } + + it { is_expected.not_to be_empty } + end + + context 'Example 5.2. Custom severity and categories' do + let(:config) { { notification_config: { minimum_severity: :warning, disabled_categories: [:hint, :generic] } } } + + it { is_expected.to be_empty } + end + end end