Skip to content

Commit 3f78d83

Browse files
authored
Add SECURITY and TOPOLOGY notification categories (#1490)
* Add SECURITY and TOPOLOGY notification categories * Add InternalNotificationCategoryTests * Add a note about the server compatibility * Update documentation
1 parent d9cbb7f commit 3f78d83

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

driver/src/main/java/org/neo4j/driver/NotificationCategory.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ public sealed interface NotificationCategory extends Serializable permits Intern
6464
*/
6565
NotificationCategory DEPRECATION = new InternalNotificationCategory(Type.DEPRECATION);
6666

67+
/**
68+
* A security category.
69+
* <p>
70+
* For instance, the security warnings.
71+
* <p>
72+
* Please note that this category was added to a later server version. Therefore, a compatible server version is
73+
* required to use it.
74+
*
75+
* @since 5.14
76+
*/
77+
NotificationCategory SECURITY = new InternalNotificationCategory(Type.SECURITY);
78+
79+
/**
80+
* A topology category.
81+
* <p>
82+
* For instance, the topology notifications.
83+
* <p>
84+
* Please note that this category was added to a later server version. Therefore, a compatible server version is
85+
* required to use it.
86+
*
87+
* @since 5.14
88+
*/
89+
NotificationCategory TOPOLOGY = new InternalNotificationCategory(Type.TOPOLOGY);
90+
6791
/**
6892
* A generic category.
6993
* <p>

driver/src/main/java/org/neo4j/driver/internal/InternalNotificationCategory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public enum Type {
3535
UNSUPPORTED,
3636
PERFORMANCE,
3737
DEPRECATION,
38+
SECURITY,
39+
TOPOLOGY,
3840
GENERIC
3941
}
4042

@@ -48,6 +50,8 @@ public static Optional<NotificationCategory> valueOf(String value) {
4850
case UNSUPPORTED -> NotificationCategory.UNSUPPORTED;
4951
case PERFORMANCE -> NotificationCategory.PERFORMANCE;
5052
case DEPRECATION -> NotificationCategory.DEPRECATION;
53+
case SECURITY -> NotificationCategory.SECURITY;
54+
case TOPOLOGY -> NotificationCategory.TOPOLOGY;
5155
case GENERIC -> NotificationCategory.GENERIC;
5256
});
5357
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.internal;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
import java.util.Arrays;
25+
import java.util.stream.Stream;
26+
import org.junit.jupiter.api.Named;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.Arguments;
30+
import org.junit.jupiter.params.provider.MethodSource;
31+
import org.neo4j.driver.NotificationCategory;
32+
33+
class InternalNotificationCategoryTests {
34+
35+
@ParameterizedTest
36+
@MethodSource("typeToCategoryMappings")
37+
void parseKnownCategories(TypeAndCategory typeAndCategory) {
38+
var parsedValue = InternalNotificationCategory.valueOf(typeAndCategory.type());
39+
40+
assertTrue(parsedValue.isPresent());
41+
assertEquals(typeAndCategory.category(), parsedValue.get());
42+
}
43+
44+
private static Stream<Arguments> typeToCategoryMappings() {
45+
return Arrays.stream(InternalNotificationCategory.Type.values()).map(type -> switch (type) {
46+
case HINT -> Arguments.of(
47+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.HINT)));
48+
case UNRECOGNIZED -> Arguments.of(
49+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.UNRECOGNIZED)));
50+
case UNSUPPORTED -> Arguments.of(
51+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.UNSUPPORTED)));
52+
case PERFORMANCE -> Arguments.of(
53+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.PERFORMANCE)));
54+
case DEPRECATION -> Arguments.of(
55+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.DEPRECATION)));
56+
case SECURITY -> Arguments.of(
57+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.SECURITY)));
58+
case TOPOLOGY -> Arguments.of(
59+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.TOPOLOGY)));
60+
case GENERIC -> Arguments.of(
61+
Named.of(type.toString(), new TypeAndCategory(type.toString(), NotificationCategory.GENERIC)));
62+
});
63+
}
64+
65+
private record TypeAndCategory(String type, NotificationCategory category) {}
66+
67+
@Test
68+
void shouldReturnEmptyWhenNoMatchFound() {
69+
var unknownCategory = "something";
70+
71+
var parsedValue = InternalNotificationCategory.valueOf(unknownCategory);
72+
73+
System.out.println(parsedValue);
74+
}
75+
}

0 commit comments

Comments
 (0)