|
1 | 1 | package com.github.capjscommunity.sapafcsdk.scheduling.outbox; |
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
5 | 4 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
6 | 5 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
7 | 6 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
8 | 7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
9 | 8 |
|
10 | 9 | import com.github.capjscommunity.sapafcsdk.model.sapafcsdk.scheduling.JobStatusCode; |
11 | | -import com.github.capjscommunity.sapafcsdk.model.sapafcsdk.scheduling.processingservice.ProcessJobContext; |
12 | 10 | import com.github.capjscommunity.sapafcsdk.model.sapafcsdk.scheduling.processingservice.ProcessingService_; |
13 | 11 | import com.github.capjscommunity.sapafcsdk.test.OutboxTestSetup; |
14 | 12 | import com.sap.cds.services.persistence.PersistenceService; |
@@ -42,74 +40,66 @@ public class SchedulingProviderOutboxCreateTest { |
42 | 40 | @Test |
43 | 41 | @WithMockUser("authenticated") |
44 | 42 | public void createJobOutboxed() throws Exception { |
45 | | - OutboxTestSetup setup = new OutboxTestSetup( |
46 | | - ProcessingService_.CDS_NAME, |
47 | | - ProcessJobContext.CDS_NAME, |
48 | | - cdsRuntime, |
49 | | - persistenceService |
50 | | - ); |
51 | | - JSONObject job = new JSONObject( |
52 | | - Map.of( |
53 | | - "name", |
54 | | - "JOB_1", |
55 | | - "referenceID", |
56 | | - "c1253940-5f25-4a0b-8585-f62bd085b327", |
57 | | - "parameters", |
58 | | - new JSONArray( |
59 | | - List.of( |
60 | | - new JSONObject(Map.of("name", "A", "value", "abc")), |
61 | | - new JSONObject(Map.of("name", "C", "value", "true")), |
62 | | - new JSONObject(Map.of("name", "E", "value", JSONObject.NULL)) |
| 43 | + try (OutboxTestSetup setup = new OutboxTestSetup(ProcessingService_.CDS_NAME, cdsRuntime, persistenceService)) { |
| 44 | + JSONObject job = new JSONObject( |
| 45 | + Map.of( |
| 46 | + "name", |
| 47 | + "JOB_1", |
| 48 | + "referenceID", |
| 49 | + "c1253940-5f25-4a0b-8585-f62bd085b327", |
| 50 | + "parameters", |
| 51 | + new JSONArray( |
| 52 | + List.of( |
| 53 | + new JSONObject(Map.of("name", "A", "value", "abc")), |
| 54 | + new JSONObject(Map.of("name", "C", "value", "true")), |
| 55 | + new JSONObject(Map.of("name", "E", "value", JSONObject.NULL)) |
| 56 | + ) |
63 | 57 | ) |
64 | 58 | ) |
65 | | - ) |
66 | | - ); |
67 | | - MvcResult result = mockMvc |
68 | | - .perform(post("/api/job-scheduling/v1/Job").contentType("application/json").content(job.toString())) |
69 | | - .andExpect(status().isCreated()) |
70 | | - .andReturn(); |
71 | | - String response = result.getResponse().getContentAsString(); |
72 | | - JSONObject json = new JSONObject(response); |
73 | | - String ID = json.getString("ID"); |
74 | | - assertEquals("http://localhost:8080/launchpad.html#Job-monitor&/Job(" + ID + ")", json.get("link")); |
75 | | - assertEquals("JOB_1", json.get("name")); |
76 | | - assertEquals("c1253940-5f25-4a0b-8585-f62bd085b327", json.get("referenceID")); |
77 | | - assertEquals(JSONObject.NULL, json.get("startDateTime")); |
78 | | - assertEquals(JobStatusCode.REQUESTED, json.get("status")); |
79 | | - assertEquals(JSONObject.NULL, json.get("testRun")); |
80 | | - assertEquals("1", json.get("version")); |
| 59 | + ); |
| 60 | + MvcResult result = mockMvc |
| 61 | + .perform(post("/api/job-scheduling/v1/Job").contentType("application/json").content(job.toString())) |
| 62 | + .andExpect(status().isCreated()) |
| 63 | + .andReturn(); |
| 64 | + String response = result.getResponse().getContentAsString(); |
| 65 | + JSONObject json = new JSONObject(response); |
| 66 | + String ID = json.getString("ID"); |
| 67 | + assertEquals("http://localhost:8080/launchpad.html#Job-monitor&/Job(" + ID + ")", json.get("link")); |
| 68 | + assertEquals("JOB_1", json.get("name")); |
| 69 | + assertEquals("c1253940-5f25-4a0b-8585-f62bd085b327", json.get("referenceID")); |
| 70 | + assertEquals(JSONObject.NULL, json.get("startDateTime")); |
| 71 | + assertEquals(JobStatusCode.REQUESTED, json.get("status")); |
| 72 | + assertEquals(JSONObject.NULL, json.get("testRun")); |
| 73 | + assertEquals("1", json.get("version")); |
81 | 74 |
|
82 | | - mockMvc |
83 | | - .perform(get("/api/job-scheduling/v1/Job/" + ID)) |
84 | | - .andExpect(status().isOk()) |
85 | | - .andExpect(jsonPath("$.status").value(JobStatusCode.REQUESTED)); |
| 75 | + mockMvc |
| 76 | + .perform(get("/api/job-scheduling/v1/Job/" + ID)) |
| 77 | + .andExpect(status().isOk()) |
| 78 | + .andExpect(jsonPath("$.status").value(JobStatusCode.REQUESTED)); |
86 | 79 |
|
87 | | - setup.eventTriggered.countDown(); |
| 80 | + List<JSONObject> messageEvents = setup.awaitCompleted(5, TimeUnit.SECONDS); |
88 | 81 |
|
89 | | - JSONObject processingEvent = setup.messageEvents.get(0); |
90 | | - assertEquals("sapafcsdk.scheduling.ProcessingService", processingEvent.get("event")); |
91 | | - assertEquals("processJob", processingEvent.getJSONObject("message").get("event")); |
92 | | - assertEquals(ID, processingEvent.getJSONObject("message").getJSONObject("params").get("ID")); |
| 82 | + JSONObject processingEvent = messageEvents.get(0); |
| 83 | + assertEquals("sapafcsdk.scheduling.ProcessingService", processingEvent.get("event")); |
| 84 | + assertEquals("processJob", processingEvent.getJSONObject("message").get("event")); |
| 85 | + assertEquals(ID, processingEvent.getJSONObject("message").getJSONObject("params").get("ID")); |
93 | 86 |
|
94 | | - JSONObject websocketEvent = setup.messageEvents.get(1); |
95 | | - assertEquals("sapafcsdk.scheduling.WebsocketService", websocketEvent.get("event")); |
96 | | - assertEquals("jobStatusChanged", websocketEvent.getJSONObject("message").get("event")); |
97 | | - assertEquals( |
98 | | - JobStatusCode.REQUESTED, |
99 | | - websocketEvent.getJSONObject("message").getJSONObject("params").getJSONObject("data").get("status") |
100 | | - ); |
101 | | - assertEquals( |
102 | | - ID, |
103 | | - websocketEvent.getJSONObject("message").getJSONObject("params").getJSONObject("data").getJSONArray("IDs").get(0) |
104 | | - ); |
| 87 | + JSONObject websocketEvent = messageEvents.get(1); |
| 88 | + assertEquals("sapafcsdk.scheduling.WebsocketService", websocketEvent.get("event")); |
| 89 | + assertEquals("jobStatusChanged", websocketEvent.getJSONObject("message").get("event")); |
| 90 | + assertEquals( |
| 91 | + JobStatusCode.REQUESTED, |
| 92 | + websocketEvent.getJSONObject("message").getJSONObject("params").getJSONObject("data").get("status") |
| 93 | + ); |
| 94 | + assertEquals( |
| 95 | + ID, |
| 96 | + websocketEvent.getJSONObject("message").getJSONObject("params").getJSONObject("data").getJSONArray("IDs").get(0) |
| 97 | + ); |
105 | 98 |
|
106 | | - assertTrue(setup.messageFinished.await(3, TimeUnit.SECONDS)); |
107 | | - |
108 | | - mockMvc |
109 | | - .perform(get("/api/job-scheduling/v1/Job/" + ID)) |
110 | | - .andExpect(status().isOk()) |
111 | | - .andExpect(jsonPath("$.status").value(JobStatusCode.RUNNING)); |
112 | | - |
113 | | - setup.end(); |
| 99 | + mockMvc |
| 100 | + .perform(get("/api/job-scheduling/v1/Job/" + ID)) |
| 101 | + .andExpect(status().isOk()) |
| 102 | + .andExpect(jsonPath("$.status").value(JobStatusCode.RUNNING)); |
| 103 | + } |
114 | 104 | } |
115 | 105 | } |
0 commit comments