@@ -31,7 +31,7 @@ class IncidentsODataTests {
3131 */
3232 @ Test
3333 @ WithMockUser (username = "alice" )
34- void incidentReturned () throws Exception {
34+ void incidentReturned (@ Autowired MockMvc mockMvc ) throws Exception {
3535 mockMvc .perform (get (incidentsURI ))
3636 .andExpect (status ().isOk ())
3737 .andExpect (jsonPath ("$.value" , hasSize (4 )));
@@ -65,30 +65,61 @@ void expandEntityEndpoint() throws Exception {
6565
6666 }
6767
68+
6869 /**
69- * Test to create an Incident.
70- * Test custom handler ensuring High Urgency For Incidents With "Urgent" in Title
71- * @throws Exception
70+ * Test for creating an Draft Incident
71+ * Activating the draft Incident and check Urgency code as H using custom logic
72+ * Delete the Incident
7273 */
73- @ Test
74- @ WithMockUser (username = "alice" )
75- void createIncident () throws Exception {
76- String incidentJson = "{ \" title\" : \" Urgent attention required!\" , \" status_code\" : \" N\" , \" urgency_code\" : \" M\" , \" IsActiveEntity\" : true }" ;
7774
78- mockMvc .perform (MockMvcRequestBuilders .post ("/odata/v4/ProcessorService/Incidents" )
79- .content (incidentJson )
80- .contentType ("application/json" )
81- .accept ("application/json" ))
82- .andExpect (status ().isCreated ())
83- .andExpect (jsonPath ("$" ).isMap ())
84- .andExpect (jsonPath ("$.title" ).value ("Urgent attention required!" ))
85- .andExpect (jsonPath ("$.status_code" ).value ("N" ))
86- .andExpect (jsonPath ("$.urgency_code" ).value ("H" ));
87- }
75+ @ Test
76+ @ WithMockUser (username = "alice" )
77+ void draftIncident () throws Exception {
78+ String incidentCreateJson = "{ \" title\" : \" Urgent attention required!\" , \" status_code\" : \" N\" ,\" urgency_code\" : \" M\" }" ;
79+
80+ /**
81+ * Create a draft Incident
82+ */
83+
84+ MvcResult createResult = mockMvc .perform (MockMvcRequestBuilders .post ("/odata/v4/ProcessorService/Incidents" )
85+ .content (incidentCreateJson )
86+ .contentType ("application/json" )
87+ .accept ("application/json" ))
88+ .andExpect (status ().isCreated ())
89+ .andExpect (jsonPath ("$.title" ).value ("Urgent attention required!" ))
90+ .andExpect (jsonPath ("$.status_code" ).value ("N" ))
91+ .andExpect (jsonPath ("$.urgency_code" ).value ("M" ))
92+ .andReturn ();
93+
94+ String createResponseContent = createResult .getResponse ().getContentAsString ();
95+ String ID = JsonPath .read (createResponseContent , "$.ID" );
96+ System .out .println ("Incident ID : " + ID );
97+
98+ /**
99+ * Activating the draft Incident
100+ */
101+
102+ mockMvc .perform (MockMvcRequestBuilders .post ("/odata/v4/ProcessorService/Incidents(ID=" +ID +",IsActiveEntity=false)/ProcessorService.draftActivate" )
103+ .contentType ("application/json" )
104+ .accept ("application/json" ))
105+ .andExpect (status ().isOk ())
106+ .andExpect (jsonPath ("$" ).isMap ())
107+ .andExpect (jsonPath ("$.title" ).value ("Urgent attention required!" ))
108+ .andExpect (jsonPath ("$.status_code" ).value ("N" ))
109+ .andExpect (jsonPath ("$.urgency_code" ).value ("H" ));
110+
111+ /**
112+ * Deleting an Incident
113+ */
114+
115+ mockMvc .perform (MockMvcRequestBuilders .delete ("/odata/v4/ProcessorService/Incidents(ID=" +ID +",IsActiveEntity=true)" ))
116+ .andExpect (status ().is (204 ));
117+ }
118+
88119
89120 /**
90- * Test for creating an Incident
91- * Test for closing the Incident
121+ * Test for creating an Active Incident
122+ * Test for closing the Active Incident
92123 * Test for custom handler ensuing prevent users from modifying a closed Incident
93124 */
94125
0 commit comments