Skip to content

Commit ad598dc

Browse files
marevolclaude
andauthored
test: Add integration test for DELETE /api/admin/crawlinginfo/all endpoint (#2942)
Add test coverage for the crawlinginfo bulk deletion endpoint that was previously untested. The new test verifies that DELETE /api/admin/crawlinginfo/all successfully deletes all old crawling sessions except currently running ones. Changes: - Add crawlingInfoDeleteAllTest() test method with @order(3) annotation - Add testDeleteAllCrawlingInfo() implementation that: * Reads crawling info logs before deletion (if any exist) * Calls DELETE /api/admin/crawlinginfo/all endpoint * Confirms all old sessions are deleted (result should be 0) * Works correctly even if logs were already deleted by previous tests - Add @TestMethodOrder annotation to ensure proper test execution order - Import necessary JUnit OrderAnnotation classes Test execution order: 1. jobLogTest() - Job log CRUD operations 2. crawlingInfoTest() - Individual crawling info operations 3. crawlingInfoDeleteAllTest() - Bulk deletion (NEW) 4. failureUrlTest() - Failure URL operations 5. searchListTest() - Search list operations This test follows the existing pattern in CrawlerLogTests.java and uses the same testing approach as other admin API integration tests. Resolves #1016 Co-authored-by: Claude <[email protected]>
1 parent e102b54 commit ad598dc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/test/java/org/codelibs/fess/it/admin/CrawlerLogTests.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
import org.junit.jupiter.api.AfterEach;
3232
import org.junit.jupiter.api.BeforeAll;
3333
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.MethodOrderer;
35+
import org.junit.jupiter.api.Order;
3436
import org.junit.jupiter.api.Tag;
3537
import org.junit.jupiter.api.Test;
38+
import org.junit.jupiter.api.TestMethodOrder;
3639

3740
import io.restassured.RestAssured;
3841
import io.restassured.path.json.JsonPath;
@@ -45,6 +48,7 @@
4548
* - /api/admin/searchlist
4649
* */
4750
@Tag("it")
51+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
4852
public class CrawlerLogTests extends CrawlTestBase {
4953
private static final Logger logger = LogManager.getLogger(CrawlerLogTests.class);
5054

@@ -116,27 +120,38 @@ protected static void tearDownAll() {
116120
}
117121

118122
@Test
123+
@Order(1)
119124
void jobLogTest() {
120125
logger.info("start jobLogTest");
121126
testReadJobLog();
122127
testDeleteJobLog();
123128
}
124129

125130
@Test
131+
@Order(2)
126132
void crawlingInfoTest() {
127133
logger.info("start crawlingInfoTest");
128134
testReadCrawlingInfo();
129135
testDeleteCrawlingInfo();
130136
}
131137

132138
@Test
139+
@Order(3)
140+
void crawlingInfoDeleteAllTest() {
141+
logger.info("start crawlingInfoDeleteAllTest");
142+
testDeleteAllCrawlingInfo();
143+
}
144+
145+
@Test
146+
@Order(4)
133147
void failureUrlTest() {
134148
logger.info("start failureUrlTest");
135149
testReadFailureUrl();
136150
testDeleteFailureUrl();
137151
}
138152

139153
@Test
154+
@Order(5)
140155
void searchListTest() {
141156
logger.info("start searchListTest");
142157
testReadSearchList();
@@ -268,4 +283,32 @@ private List<Map<String, Object>> getSearchResults() {
268283
final List<Map<String, Object>> results = JsonPath.from(response).getList("response.docs");
269284
return results;
270285
}
286+
287+
/**
288+
* Test for DELETE /api/admin/crawlinginfo/all
289+
* This endpoint deletes all old crawling sessions except currently running ones
290+
* */
291+
private void testDeleteAllCrawlingInfo() {
292+
// Read crawling info before deletion
293+
final List<Map<String, Object>> logListBefore = readCrawlingInfo(webConfigId);
294+
logger.info("logListBefore: {}", logListBefore);
295+
final int sizeBeforeDeletion = logListBefore.size();
296+
logger.info("Number of crawling info logs before deletion: {}", sizeBeforeDeletion);
297+
298+
// Delete all old crawling sessions
299+
deleteMethod("/api/admin/crawlinginfo/all").then().body("response.status", equalTo(0));
300+
refresh();
301+
302+
// Verify all old sessions are deleted (size should be 0 after deletion)
303+
final List<Map<String, Object>> logListAfter = readCrawlingInfo(webConfigId);
304+
logger.info("logListAfter: {}", logListAfter);
305+
assertEquals(0, logListAfter.size(), "All crawling info logs should be deleted after calling delete all endpoint");
306+
307+
// Log the result
308+
if (sizeBeforeDeletion > 0) {
309+
logger.info("Successfully deleted {} crawling info log(s) using bulk delete", sizeBeforeDeletion);
310+
} else {
311+
logger.info("No crawling info logs to delete (may have been deleted by previous test)");
312+
}
313+
}
271314
}

0 commit comments

Comments
 (0)