-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4490 from inception-project/feature/4377-configur…
…e-patterns-for-logged-events #4377 - Configure include and exclude patterns for logged events
- Loading branch information
Showing
4 changed files
with
162 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...nception-log/src/test/java/de/tudarmstadt/ukp/inception/log/EventLoggingListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Set; | ||
|
||
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 de.tudarmstadt.ukp.inception.log.config.EventLoggingPropertiesImpl; | ||
|
||
class EventLoggingListenerTest | ||
{ | ||
|
||
private EventLoggingListener listener; | ||
private EventLoggingPropertiesImpl properties; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception | ||
{ | ||
properties = new EventLoggingPropertiesImpl(); | ||
listener = new EventLoggingListener(null, properties, null); | ||
} | ||
|
||
@Test | ||
public void shouldLogEvent_defaultExcludeInternalList_ReturnsFalse() | ||
{ | ||
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() | ||
{ | ||
var eventAfterDocumentOpened = "AfterDocumentOpenedEvent"; | ||
|
||
assertThat(listener.shouldLogEvent(eventAfterDocumentOpened)).isTrue(); | ||
assertThat(properties.getExcludePatterns()).doesNotContain(eventAfterDocumentOpened); | ||
} | ||
|
||
@Test | ||
public void shouldLogEvent_setExcludeWorksAndEventsGetExcludedTrue() | ||
{ | ||
var excludedEvent = "ExcludedEvent"; | ||
|
||
properties.setExcludePatterns(Set.of(excludedEvent)); | ||
|
||
assertThat(listener.shouldLogEvent(excludedEvent)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void shouldLogEvent_setIncludeWorksAndOnlyEventsSetIncludedWork() | ||
{ | ||
var includedEvent = "IncludedEvent"; | ||
var notIncludedEvent = "NotIncludedEvent"; | ||
|
||
properties.setIncludePatterns(Set.of(includedEvent)); | ||
|
||
assertThat(listener.shouldLogEvent(includedEvent)).isTrue(); | ||
assertThat(listener.shouldLogEvent(notIncludedEvent)).isFalse(); | ||
} | ||
} |