diff --git a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java index 6c33736366..82761525c1 100644 --- a/driver/src/main/java/org/neo4j/driver/NotificationCategory.java +++ b/driver/src/main/java/org/neo4j/driver/NotificationCategory.java @@ -64,6 +64,30 @@ public sealed interface NotificationCategory extends Serializable permits Intern */ NotificationCategory DEPRECATION = new InternalNotificationCategory(Type.DEPRECATION); + /** + * A security category. + *

+ * For instance, the security warnings. + *

+ * 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 + */ + NotificationCategory SECURITY = new InternalNotificationCategory(Type.SECURITY); + + /** + * A topology category. + *

+ * For instance, the topology notifications. + *

+ * 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 + */ + 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; }); } 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); + } +}