Skip to content

Commit 3549455

Browse files
Query no content response code is now 204 (#228)
1 parent 3169f61 commit 3549455

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/functionaltests/java/com/ericsson/ei/query/QueryAggregatedObjectsTestSteps.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void perform_valid_query_on_newly_created_aggregated_object() throws Thro
132132
String actualTestCaseFinishedEventId = responseEntityFormattedJsonNode.get("aggregatedObject")
133133
.get("testCaseExecutions").get(0).get("testCaseFinishedEventId").asText();
134134

135-
assertEquals(HttpStatus.OK.toString(), Integer.toString(response.getStatusCodeValue()));
135+
assertEquals(HttpStatus.OK.value(), response.getStatusCodeValue());
136136
assertEquals(
137137
"Failed to compare actual Aggregated Object TestCaseFinishedEventId:\n" + actualTestCaseFinishedEventId
138138
+ "\nwith expected Aggregated Object TestCaseFinishedEventId:\n"
@@ -144,7 +144,7 @@ public void perform_valid_query_on_newly_created_aggregated_object() throws Thro
144144
public void perform_invalid_query_on_created_aggregated_object() throws Throwable {
145145
final String invalidDocumentId = "6acc3c87-75e0-4aaa-88f5-b1a5d4e6cccc";
146146
final String entryPoint = "/queryAggregatedObject";
147-
final String expectedResponse = "{\"responseEntity\":\"[]\"}";
147+
final String expectedResponse = "";
148148

149149
LOGGER.debug("Trying an invalid query on /queryAggregatedObject RestApi with invalid documentId: "
150150
+ invalidDocumentId);
@@ -158,7 +158,7 @@ public void perform_invalid_query_on_created_aggregated_object() throws Throwabl
158158
LOGGER.debug("Response of /queryAggregatedObject RestApi, Status Code: " + responseStatusCode + "\nResponse: "
159159
+ responseAsString);
160160

161-
assertEquals(HttpStatus.OK.toString(), Integer.toString(responseStatusCode));
161+
assertEquals(HttpStatus.NO_CONTENT.value(), responseStatusCode);
162162
assertEquals("Differences between actual Aggregated Object:\n" + responseAsString
163163
+ "\nand expected Aggregated Object:\n" + expectedResponse, expectedResponse, responseAsString);
164164
}
@@ -197,7 +197,7 @@ public void perform_several_valid_freestyle_queries_on_created_Aggregated_object
197197
String actualAggrObjId = aggrObjResponse.get("id").asText();
198198
LOGGER.debug("AggregatedObject id from Response: " + actualAggrObjId);
199199

200-
assertEquals(HttpStatus.OK.toString(), Integer.toString(response.getStatusCodeValue()));
200+
assertEquals(HttpStatus.OK.value(), response.getStatusCodeValue());
201201
assertEquals(
202202
"Failed to compare actual Aggregated Object Id:\n" + actualAggrObjId
203203
+ "\nwith expected Aggregated Object Id:\n" + expectedAggrId,
@@ -210,7 +210,7 @@ public void perform_invalid_freestyle_query_on_created_aggregated_object() throw
210210
final String invalidAggrId = "6acc3c87-75e0-4b6d-88f5-b1aee4e62b43";
211211
final String entryPoint = "/query";
212212
final String queryAggrObj = "{\"criteria\" :{\"aggregatedObject.id\" : \"" + invalidAggrId + "\" }}";
213-
final String expectedResponse = "[]";
213+
final String expectedResponse = "";
214214

215215
LOGGER.debug("Trying an invalid query on /query RestApi with invalid criteria query: " + queryAggrObj);
216216

@@ -223,7 +223,7 @@ public void perform_invalid_freestyle_query_on_created_aggregated_object() throw
223223
LOGGER.debug(
224224
"Response of /query RestApi, Status Code: " + responseStatusCode + "\nResponse: " + responseAsString);
225225

226-
assertEquals(HttpStatus.OK.toString(), Integer.toString(responseStatusCode));
226+
assertEquals(HttpStatus.NO_CONTENT.value(), responseStatusCode);
227227
assertEquals("Differences between actual Aggregated Object:\n" + responseAsString
228228
+ "\nand expected Aggregated Object:\n" + expectedResponse, expectedResponse, responseAsString);
229229
}
@@ -264,7 +264,7 @@ public void perform_a_query_for_missed_notification() throws Throwable {
264264

265265
String actualTestCaseStartedEventId = responseEntityFormattedJsonNode.get("testCaseExecutions")
266266
.get("testCaseStartedEventId").asText();
267-
assertEquals(HttpStatus.OK.toString(), Integer.toString(response.getStatusCodeValue()));
267+
assertEquals(HttpStatus.OK.value(), response.getStatusCodeValue());
268268
assertEquals("Differences between actual Missed Notification response TestCaseStartedEventId:\n"
269269
+ actualTestCaseStartedEventId
270270
+ "\nand expected Missed Notification response TestCaseStartedEventId:\n"
@@ -291,7 +291,7 @@ public void check_missed_notification_has_been_returned() throws Throwable {
291291
LOGGER.debug("Response of /queryMissedNotifications RestApi, Status Code: " + responseStatusCode + "\nResponse: "
292292
+ responseAsString);
293293

294-
assertEquals(HttpStatus.OK.toString(), Integer.toString(responseStatusCode));
294+
assertEquals(HttpStatus.OK.value(), responseStatusCode);
295295
assertEquals(
296296
"Differences between actual Missed Notification response:\n" + responseAsString
297297
+ "\nand expected Missed Notification response:\n" + expectedResponse,
@@ -326,7 +326,7 @@ public void perform_valid_query_and_filter_on_aggregated_object() throws Throwab
326326
String responseAsString = response.getBody().toString();
327327
int responseStatusCode = response.getStatusCodeValue();
328328

329-
assertEquals(HttpStatus.OK.toString(), Integer.toString(responseStatusCode));
329+
assertEquals(HttpStatus.OK.value(), responseStatusCode);
330330
assertEquals(
331331
"Failed to compare actual response:\n" + responseAsString + "\nwith expected response:\n"
332332
+ expectedResponse,
@@ -374,7 +374,7 @@ public void perform__query_and_filter_with_part_of_path() throws Throwable {
374374
String responseAsString = response.getBody().toString();
375375
int responseStatusCode = response.getStatusCodeValue();
376376

377-
assertEquals(HttpStatus.OK.toString(), Integer.toString(responseStatusCode));
377+
assertEquals(HttpStatus.OK.value(), responseStatusCode);
378378
assertEquals(
379379
"Failed to compare actual response:\n" + responseAsString + "\nwith expected response:\n"
380380
+ expectedResponses.get(pos),
@@ -413,7 +413,7 @@ public void perform_query_to_retrieve_and_filter_out_confidence_level_informatio
413413

414414
JsonNode confidenceLevels = aggrObjResponse.get("confidenceLevels").get(1);
415415

416-
assertEquals(HttpStatus.OK.toString(), Integer.toString(response.getStatusCodeValue()));
416+
assertEquals(HttpStatus.OK.value(), response.getStatusCodeValue());
417417
assertEquals("Failed to retrieve the latest confidence level.", "readyForDelivery",
418418
confidenceLevels.get("name").asText());
419419
assertEquals("Failed to retrieve the latest confidence level.", "SUCCESS",

src/main/java/com/ericsson/ei/controller/QueryAggregatedObjectControllerImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,18 @@ public class QueryAggregatedObjectControllerImpl implements QueryAggregatedObjec
5050
@Override
5151
public ResponseEntity<QueryResponse> getQueryAggregatedObject(@RequestParam("ID") final String id) {
5252
QueryResponse queryResponse = new QueryResponse();
53+
String emptyResponseContent = "[]";
54+
HttpStatus httpStatus;
5355
try {
5456
List<String> response = processAggregatedObject.processQueryAggregatedObject(id);
5557
queryResponse.setResponseEntity(response.toString());
5658
LOGGER.debug("The response is: " + response.toString());
57-
return new ResponseEntity<>(queryResponse, HttpStatus.OK);
59+
if(!queryResponse.getResponseEntity().equalsIgnoreCase(emptyResponseContent)) {
60+
httpStatus = HttpStatus.OK;
61+
} else {
62+
httpStatus = HttpStatus.NO_CONTENT;
63+
}
64+
return new ResponseEntity<>(queryResponse, httpStatus);
5865
} catch (Exception e) {
5966
String errorMessage = "Failed to extract the aggregated data from the Aggregated Object based on ID "
6067
+ id + ". Error message:\n" + e.getMessage();

src/main/java/com/ericsson/ei/controller/QueryControllerImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class QueryControllerImpl implements QueryController {
5151
@CrossOrigin
5252
@ApiOperation(value = "")
5353
public ResponseEntity<?> createQuery(@RequestBody final QueryBody body) {
54+
String emptyResponseContent = "[]";
55+
HttpStatus httpStatus;
5456
try {
5557
JSONObject criteria = new JSONObject(body.getCriteria().getAdditionalProperties());
5658
JSONObject options = null;
@@ -63,7 +65,12 @@ public ResponseEntity<?> createQuery(@RequestBody final QueryBody body) {
6365
}
6466

6567
JSONArray result = processQueryParams.filterFormParam(criteria, options, filter);
66-
return new ResponseEntity<>(result.toString(), HttpStatus.OK);
68+
if(!result.toString().equalsIgnoreCase(emptyResponseContent)) {
69+
httpStatus = HttpStatus.OK;
70+
} else {
71+
httpStatus = HttpStatus.NO_CONTENT;
72+
}
73+
return new ResponseEntity<>(result.toString(), httpStatus);
6774
} catch (Exception e) {
6875
String errorMessage = "Failed to extract data from the Aggregated Object using freestyle query. Error message:\n" + e.getMessage();
6976
LOGGER.error(errorMessage, e);

0 commit comments

Comments
 (0)