Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions driver/src/main/java/org/neo4j/driver/NotificationCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ public sealed interface NotificationCategory extends Serializable permits Intern
*/
NotificationCategory DEPRECATION = new InternalNotificationCategory(Type.DEPRECATION);

/**
* A security category.
* <p>
* For instance, the security warnings.
* <p>
* 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.
* <p>
* For instance, the topology notifications.
* <p>
* 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.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public enum Type {
UNSUPPORTED,
PERFORMANCE,
DEPRECATION,
SECURITY,
TOPOLOGY,
GENERIC
}

Expand All @@ -48,6 +50,8 @@ public static Optional<NotificationCategory> 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;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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);
}
}