View Javadoc
1   package com.acumenvelocity.ath.integration;
2   
3   import com.fasterxml.jackson.databind.JsonNode;
4   import org.junit.jupiter.api.Test;
5   
6   import java.util.UUID;
7   
8   import static org.junit.jupiter.api.Assertions.*;
9   
10  public class TestErrorHandling_IT extends BaseIntegrationTest {
11  
12    @Test
13    public void testGetNonExistentTranslationMemory() throws Exception {
14      UUID nonExistentId = UUID.randomUUID();
15  
16      HttpResponse response = sendGetRequest(
17          "/resources/translation-memory/" + nonExistentId + "/info");
18  
19      assertEquals(404, response.getStatusCode(), "Expected HTTP 404");
20  
21      JsonNode json = parseJson(response.getBody());
22      assertTrue(json.has("code"));
23      assertEquals(404, json.get("code").asInt());
24    }
25  
26    @Test
27    public void testGetNonExistentDocument() throws Exception {
28      UUID nonExistentId = UUID.randomUUID();
29  
30      HttpResponse response = sendGetRequest("/document/" + nonExistentId + "/status");
31  
32      assertEquals(404, response.getStatusCode(), "Expected HTTP 404");
33    }
34  
35    @Test
36    public void testGetNonExistentDocumentSegment() throws Exception {
37      UUID nonExistentDocId = UUID.randomUUID();
38      UUID nonExistentSegId = UUID.randomUUID();
39  
40      HttpResponse response = sendGetRequest(
41          "/document/" + nonExistentDocId + "/segment/" + nonExistentSegId);
42  
43      assertEquals(404, response.getStatusCode(), "Expected HTTP 404");
44    }
45  
46    @Test
47    public void testGetNonExistentTmSegment() throws Exception {
48      UUID nonExistentTmId = UUID.randomUUID();
49      UUID nonExistentSegId = UUID.randomUUID();
50  
51      HttpResponse response = sendGetRequest(
52          "/resources/translation-memory/" + nonExistentTmId + "/segment/" + nonExistentSegId);
53  
54      assertEquals(404, response.getStatusCode(), "Expected HTTP 404");
55    }
56  
57    @Test
58    public void testCreateDocumentWithInvalidBody() throws Exception {
59      HttpResponse response = sendPostRequest("/document", "invalid json");
60  
61      assertTrue(response.getStatusCode() >= 400, "Expected error status code");
62    }
63  
64    @Test
65    public void testExportDocumentBeforeImportComplete() throws Exception {
66      // This would require a document in importing state
67      // For simplicity, we test with non-existent document
68      UUID docId = UUID.randomUUID();
69  
70      String requestBody = "{\"doc_out_storage_name\":\"test.txt\",\"user_id\":\"" +
71          UUID.randomUUID() + "\"}";
72  
73      HttpResponse response = sendPostRequest("/document/" + docId + "/export", requestBody);
74  
75      assertTrue(response.getStatusCode() == 404 || response.getStatusCode() == 409,
76          "Expected HTTP 404 or 409");
77    }
78  
79    @Test
80    public void testDeleteNonExistentTranslationMemory() throws Exception {
81      UUID nonExistentId = UUID.randomUUID();
82  
83      HttpResponse response = sendDeleteRequest(
84          "/resources/translation-memory/" + nonExistentId);
85  
86      assertEquals(404, response.getStatusCode(), "Expected HTTP 404");
87    }
88  
89    @Test
90    public void testDeleteNonExistentDocument() throws Exception {
91      UUID nonExistentId = UUID.randomUUID();
92  
93      HttpResponse response = sendDeleteRequest("/document/" + nonExistentId);
94  
95      assertEquals(404, response.getStatusCode(), "Expected HTTP 404");
96    }
97  }