Skip to content

Commit

Permalink
Add NotificationClassification.SCHEMA (neo4j#1567)
Browse files Browse the repository at this point in the history
A new notification classification for notifications about indexes and constraints.
  • Loading branch information
injectives committed Aug 20, 2024
1 parent 9fdbdfa commit a21e88a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
11 changes: 11 additions & 0 deletions driver/src/main/java/org/neo4j/driver/NotificationCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ public sealed interface NotificationCategory extends Serializable permits Notifi
* For instance, notifications that are not part of a more specific class.
*/
NotificationCategory GENERIC = NotificationClassification.GENERIC;

/**
* A schema category.
* <p>
* For instance, notifications about indexes and constraints.
* <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.24.0
*/
NotificationCategory SCHEMA = NotificationClassification.SCHEMA;
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,15 @@ public enum NotificationClassification implements NotificationCategory {
* <p>
* For instance, notifications that are not part of a more specific class.
*/
GENERIC
GENERIC,
/**
* A schema category.
* <p>
* For instance, notifications about indexes and constraints.
* <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.24.0
*/
SCHEMA
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.neo4j.driver.internal;

import java.util.stream.Collectors;
import org.neo4j.driver.NotificationCategory;
import org.neo4j.driver.internal.bolt.api.NotificationClassification;
import org.neo4j.driver.internal.bolt.api.NotificationConfig;
import org.neo4j.driver.internal.bolt.api.NotificationSeverity;
Expand Down Expand Up @@ -46,7 +47,7 @@ private static NotificationSeverity map(org.neo4j.driver.NotificationSeverity se
};
}

private static NotificationClassification map(org.neo4j.driver.NotificationCategory category) {
private static NotificationClassification map(NotificationCategory category) {
if (category == null) {
return null;
}
Expand All @@ -60,6 +61,7 @@ private static NotificationClassification map(org.neo4j.driver.NotificationCateg
case SECURITY -> new NotificationClassification(NotificationClassification.Type.SECURITY);
case TOPOLOGY -> new NotificationClassification(NotificationClassification.Type.TOPOLOGY);
case GENERIC -> new NotificationClassification(NotificationClassification.Type.GENERIC);
case SCHEMA -> new NotificationClassification(NotificationClassification.Type.SCHEMA);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public enum Type {
DEPRECATION,
SECURITY,
TOPOLOGY,
GENERIC
GENERIC,
SCHEMA
}

public static Optional<NotificationClassification> valueOf(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static Optional<NotificationCategory> valueOf(String value) {
case SECURITY -> NotificationCategory.SECURITY;
case TOPOLOGY -> NotificationCategory.TOPOLOGY;
case GENERIC -> NotificationCategory.GENERIC;
case SCHEMA -> NotificationCategory.SCHEMA;
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* 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.summary;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.stream.Stream;
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;
import org.neo4j.driver.NotificationClassification;

class InternalNotificationTest {
@ParameterizedTest
@MethodSource("shouldMapArgs")
void shouldMap(String value, NotificationCategory expectedNotificationCategory) {
var notificationCategory = InternalNotification.valueOf(value).orElse(null);

assertEquals(expectedNotificationCategory, notificationCategory);
}

static Stream<Arguments> shouldMapArgs() {
return Arrays.stream(NotificationClassification.values())
.map(notificationClassification -> switch (notificationClassification) {
case HINT -> Arguments.of(notificationClassification.toString(), NotificationCategory.HINT);
case UNRECOGNIZED -> Arguments.of(
notificationClassification.toString(), NotificationCategory.UNRECOGNIZED);
case UNSUPPORTED -> Arguments.of(
notificationClassification.toString(), NotificationCategory.UNSUPPORTED);
case PERFORMANCE -> Arguments.of(
notificationClassification.toString(), NotificationCategory.PERFORMANCE);
case DEPRECATION -> Arguments.of(
notificationClassification.toString(), NotificationCategory.DEPRECATION);
case SECURITY -> Arguments.of(notificationClassification.toString(), NotificationCategory.SECURITY);
case TOPOLOGY -> Arguments.of(notificationClassification.toString(), NotificationCategory.TOPOLOGY);
case GENERIC -> Arguments.of(notificationClassification.toString(), NotificationCategory.GENERIC);
case SCHEMA -> Arguments.of(notificationClassification.toString(), NotificationCategory.SCHEMA);
});
}
}

0 comments on commit a21e88a

Please sign in to comment.