-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTM-1258: Allow storing only one task per search index
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
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
53 changes: 53 additions & 0 deletions
53
src/test/java/org/tailormap/api/repository/events/SearchIndexEventHandlerTest.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,53 @@ | ||
/* | ||
* Copyright (C) 2024 B3Partners B.V. | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package org.tailormap.api.repository.events; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assumptions.assumingThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junitpioneer.jupiter.Issue; | ||
import org.quartz.SchedulerException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.tailormap.api.annotation.PostgresIntegrationTest; | ||
import org.tailormap.api.persistence.SearchIndex; | ||
import org.tailormap.api.repository.SearchIndexRepository; | ||
|
||
@PostgresIntegrationTest | ||
class SearchIndexEventHandlerTest { | ||
@Autowired SearchIndexEventHandler searchIndexEventHandler; | ||
@Autowired SearchIndexRepository searchIndexRepository; | ||
|
||
/** | ||
* Test that a {@code SearchIndex} with a scheduled task that already exists cannot be saved with | ||
* a new task through Spring Data REST. | ||
*/ | ||
@Test | ||
@Issue("HTM-1258") | ||
void testBeforeSaveSearchIndexEventHandler() { | ||
SearchIndex existingSearchIndexWithSchedule = searchIndexRepository.findById(1L).orElse(null); | ||
|
||
assumingThat( | ||
null != existingSearchIndexWithSchedule | ||
&& null != existingSearchIndexWithSchedule.getSchedule() | ||
&& null != existingSearchIndexWithSchedule.getSchedule().getUuid(), | ||
() -> { | ||
final Exception actual = | ||
assertThrows( | ||
SchedulerException.class, | ||
() -> { | ||
existingSearchIndexWithSchedule.getSchedule().setUuid(null); | ||
searchIndexEventHandler.beforeSaveSearchIndexEventHandler( | ||
existingSearchIndexWithSchedule); | ||
}, | ||
"Test did not invoke expected exception"); | ||
|
||
assertThat(actual.getMessage(), containsString("scheduled task already exists")); | ||
}); | ||
} | ||
} |