|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
5 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue; |
6 | 6 |
|
7 | | - |
| 7 | +import uk.gov.hmcts.cp.cdk.domain.Answer; |
8 | 8 | import uk.gov.hmcts.cp.cdk.domain.AnswerId; |
9 | 9 | import uk.gov.hmcts.cp.cdk.domain.CaseDocument; |
10 | | -import uk.gov.hmcts.cp.cdk.domain.Answer; |
11 | | - |
12 | | -import uk.gov.hmcts.cp.cdk.jobmanager.IngestionProperties; |
13 | 10 | import uk.gov.hmcts.cp.cdk.testsupport.AbstractHttpLiveTest; |
14 | 11 | import uk.gov.hmcts.cp.cdk.util.BrokerUtil; |
15 | 12 |
|
|
19 | 16 | import java.sql.PreparedStatement; |
20 | 17 | import java.sql.ResultSet; |
21 | 18 | import java.sql.SQLException; |
| 19 | +import java.time.Duration; |
22 | 20 | import java.time.OffsetDateTime; |
23 | 21 | import java.util.List; |
24 | | - |
25 | 22 | import java.util.UUID; |
26 | 23 |
|
| 24 | +import org.awaitility.Awaitility; |
27 | 25 | import org.junit.jupiter.api.BeforeAll; |
28 | 26 | import org.junit.jupiter.api.Test; |
29 | 27 | import org.junit.jupiter.api.TestInstance; |
30 | | -import org.springframework.beans.factory.annotation.Autowired; |
31 | | -import org.springframework.boot.test.context.SpringBootTest; |
32 | 28 | import org.springframework.http.HttpEntity; |
33 | 29 | import org.springframework.http.HttpHeaders; |
34 | 30 | import org.springframework.http.HttpMethod; |
35 | 31 | import org.springframework.http.HttpStatus; |
36 | 32 | import org.springframework.http.MediaType; |
37 | 33 | import org.springframework.http.ResponseEntity; |
38 | | -import org.springframework.test.context.TestPropertySource; |
39 | 34 |
|
40 | 35 |
|
41 | 36 | /** |
@@ -282,75 +277,35 @@ void start_ingestion_process_executes_all_tasks_successfully() throws Exception |
282 | 277 | } |
283 | 278 |
|
284 | 279 | assertNotNull(auditResponse, "Expected audit event after full ingestion task chain"); |
285 | | - boolean jmenable = isJobManagerEnabled(); |
| 280 | + |
286 | 281 | Thread.sleep(60000); |
287 | | - if (jmenable) { |
288 | | - |
289 | | - // ---- CaseDocument table validation using JDBC |
290 | | - UUID caseId = UUID.fromString("2204cd6b-5759-473c-b0f7-178b3aa0c9b3"); |
291 | | - CaseDocument doc; |
292 | | - try (Connection c = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass); |
293 | | - PreparedStatement ps = c.prepareStatement( |
294 | | - "SELECT doc_id, case_id, material_id, doc_name, blob_uri, uploaded_at " + |
295 | | - "FROM case_documents " + |
296 | | - "WHERE case_id = ? " + |
297 | | - "ORDER BY uploaded_at DESC " + |
298 | | - "LIMIT 1" |
299 | | - )) { |
300 | | - ps.setObject(1, caseId); |
301 | | - try (ResultSet rs = ps.executeQuery()) { |
302 | | - assertTrue(rs.next(), "Expected at least one CaseDocument for the case"); |
303 | | - |
304 | | - doc = new CaseDocument(); |
305 | | - doc.setDocId((UUID) rs.getObject("doc_id")); |
306 | | - doc.setCaseId((UUID) rs.getObject("case_id")); |
307 | | - doc.setMaterialId((UUID) rs.getObject("material_id")); |
308 | | - doc.setDocName(rs.getString("doc_name")); |
309 | | - doc.setBlobUri(rs.getString("blob_uri")); |
310 | | - doc.setUploadedAt(rs.getObject("uploaded_at", OffsetDateTime.class)); |
311 | | - } |
312 | | - } |
| 282 | + UUID caseId = UUID.fromString("2204cd6b-5759-473c-b0f7-178b3aa0c9b3"); |
| 283 | + UUID queryId = UUID.fromString("2a9ae797-7f70-4be5-927f-2dae65489e69"); |
| 284 | + |
| 285 | + |
| 286 | + final HttpHeaders answerHeaders = new HttpHeaders(); |
| 287 | + answerHeaders.setAccept(List.of( |
| 288 | + MediaType.valueOf("application/vnd.casedocumentknowledge-service.answers+json") |
| 289 | + )); |
| 290 | + |
| 291 | + Awaitility.await() |
| 292 | + .atMost(Duration.ofSeconds(120)) |
| 293 | + .untilAsserted(() -> { |
| 294 | + |
| 295 | + ResponseEntity<String> answerResponse = http.exchange( |
| 296 | + baseUrl + "/answers/" + caseId + "/" + queryId, |
| 297 | + HttpMethod.GET, |
| 298 | + new HttpEntity<>(answerHeaders), |
| 299 | + String.class |
| 300 | + ); |
| 301 | + |
| 302 | + assertThat(answerResponse.getStatusCode()).isEqualTo(HttpStatus.OK); |
| 303 | + assertThat(answerResponse.getBody()).isNotNull(); |
| 304 | + assertThat(answerResponse.getBody()).contains("\"answer\""); |
| 305 | + assertThat(answerResponse.getBody()).contains("\"version\""); |
| 306 | + }); |
313 | 307 |
|
314 | | - assertThat(doc.getBlobUri()).isNotBlank(); |
315 | | - assertThat(doc.getDocName()).isNotBlank(); |
316 | | - assertThat(doc.getMaterialId()).isNotNull(); |
317 | | - assertThat(doc.getUploadedAt()).isNotNull(); |
318 | | - |
319 | | - // ---- Answer table validation using JDBC |
320 | | - UUID queryId = UUID.fromString("2a9ae797-7f70-4be5-927f-2dae65489e69"); |
321 | | - Answer answer; |
322 | | - |
323 | | - try (Connection c = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass); |
324 | | - PreparedStatement ps = c.prepareStatement( |
325 | | - "SELECT case_id, query_id, version, created_at, answer, doc_id " + |
326 | | - "FROM answers " + |
327 | | - "WHERE case_id = ? AND query_id = ? " + |
328 | | - "ORDER BY created_at DESC, version DESC " + |
329 | | - "LIMIT 1" |
330 | | - )) { |
331 | | - ps.setObject(1, caseId); |
332 | | - ps.setObject(2, queryId); |
333 | | - |
334 | | - try (ResultSet rs = ps.executeQuery()) { |
335 | | - assertTrue(rs.next(), "Expected at least one Answer for the case and query"); |
336 | | - |
337 | | - answer = new Answer(); |
338 | | - AnswerId answerId = new AnswerId(); |
339 | | - answerId.setCaseId((UUID) rs.getObject("case_id")); |
340 | | - answerId.setQueryId((UUID) rs.getObject("query_id")); |
341 | | - answerId.setVersion(rs.getInt("version")); |
342 | | - answer.setAnswerId(answerId); |
343 | | - |
344 | | - answer.setCreatedAt(rs.getObject("created_at", OffsetDateTime.class)); |
345 | | - answer.setAnswerText(rs.getString("answer")); |
346 | | - answer.setDocId((UUID) rs.getObject("doc_id")); |
347 | | - } |
348 | | - } |
349 | 308 |
|
350 | | - assertThat(answer.getAnswerText()).isNotBlank(); |
351 | | - assertThat(answer.getCreatedAt()).isNotNull(); |
352 | | - assertThat(answer.getDocId()).isNotNull(); |
353 | | - } |
354 | 309 | } |
355 | 310 |
|
356 | 311 |
|
|
0 commit comments