From 8c880e95bf28f39e8dee249ecb546599b42b80f4 Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Wed, 4 Oct 2023 17:18:55 +0100 Subject: [PATCH 1/4] Add SECURITY and TOPOLOGY notification categories --- .../org/neo4j/driver/NotificationCategory.java | 16 ++++++++++++++++ .../internal/InternalNotificationCategory.java | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java index 6c33736366..8edded4ac8 100644 --- a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java +++ b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java @@ -64,6 +64,22 @@ public sealed interface NotificationCategory extends Serializable permits Intern */ NotificationCategory DEPRECATION = new InternalNotificationCategory(Type.DEPRECATION); + /** + * A security category. + *

+ * For instance, the security warnings. + * @since 5.14 + */ + NotificationCategory SECURITY = new InternalNotificationCategory(Type.SECURITY); + + /** + * A topology category. + *

+ * For instance, the topology notifications. + * @since 5.14 + */ + NotificationCategory TOPOLOGY = new InternalNotificationCategory(Type.TOPOLOGY); + /** * A generic category. *

diff --git a/driver/src/main/java/org/neo4j/driver/internal/InternalNotificationCategory.java b/driver/src/main/java/org/neo4j/driver/internal/InternalNotificationCategory.java index 1f79bcf9c7..8f84ac2976 100644 --- a/driver/src/main/java/org/neo4j/driver/internal/InternalNotificationCategory.java +++ b/driver/src/main/java/org/neo4j/driver/internal/InternalNotificationCategory.java @@ -35,6 +35,8 @@ public enum Type { UNSUPPORTED, PERFORMANCE, DEPRECATION, + SECURITY, + TOPOLOGY, GENERIC } @@ -48,6 +50,8 @@ public static Optional valueOf(String value) { case UNSUPPORTED -> NotificationCategory.UNSUPPORTED; case PERFORMANCE -> NotificationCategory.PERFORMANCE; case DEPRECATION -> NotificationCategory.DEPRECATION; + case SECURITY -> NotificationCategory.SECURITY; + case TOPOLOGY -> NotificationCategory.TOPOLOGY; case GENERIC -> NotificationCategory.GENERIC; }); } From 2302b52d781aa6646f7b62f1e87d38a52a57be9c Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Thu, 12 Oct 2023 10:40:57 +0100 Subject: [PATCH 2/4] Add InternalNotificationCategoryTests --- .../InternalNotificationCategoryTests.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 driver/src/test/java/org/neo4j/driver/internal/InternalNotificationCategoryTests.java diff --git a/driver/src/test/java/org/neo4j/driver/internal/InternalNotificationCategoryTests.java b/driver/src/test/java/org/neo4j/driver/internal/InternalNotificationCategoryTests.java new file mode 100644 index 0000000000..a66cb5dbed --- /dev/null +++ b/driver/src/test/java/org/neo4j/driver/internal/InternalNotificationCategoryTests.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.neo4j.driver.internal; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.stream.Stream; +import org.junit.jupiter.api.Named; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.neo4j.driver.NotificationCategory; + +class InternalNotificationCategoryTests { + + @ParameterizedTest + @MethodSource("typeToCategoryMappings") + void parseKnownCategories(TypeAndCategory typeAndCategory) { + var parsedValue = InternalNotificationCategory.valueOf(typeAndCategory.type()); + + assertTrue(parsedValue.isPresent()); + assertEquals(typeAndCategory.category(), parsedValue.get()); + } + + private static Stream typeToCategoryMappings() { + return Arrays.stream(InternalNotificationCategory.Type.values()).map(type -> switch (type) { + case HINT -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.HINT))); + case UNRECOGNIZED -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.UNRECOGNIZED))); + case UNSUPPORTED -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.UNSUPPORTED))); + case PERFORMANCE -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.PERFORMANCE))); + case DEPRECATION -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.DEPRECATION))); + case SECURITY -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.SECURITY))); + case TOPOLOGY -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.TOPOLOGY))); + case GENERIC -> Arguments.of( + Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.GENERIC))); + }); + } + + private record TypeAndCategory(String type, NotificationCategory category) {} + + @Test + void shouldReturnEmptyWhenNoMatchFound() { + var unknownCategory = "something"; + + var parsedValue = InternalNotificationCategory.valueOf(unknownCategory); + + System.out.println(parsedValue); + } +} From 88cd789fcfba64eb410be4f0d7a2f3bba1101b3d Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Thu, 12 Oct 2023 10:43:55 +0100 Subject: [PATCH 3/4] Add a note about the server compatibility --- .../main/java/org/neo4j/driver/NotificationCategory.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java index 8edded4ac8..e403bab303 100644 --- a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java +++ b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java @@ -68,6 +68,9 @@ public sealed interface NotificationCategory extends Serializable permits Intern * A security category. *

* For instance, the security warnings. + *

+ * Please note that this category was added to a later server version. + * * @since 5.14 */ NotificationCategory SECURITY = new InternalNotificationCategory(Type.SECURITY); @@ -76,6 +79,9 @@ public sealed interface NotificationCategory extends Serializable permits Intern * A topology category. *

* For instance, the topology notifications. + *

+ * Please note that this category was added to a later server version. + * * @since 5.14 */ NotificationCategory TOPOLOGY = new InternalNotificationCategory(Type.TOPOLOGY); From a3c235e2b9861318c6c7fcb10abeb498e14c444f Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Thu, 12 Oct 2023 10:46:08 +0100 Subject: [PATCH 4/4] Update documentation --- .../main/java/org/neo4j/driver/NotificationCategory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java index e403bab303..82761525c1 100644 --- a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java +++ b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java @@ -69,7 +69,8 @@ public sealed interface NotificationCategory extends Serializable permits Intern *

* For instance, the security warnings. *

- * Please note that this category was added to a later server version. + * Please note that this category was added to a later server version. Therefore, a compatible server version is + * required to use it. * * @since 5.14 */ @@ -80,7 +81,8 @@ public sealed interface NotificationCategory extends Serializable permits Intern *

* For instance, the topology notifications. *

- * Please note that this category was added to a later server version. + * Please note that this category was added to a later server version. Therefore, a compatible server version is + * required to use it. * * @since 5.14 */