From 008d3b40c1483efdae1662932ca8e7931320405a Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Thu, 1 Feb 2024 16:37:29 +0100 Subject: [PATCH 01/11] #4377 - Configure include and exclude patterns for logged events - Deprecated exclude events. - Introduced include and exclude patterns. - Including everything (.*) by default, and excluding a predefined set of events by default. - Refactored EventLoggingListener to use the new include and exclude patterns. - Added tests. --- .../inception/log/EventLoggingListener.java | 3 +- .../log/config/EventLoggingProperties.java | 27 ++++++- .../config/EventLoggingPropertiesImpl.java | 79 ++++++++++-------- .../EventLoggingPropertiesImplTest.java | 81 +++++++++++++++++++ 4 files changed, 152 insertions(+), 38 deletions(-) create mode 100644 inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java index 9c016be3cd4..9e5c341e1c1 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java @@ -83,10 +83,11 @@ public void onApplicationEvent(ApplicationEvent aEvent) if (!maybeAdapter.isPresent()) { return; } + var adapter = maybeAdapter.get(); - if (properties.getExcludeEvents().contains(adapter.getEvent(aEvent))) { + if (!properties.shouldLogEvent(adapter.getEvent(aEvent))) { return; } diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java index 4588870bba2..3db6ea80c13 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java @@ -25,11 +25,30 @@ public interface EventLoggingProperties boolean isEnabled(); - Set getExcludeEvents(); + /** + * @return Set of regex include patterns + */ + Set getIncludePatterns(); + + /** + * @param includePatterns Set of regex include patterns + */ + void setIncludePatterns(Set includePatterns); + + /** + * @return Set of regex exclude patterns + */ + Set getExcludePatterns(); + + /** + * @param excludePatterns Set of regex exclude patterns + */ + void setExcludePatterns(Set excludePatterns); /** - * @param aExcludeEvents - * events never to be written to the event log. + * @param eventName Name of the event to check. + * @return true if the event should be logged, false otherwise. */ - void setExcludeEvents(Set aExcludeEvents); + boolean shouldLogEvent(String eventName); } + diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java index 739b7348f35..d792537c2ac 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java @@ -18,6 +18,7 @@ package de.tudarmstadt.ukp.inception.log.config; import java.util.Set; +import java.util.regex.Pattern; import org.springframework.boot.availability.AvailabilityChangeEvent; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -27,42 +28,54 @@ import de.tudarmstadt.ukp.inception.documents.event.AfterCasWrittenEvent; @ConfigurationProperties("event-logging") -public class EventLoggingPropertiesImpl - implements EventLoggingProperties -{ - private boolean enabled; +public class EventLoggingPropertiesImpl implements EventLoggingProperties { + private boolean enabled; - private Set excludeEvents = Set.of( // - // Do not log this by default - hardly any information value - AfterCasWrittenEvent.class.getSimpleName(), // - AvailabilityChangeEvent.class.getSimpleName(), // - "RecommenderTaskNotificationEvent", // - BeforeDocumentOpenedEvent.class.getSimpleName(), // - PreparingToOpenDocumentEvent.class.getSimpleName(), // - "BrokerAvailabilityEvent", // - "ShutdownDialogAvailableEvent"); + private Set includePatterns = Set.of(".*"); // Default include everything + + private Set excludePatterns = Set.of( + AfterCasWrittenEvent.class.getSimpleName(), + AvailabilityChangeEvent.class.getSimpleName(), + "RecommenderTaskNotificationEvent", + BeforeDocumentOpenedEvent.class.getSimpleName(), + PreparingToOpenDocumentEvent.class.getSimpleName(), + "BrokerAvailabilityEvent", + "ShutdownDialogAvailableEvent"); - @Override - public boolean isEnabled() - { - return enabled; - } + @Override + public boolean isEnabled() { + return enabled; + } - @Override - public void setEnabled(boolean aEnabled) - { - enabled = aEnabled; - } + @Override + public void setEnabled(boolean aEnabled) { + enabled = aEnabled; + } - @Override - public Set getExcludeEvents() - { - return excludeEvents; - } + @Override + public Set getIncludePatterns() { + return includePatterns; + } + + @Override + public void setIncludePatterns(Set includePatterns) { + this.includePatterns = includePatterns; + } + + @Override + public Set getExcludePatterns() { + return excludePatterns; + } + + @Override + public void setExcludePatterns(Set excludePatterns) { + this.excludePatterns = excludePatterns; + } + + @Override + public boolean shouldLogEvent(String eventName) { + return includePatterns.stream().anyMatch(pattern -> Pattern.matches(pattern, eventName)) + && excludePatterns.stream().noneMatch(pattern -> Pattern.matches(pattern, eventName)); + } - @Override - public void setExcludeEvents(Set aExcludeEvents) - { - excludeEvents = aExcludeEvents; - } } diff --git a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java new file mode 100644 index 00000000000..e099d114eaf --- /dev/null +++ b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java @@ -0,0 +1,81 @@ +package de.tudarmstadt.ukp.inception.log.config; + +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.availability.AvailabilityChangeEvent; + +import de.tudarmstadt.ukp.inception.annotation.events.BeforeDocumentOpenedEvent; +import de.tudarmstadt.ukp.inception.annotation.events.PreparingToOpenDocumentEvent; +import de.tudarmstadt.ukp.inception.documents.event.AfterCasWrittenEvent; + +import java.util.Set; + +class EventLoggingPropertiesImplTest { + + private EventLoggingPropertiesImpl properties; + + @BeforeEach + public void setUp() { + properties = new EventLoggingPropertiesImpl(); + } + + @Test + public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() { + // Test events + String eventAfterCasWritten = AfterCasWrittenEvent.class.getSimpleName(); + String eventAvailabilityChange = AvailabilityChangeEvent.class.getSimpleName(); + String eventRecommenderTaskNotification = "RecommenderTaskNotificationEvent"; + String eventBeforeDocumentOpened = BeforeDocumentOpenedEvent.class.getSimpleName(); + String eventPreparingToOpenDocument = PreparingToOpenDocumentEvent.class.getSimpleName(); + String eventBrokerAvailability = "BrokerAvailabilityEvent"; + String eventShutdownDialogAvailable = "ShutdownDialogAvailableEvent"; + + + // Assert + assertThat(properties.shouldLogEvent(eventAfterCasWritten)).isFalse(); + assertThat(properties.shouldLogEvent(eventAvailabilityChange)).isFalse(); + assertThat(properties.shouldLogEvent(eventRecommenderTaskNotification)).isFalse(); + assertThat(properties.shouldLogEvent(eventBeforeDocumentOpened)).isFalse(); + assertThat(properties.shouldLogEvent(eventPreparingToOpenDocument)).isFalse(); + assertThat(properties.shouldLogEvent(eventBrokerAvailability)).isFalse(); + assertThat(properties.shouldLogEvent(eventShutdownDialogAvailable)).isFalse(); + } + + @Test + public void shouldLogEvent_EventNotInExcludeLists_ReturnsTrue() { + // Test events + String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; + + // Assert + assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); + } + + @Test + public void shouldLogEvent_setExcludeWorksAndEventsGetExcludedTrue() { + // Set exclude patterns + properties.setExcludePatterns(Set.of("AfterDocumentOpenedEvent")); + + // Test events + String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; + + // Assert + assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isFalse(); + } + + @Test + public void shouldLogEvent_setIncludeWorksAndOnlyEventsSetIncludedWork() { + // Set include patterns + properties.setIncludePatterns(Set.of("AfterDocumentOpenedEvent")); + + // Test events + String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; + String eventDocumentStateChanged = "DocumentStateChangedEvent"; + + // Assert + assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); + assertThat(properties.shouldLogEvent(eventDocumentStateChanged)).isFalse(); + } + + +} From 83411cb964fd60c5b9471ba538c1b52779cbcbda Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Thu, 1 Feb 2024 17:03:42 +0100 Subject: [PATCH 02/11] #4377 - Configure include and exclude patterns for logged events - Added missing license header --- .../EventLoggingPropertiesImplTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java index e099d114eaf..b0189cfcb76 100644 --- a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java +++ b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Technische Universität Darmstadt under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The Technische Universität Darmstadt + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. + * + * 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 de.tudarmstadt.ukp.inception.log.config; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +48,7 @@ public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() { String eventBrokerAvailability = "BrokerAvailabilityEvent"; String eventShutdownDialogAvailable = "ShutdownDialogAvailableEvent"; - + // Assert assertThat(properties.shouldLogEvent(eventAfterCasWritten)).isFalse(); assertThat(properties.shouldLogEvent(eventAvailabilityChange)).isFalse(); From 0eaa21df27b33d3d6675e6239ae83c12b4078721 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Fri, 2 Feb 2024 11:21:34 +0100 Subject: [PATCH 03/11] #4377 - Configure include and exclude patterns for logged events - Auto-format --- .../inception/log/EventLoggingListener.java | 1 - .../log/config/EventLoggingProperties.java | 10 ++- .../config/EventLoggingPropertiesImpl.java | 88 ++++++++++--------- .../EventLoggingPropertiesImplTest.java | 47 +++++----- 4 files changed, 79 insertions(+), 67 deletions(-) diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java index 9e5c341e1c1..18321ddb427 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java @@ -83,7 +83,6 @@ public void onApplicationEvent(ApplicationEvent aEvent) if (!maybeAdapter.isPresent()) { return; } - var adapter = maybeAdapter.get(); diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java index 3db6ea80c13..38112aceb4c 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java @@ -31,7 +31,8 @@ public interface EventLoggingProperties Set getIncludePatterns(); /** - * @param includePatterns Set of regex include patterns + * @param includePatterns + * Set of regex include patterns */ void setIncludePatterns(Set includePatterns); @@ -41,14 +42,15 @@ public interface EventLoggingProperties Set getExcludePatterns(); /** - * @param excludePatterns Set of regex exclude patterns + * @param excludePatterns + * Set of regex exclude patterns */ void setExcludePatterns(Set excludePatterns); /** - * @param eventName Name of the event to check. + * @param eventName + * Name of the event to check. * @return true if the event should be logged, false otherwise. */ boolean shouldLogEvent(String eventName); } - diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java index d792537c2ac..88e9572a5fd 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java @@ -28,54 +28,60 @@ import de.tudarmstadt.ukp.inception.documents.event.AfterCasWrittenEvent; @ConfigurationProperties("event-logging") -public class EventLoggingPropertiesImpl implements EventLoggingProperties { - private boolean enabled; +public class EventLoggingPropertiesImpl + implements EventLoggingProperties +{ + private boolean enabled; - private Set includePatterns = Set.of(".*"); // Default include everything - - private Set excludePatterns = Set.of( - AfterCasWrittenEvent.class.getSimpleName(), - AvailabilityChangeEvent.class.getSimpleName(), - "RecommenderTaskNotificationEvent", - BeforeDocumentOpenedEvent.class.getSimpleName(), - PreparingToOpenDocumentEvent.class.getSimpleName(), - "BrokerAvailabilityEvent", - "ShutdownDialogAvailableEvent"); + private Set includePatterns = Set.of(".*"); // Default include everything - @Override - public boolean isEnabled() { - return enabled; - } + private Set excludePatterns = Set.of(AfterCasWrittenEvent.class.getSimpleName(), + AvailabilityChangeEvent.class.getSimpleName(), "RecommenderTaskNotificationEvent", + BeforeDocumentOpenedEvent.class.getSimpleName(), + PreparingToOpenDocumentEvent.class.getSimpleName(), "BrokerAvailabilityEvent", + "ShutdownDialogAvailableEvent"); - @Override - public void setEnabled(boolean aEnabled) { - enabled = aEnabled; - } + @Override + public boolean isEnabled() + { + return enabled; + } - @Override - public Set getIncludePatterns() { - return includePatterns; - } + @Override + public void setEnabled(boolean aEnabled) + { + enabled = aEnabled; + } - @Override - public void setIncludePatterns(Set includePatterns) { - this.includePatterns = includePatterns; - } + @Override + public Set getIncludePatterns() + { + return includePatterns; + } - @Override - public Set getExcludePatterns() { - return excludePatterns; - } + @Override + public void setIncludePatterns(Set includePatterns) + { + this.includePatterns = includePatterns; + } - @Override - public void setExcludePatterns(Set excludePatterns) { - this.excludePatterns = excludePatterns; - } + @Override + public Set getExcludePatterns() + { + return excludePatterns; + } - @Override - public boolean shouldLogEvent(String eventName) { - return includePatterns.stream().anyMatch(pattern -> Pattern.matches(pattern, eventName)) - && excludePatterns.stream().noneMatch(pattern -> Pattern.matches(pattern, eventName)); - } + @Override + public void setExcludePatterns(Set excludePatterns) + { + this.excludePatterns = excludePatterns; + } + @Override + public boolean shouldLogEvent(String eventName) + { + return includePatterns.stream().anyMatch(pattern -> Pattern.matches(pattern, eventName)) + && excludePatterns.stream() + .noneMatch(pattern -> Pattern.matches(pattern, eventName)); + } } diff --git a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java index b0189cfcb76..e0aec7576e2 100644 --- a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java +++ b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java @@ -18,6 +18,9 @@ package de.tudarmstadt.ukp.inception.log.config; import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Set; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.availability.AvailabilityChangeEvent; @@ -26,29 +29,29 @@ import de.tudarmstadt.ukp.inception.annotation.events.PreparingToOpenDocumentEvent; import de.tudarmstadt.ukp.inception.documents.event.AfterCasWrittenEvent; -import java.util.Set; +class EventLoggingPropertiesImplTest +{ -class EventLoggingPropertiesImplTest { - private EventLoggingPropertiesImpl properties; @BeforeEach - public void setUp() { + public void setUp() + { properties = new EventLoggingPropertiesImpl(); } @Test - public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() { + public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() + { // Test events - String eventAfterCasWritten = AfterCasWrittenEvent.class.getSimpleName(); - String eventAvailabilityChange = AvailabilityChangeEvent.class.getSimpleName(); - String eventRecommenderTaskNotification = "RecommenderTaskNotificationEvent"; - String eventBeforeDocumentOpened = BeforeDocumentOpenedEvent.class.getSimpleName(); - String eventPreparingToOpenDocument = PreparingToOpenDocumentEvent.class.getSimpleName(); - String eventBrokerAvailability = "BrokerAvailabilityEvent"; - String eventShutdownDialogAvailable = "ShutdownDialogAvailableEvent"; - - + String eventAfterCasWritten = AfterCasWrittenEvent.class.getSimpleName(); + String eventAvailabilityChange = AvailabilityChangeEvent.class.getSimpleName(); + String eventRecommenderTaskNotification = "RecommenderTaskNotificationEvent"; + String eventBeforeDocumentOpened = BeforeDocumentOpenedEvent.class.getSimpleName(); + String eventPreparingToOpenDocument = PreparingToOpenDocumentEvent.class.getSimpleName(); + String eventBrokerAvailability = "BrokerAvailabilityEvent"; + String eventShutdownDialogAvailable = "ShutdownDialogAvailableEvent"; + // Assert assertThat(properties.shouldLogEvent(eventAfterCasWritten)).isFalse(); assertThat(properties.shouldLogEvent(eventAvailabilityChange)).isFalse(); @@ -58,18 +61,20 @@ public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() { assertThat(properties.shouldLogEvent(eventBrokerAvailability)).isFalse(); assertThat(properties.shouldLogEvent(eventShutdownDialogAvailable)).isFalse(); } - + @Test - public void shouldLogEvent_EventNotInExcludeLists_ReturnsTrue() { + public void shouldLogEvent_EventNotInExcludeLists_ReturnsTrue() + { // Test events String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; // Assert assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); } - + @Test - public void shouldLogEvent_setExcludeWorksAndEventsGetExcludedTrue() { + public void shouldLogEvent_setExcludeWorksAndEventsGetExcludedTrue() + { // Set exclude patterns properties.setExcludePatterns(Set.of("AfterDocumentOpenedEvent")); @@ -79,9 +84,10 @@ public void shouldLogEvent_setExcludeWorksAndEventsGetExcludedTrue() { // Assert assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isFalse(); } - + @Test - public void shouldLogEvent_setIncludeWorksAndOnlyEventsSetIncludedWork() { + public void shouldLogEvent_setIncludeWorksAndOnlyEventsSetIncludedWork() + { // Set include patterns properties.setIncludePatterns(Set.of("AfterDocumentOpenedEvent")); @@ -94,5 +100,4 @@ public void shouldLogEvent_setIncludeWorksAndOnlyEventsSetIncludedWork() { assertThat(properties.shouldLogEvent(eventDocumentStateChanged)).isFalse(); } - } From f5bb6776fd8f4b2f9a1bef6389aed46f08a06c62 Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Fri, 2 Feb 2024 19:43:33 +0100 Subject: [PATCH 04/11] #4377 - Configure include and exclude patterns for logged events - Fixed parameter name. --- .../ukp/inception/log/config/EventLoggingPropertiesImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java index 88e9572a5fd..103e371e917 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java @@ -60,9 +60,9 @@ public Set getIncludePatterns() } @Override - public void setIncludePatterns(Set includePatterns) + public void setIncludePatterns(Set aIncludePatterns) { - this.includePatterns = includePatterns; + this.includePatterns = aIncludePatterns; } @Override From edc0efad1dd70f4a16344b985144a686ac1d1973 Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Fri, 2 Feb 2024 19:55:55 +0100 Subject: [PATCH 05/11] #4377 - Configure include and exclude patterns for logged events - Optimized event name logging with pattern caching to avoid repetitive pattern processing. --- .../config/EventLoggingPropertiesImpl.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java index 103e371e917..43c22e4ce82 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java @@ -17,6 +17,8 @@ */ package de.tudarmstadt.ukp.inception.log.config; +import java.util.HashMap; +import java.util.Map; import java.util.Set; import java.util.regex.Pattern; @@ -33,6 +35,8 @@ public class EventLoggingPropertiesImpl { private boolean enabled; + private Map eventCache = new HashMap<>(); + private Set includePatterns = Set.of(".*"); // Default include everything private Set excludePatterns = Set.of(AfterCasWrittenEvent.class.getSimpleName(), @@ -78,10 +82,26 @@ public void setExcludePatterns(Set excludePatterns) } @Override - public boolean shouldLogEvent(String eventName) + public boolean shouldLogEvent(String aEventName) { - return includePatterns.stream().anyMatch(pattern -> Pattern.matches(pattern, eventName)) - && excludePatterns.stream() - .noneMatch(pattern -> Pattern.matches(pattern, eventName)); + if (eventCache.containsKey(aEventName)) { + return eventCache.get(aEventName); + } + + boolean shouldLog = false; + + if (includePatterns != null && !includePatterns.isEmpty()) { + shouldLog = includePatterns.stream() + .anyMatch(pattern -> Pattern.matches(pattern, aEventName)); + } + + if (shouldLog && excludePatterns != null && !excludePatterns.isEmpty()) { + shouldLog = excludePatterns.stream() + .noneMatch(pattern -> Pattern.matches(pattern, aEventName)); + } + + eventCache.put(aEventName, shouldLog); + + return shouldLog; } } From 04a2920883e3a6dd4eeb4e905c88ad74b250eb69 Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Fri, 2 Feb 2024 20:01:19 +0100 Subject: [PATCH 06/11] #4377 - Configure include and exclude patterns for logged events - Added assertion to check that event not in exclude list. --- .../ukp/inception/log/config/EventLoggingPropertiesImplTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java index e0aec7576e2..a03c4f44e9a 100644 --- a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java +++ b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java @@ -70,6 +70,7 @@ public void shouldLogEvent_EventNotInExcludeLists_ReturnsTrue() // Assert assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); + assertThat(properties.getExcludePatterns()).doesNotContain(eventAfterDocumentOpened); } @Test From f227ab94d9fe258c5b9412e28a424b246416730f Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Fri, 2 Feb 2024 20:12:21 +0100 Subject: [PATCH 07/11] #4377 - Configure include and exclude patterns for logged events - Fixed parameter name. --- .../ukp/inception/log/config/EventLoggingPropertiesImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java index 43c22e4ce82..6e15f9014ba 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java @@ -76,9 +76,9 @@ public Set getExcludePatterns() } @Override - public void setExcludePatterns(Set excludePatterns) + public void setExcludePatterns(Set aExcludePatterns) { - this.excludePatterns = excludePatterns; + this.excludePatterns = aExcludePatterns; } @Override From f6c8ded0365b3865a895ff162d89621fcc3b5ac2 Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Fri, 2 Feb 2024 20:49:09 +0100 Subject: [PATCH 08/11] #4377 - Configure include and exclude patterns for logged events - Moved shouldLogEvent to EventLoggingListener as a package-private method to keep EventLoggingProperties a data class. --- .../inception/log/EventLoggingListener.java | 31 ++++++++++++++++++- .../log/config/EventLoggingProperties.java | 7 ----- .../config/EventLoggingPropertiesImpl.java | 29 ----------------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java index 18321ddb427..2d6e4088d16 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java @@ -20,10 +20,13 @@ import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Deque; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +58,8 @@ public class EventLoggingListener private final EventLoggingProperties properties; private final EventLoggingAdapterRegistry adapterRegistry; + private Map eventCache = new HashMap<>(); + private volatile boolean flushing = false; @Autowired @@ -71,6 +76,30 @@ public EventLoggingListener(EventRepository aRepo, EventLoggingProperties aPrope scheduler.scheduleAtFixedRate(() -> flush(), 1, 1, TimeUnit.SECONDS); } + boolean shouldLogEvent(String aEventName) + { + if (eventCache.containsKey(aEventName)) { + return eventCache.get(aEventName); + } + + boolean shouldLog = false; + + if (properties.getIncludePatterns() != null && !properties.getIncludePatterns().isEmpty()) { + shouldLog = properties.getIncludePatterns().stream() + .anyMatch(pattern -> Pattern.matches(pattern, aEventName)); + } + + if (shouldLog && properties.getExcludePatterns() != null + && !properties.getExcludePatterns().isEmpty()) { + shouldLog = properties.getExcludePatterns().stream() + .noneMatch(pattern -> Pattern.matches(pattern, aEventName)); + } + + eventCache.put(aEventName, shouldLog); + + return shouldLog; + } + @EventListener public void onApplicationEvent(ApplicationEvent aEvent) { @@ -86,7 +115,7 @@ public void onApplicationEvent(ApplicationEvent aEvent) var adapter = maybeAdapter.get(); - if (!properties.shouldLogEvent(adapter.getEvent(aEvent))) { + if (!shouldLogEvent(adapter.getEvent(aEvent))) { return; } diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java index 38112aceb4c..09c77446c7a 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingProperties.java @@ -46,11 +46,4 @@ public interface EventLoggingProperties * Set of regex exclude patterns */ void setExcludePatterns(Set excludePatterns); - - /** - * @param eventName - * Name of the event to check. - * @return true if the event should be logged, false otherwise. - */ - boolean shouldLogEvent(String eventName); } diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java index 6e15f9014ba..b397121fd0f 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java @@ -17,10 +17,7 @@ */ package de.tudarmstadt.ukp.inception.log.config; -import java.util.HashMap; -import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import org.springframework.boot.availability.AvailabilityChangeEvent; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -35,8 +32,6 @@ public class EventLoggingPropertiesImpl { private boolean enabled; - private Map eventCache = new HashMap<>(); - private Set includePatterns = Set.of(".*"); // Default include everything private Set excludePatterns = Set.of(AfterCasWrittenEvent.class.getSimpleName(), @@ -80,28 +75,4 @@ public void setExcludePatterns(Set aExcludePatterns) { this.excludePatterns = aExcludePatterns; } - - @Override - public boolean shouldLogEvent(String aEventName) - { - if (eventCache.containsKey(aEventName)) { - return eventCache.get(aEventName); - } - - boolean shouldLog = false; - - if (includePatterns != null && !includePatterns.isEmpty()) { - shouldLog = includePatterns.stream() - .anyMatch(pattern -> Pattern.matches(pattern, aEventName)); - } - - if (shouldLog && excludePatterns != null && !excludePatterns.isEmpty()) { - shouldLog = excludePatterns.stream() - .noneMatch(pattern -> Pattern.matches(pattern, aEventName)); - } - - eventCache.put(aEventName, shouldLog); - - return shouldLog; - } } From 0c75960ccdd7647964aa078471c45f3b2d14a846 Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Fri, 2 Feb 2024 20:50:26 +0100 Subject: [PATCH 09/11] #4377 - Configure include and exclude patterns for logged events - Removed unit test for EventLoggingPropertiesImplTest. - Added unit test for EventLoggingListenerTest to test shouldLogEvent method. --- ...est.java => EventLoggingListenerTest.java} | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) rename inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/{config/EventLoggingPropertiesImplTest.java => EventLoggingListenerTest.java} (50%) diff --git a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java similarity index 50% rename from inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java rename to inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java index a03c4f44e9a..b8bbb41b284 100644 --- a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImplTest.java +++ b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java @@ -1,21 +1,4 @@ -/* - * Licensed to the Technische Universität Darmstadt under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The Technische Universität Darmstadt - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. - * - * 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 de.tudarmstadt.ukp.inception.log.config; +package de.tudarmstadt.ukp.inception.log; import static org.assertj.core.api.Assertions.assertThat; @@ -28,22 +11,24 @@ import de.tudarmstadt.ukp.inception.annotation.events.BeforeDocumentOpenedEvent; import de.tudarmstadt.ukp.inception.annotation.events.PreparingToOpenDocumentEvent; import de.tudarmstadt.ukp.inception.documents.event.AfterCasWrittenEvent; +import de.tudarmstadt.ukp.inception.log.config.EventLoggingPropertiesImpl; -class EventLoggingPropertiesImplTest +class EventLoggingListenerTest { + private EventLoggingListener listener; private EventLoggingPropertiesImpl properties; @BeforeEach - public void setUp() + void setUp() throws Exception { properties = new EventLoggingPropertiesImpl(); + listener = new EventLoggingListener(null, properties, null); } @Test public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() { - // Test events String eventAfterCasWritten = AfterCasWrittenEvent.class.getSimpleName(); String eventAvailabilityChange = AvailabilityChangeEvent.class.getSimpleName(); String eventRecommenderTaskNotification = "RecommenderTaskNotificationEvent"; @@ -52,53 +37,44 @@ public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() String eventBrokerAvailability = "BrokerAvailabilityEvent"; String eventShutdownDialogAvailable = "ShutdownDialogAvailableEvent"; - // Assert - assertThat(properties.shouldLogEvent(eventAfterCasWritten)).isFalse(); - assertThat(properties.shouldLogEvent(eventAvailabilityChange)).isFalse(); - assertThat(properties.shouldLogEvent(eventRecommenderTaskNotification)).isFalse(); - assertThat(properties.shouldLogEvent(eventBeforeDocumentOpened)).isFalse(); - assertThat(properties.shouldLogEvent(eventPreparingToOpenDocument)).isFalse(); - assertThat(properties.shouldLogEvent(eventBrokerAvailability)).isFalse(); - assertThat(properties.shouldLogEvent(eventShutdownDialogAvailable)).isFalse(); + assertThat(listener.shouldLogEvent(eventAfterCasWritten)).isFalse(); + assertThat(listener.shouldLogEvent(eventAvailabilityChange)).isFalse(); + assertThat(listener.shouldLogEvent(eventRecommenderTaskNotification)).isFalse(); + assertThat(listener.shouldLogEvent(eventBeforeDocumentOpened)).isFalse(); + assertThat(listener.shouldLogEvent(eventPreparingToOpenDocument)).isFalse(); + assertThat(listener.shouldLogEvent(eventBrokerAvailability)).isFalse(); + assertThat(listener.shouldLogEvent(eventShutdownDialogAvailable)).isFalse(); } @Test public void shouldLogEvent_EventNotInExcludeLists_ReturnsTrue() { - // Test events String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; - // Assert - assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); + assertThat(listener.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); assertThat(properties.getExcludePatterns()).doesNotContain(eventAfterDocumentOpened); } @Test public void shouldLogEvent_setExcludeWorksAndEventsGetExcludedTrue() { - // Set exclude patterns properties.setExcludePatterns(Set.of("AfterDocumentOpenedEvent")); - // Test events String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; - // Assert - assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isFalse(); + assertThat(listener.shouldLogEvent(eventAfterDocumentOpened)).isFalse(); } @Test public void shouldLogEvent_setIncludeWorksAndOnlyEventsSetIncludedWork() { - // Set include patterns properties.setIncludePatterns(Set.of("AfterDocumentOpenedEvent")); - // Test events String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; String eventDocumentStateChanged = "DocumentStateChangedEvent"; - // Assert - assertThat(properties.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); - assertThat(properties.shouldLogEvent(eventDocumentStateChanged)).isFalse(); + assertThat(listener.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); + assertThat(listener.shouldLogEvent(eventDocumentStateChanged)).isFalse(); } } From 05eed48eef75d65e81020dd597b22d5215b2e876 Mon Sep 17 00:00:00 2001 From: Serwar Basch Date: Fri, 2 Feb 2024 20:59:51 +0100 Subject: [PATCH 10/11] #4377 - Configure include and exclude patterns for logged events - Added missing license header --- .../inception/log/EventLoggingListenerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java index b8bbb41b284..7c1c1d52668 100644 --- a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java +++ b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Technische Universität Darmstadt under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The Technische Universität Darmstadt + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. + * + * 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 de.tudarmstadt.ukp.inception.log; import static org.assertj.core.api.Assertions.assertThat; From 32d3104b83d81a37464e3caeb73a9c814de7b4ce Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Sun, 4 Feb 2024 21:25:15 +0100 Subject: [PATCH 11/11] #4377 - Configure include and exclude patterns for logged events - Treat an empty include patterns set as "include all" - Bit of cleaning up --- .../inception/log/EventLoggingListener.java | 11 +++-- .../config/EventLoggingPropertiesImpl.java | 14 +++--- .../log/EventLoggingListenerTest.java | 44 ++++++++----------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java index 2d6e4088d16..53ef44335e1 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/EventLoggingListener.java @@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; +import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; @@ -82,15 +83,17 @@ boolean shouldLogEvent(String aEventName) return eventCache.get(aEventName); } - boolean shouldLog = false; + boolean shouldLog; - if (properties.getIncludePatterns() != null && !properties.getIncludePatterns().isEmpty()) { + if (CollectionUtils.isEmpty(properties.getIncludePatterns())) { + shouldLog = true; + } + else { shouldLog = properties.getIncludePatterns().stream() .anyMatch(pattern -> Pattern.matches(pattern, aEventName)); } - if (shouldLog && properties.getExcludePatterns() != null - && !properties.getExcludePatterns().isEmpty()) { + if (shouldLog && !CollectionUtils.isEmpty(properties.getExcludePatterns())) { shouldLog = properties.getExcludePatterns().stream() .noneMatch(pattern -> Pattern.matches(pattern, aEventName)); } diff --git a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java index b397121fd0f..85cd86ed141 100644 --- a/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java +++ b/inception/inception-log/src/main/java/de/tudarmstadt/ukp/inception/log/config/EventLoggingPropertiesImpl.java @@ -17,6 +17,7 @@ */ package de.tudarmstadt.ukp.inception.log.config; +import java.util.Collections; import java.util.Set; import org.springframework.boot.availability.AvailabilityChangeEvent; @@ -32,12 +33,15 @@ public class EventLoggingPropertiesImpl { private boolean enabled; - private Set includePatterns = Set.of(".*"); // Default include everything + private Set includePatterns = Collections.emptySet(); // Default include everything - private Set excludePatterns = Set.of(AfterCasWrittenEvent.class.getSimpleName(), - AvailabilityChangeEvent.class.getSimpleName(), "RecommenderTaskNotificationEvent", - BeforeDocumentOpenedEvent.class.getSimpleName(), - PreparingToOpenDocumentEvent.class.getSimpleName(), "BrokerAvailabilityEvent", + private Set excludePatterns = Set.of( // + AfterCasWrittenEvent.class.getSimpleName(), // + AvailabilityChangeEvent.class.getSimpleName(), // + "RecommenderTaskNotificationEvent", // + BeforeDocumentOpenedEvent.class.getSimpleName(), // + PreparingToOpenDocumentEvent.class.getSimpleName(), // + "BrokerAvailabilityEvent", // "ShutdownDialogAvailableEvent"); @Override diff --git a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java index 7c1c1d52668..fbb0f3951e7 100644 --- a/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java +++ b/inception/inception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java @@ -46,27 +46,22 @@ void setUp() throws Exception @Test public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() { - String eventAfterCasWritten = AfterCasWrittenEvent.class.getSimpleName(); - String eventAvailabilityChange = AvailabilityChangeEvent.class.getSimpleName(); - String eventRecommenderTaskNotification = "RecommenderTaskNotificationEvent"; - String eventBeforeDocumentOpened = BeforeDocumentOpenedEvent.class.getSimpleName(); - String eventPreparingToOpenDocument = PreparingToOpenDocumentEvent.class.getSimpleName(); - String eventBrokerAvailability = "BrokerAvailabilityEvent"; - String eventShutdownDialogAvailable = "ShutdownDialogAvailableEvent"; - - assertThat(listener.shouldLogEvent(eventAfterCasWritten)).isFalse(); - assertThat(listener.shouldLogEvent(eventAvailabilityChange)).isFalse(); - assertThat(listener.shouldLogEvent(eventRecommenderTaskNotification)).isFalse(); - assertThat(listener.shouldLogEvent(eventBeforeDocumentOpened)).isFalse(); - assertThat(listener.shouldLogEvent(eventPreparingToOpenDocument)).isFalse(); - assertThat(listener.shouldLogEvent(eventBrokerAvailability)).isFalse(); - assertThat(listener.shouldLogEvent(eventShutdownDialogAvailable)).isFalse(); + assertThat(listener.shouldLogEvent(AfterCasWrittenEvent.class.getSimpleName())).isFalse(); + assertThat(listener.shouldLogEvent(AvailabilityChangeEvent.class.getSimpleName())) + .isFalse(); + assertThat(listener.shouldLogEvent("RecommenderTaskNotificationEvent")).isFalse(); + assertThat(listener.shouldLogEvent(BeforeDocumentOpenedEvent.class.getSimpleName())) + .isFalse(); + assertThat(listener.shouldLogEvent(PreparingToOpenDocumentEvent.class.getSimpleName())) + .isFalse(); + assertThat(listener.shouldLogEvent("BrokerAvailabilityEvent")).isFalse(); + assertThat(listener.shouldLogEvent("ShutdownDialogAvailableEvent")).isFalse(); } @Test public void shouldLogEvent_EventNotInExcludeLists_ReturnsTrue() { - String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; + var eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; assertThat(listener.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); assertThat(properties.getExcludePatterns()).doesNotContain(eventAfterDocumentOpened); @@ -75,23 +70,22 @@ public void shouldLogEvent_EventNotInExcludeLists_ReturnsTrue() @Test public void shouldLogEvent_setExcludeWorksAndEventsGetExcludedTrue() { - properties.setExcludePatterns(Set.of("AfterDocumentOpenedEvent")); + var excludedEvent = "ExcludedEvent"; - String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; + properties.setExcludePatterns(Set.of(excludedEvent)); - assertThat(listener.shouldLogEvent(eventAfterDocumentOpened)).isFalse(); + assertThat(listener.shouldLogEvent(excludedEvent)).isFalse(); } @Test public void shouldLogEvent_setIncludeWorksAndOnlyEventsSetIncludedWork() { - properties.setIncludePatterns(Set.of("AfterDocumentOpenedEvent")); + var includedEvent = "IncludedEvent"; + var notIncludedEvent = "NotIncludedEvent"; - String eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; - String eventDocumentStateChanged = "DocumentStateChangedEvent"; + properties.setIncludePatterns(Set.of(includedEvent)); - assertThat(listener.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); - assertThat(listener.shouldLogEvent(eventDocumentStateChanged)).isFalse(); + assertThat(listener.shouldLogEvent(includedEvent)).isTrue(); + assertThat(listener.shouldLogEvent(notIncludedEvent)).isFalse(); } - }