aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java18
1 files changed, 11 insertions, 7 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java
index d2ab15fb..1f4f10f3 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +45,9 @@ import org.springframework.stereotype.Service;
@Profile("stub")
class StubUtils {
private static final Logger log = LoggerFactory.getLogger(StubUtils.class);
+ private static final String APPLICATION_JSON = "application/json";
+ private static final String SERIALIZE_RESPONSE_FAILURE_MSG =
+ "Couldn't serialize response for content type application/json";
private final HttpServletRequest request;
private static final String ACCEPT = "Accept";
private static final String PAP_DB =
@@ -52,14 +56,14 @@ class StubUtils {
<T> ResponseEntity<T> getStubbedResponse(Class<T> clazz) {
var accept = request.getHeader(ACCEPT);
- if (accept != null && accept.contains("application/json")) {
+ if (accept != null && accept.contains(APPLICATION_JSON)) {
final var resource = new ClassPathResource(PAP_DB);
try (var inputStream = resource.getInputStream()) {
final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
var targetObject = JSON_TRANSLATOR.fromJson(string, clazz);
return new ResponseEntity<>(targetObject, HttpStatus.OK);
} catch (IOException e) {
- log.error("Couldn't serialize response for content type application/json", e);
+ log.error(SERIALIZE_RESPONSE_FAILURE_MSG, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -68,14 +72,14 @@ class StubUtils {
<T> ResponseEntity<List<T>> getStubbedResponseList(Class<T> clazz) {
var accept = request.getHeader(ACCEPT);
- if (accept != null && accept.contains("application/json")) {
+ if (accept != null && accept.contains(APPLICATION_JSON)) {
final var resource = new ClassPathResource(PAP_DB);
try (var inputStream = resource.getInputStream()) {
final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
var targetObject = Arrays.asList(JSON_TRANSLATOR.fromJson(string, clazz));
return new ResponseEntity<>(targetObject, HttpStatus.OK);
} catch (IOException e) {
- log.error("Couldn't serialize response for content type application/json", e);
+ log.error(SERIALIZE_RESPONSE_FAILURE_MSG, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -84,7 +88,7 @@ class StubUtils {
ResponseEntity<Map<String, Object>> getStubbedResponseMap() {
var accept = request.getHeader(ACCEPT);
- if (accept != null && accept.contains("application/json")) {
+ if (accept != null && accept.contains(APPLICATION_JSON)) {
final var resource = new ClassPathResource(PAP_DB);
try (var inputStream = resource.getInputStream()) {
Map<String, Object> map = new HashMap<>();
@@ -93,7 +97,7 @@ class StubUtils {
JSON_TRANSLATOR.fromJson(string, Object.class));
return new ResponseEntity<>(map, HttpStatus.OK);
} catch (IOException e) {
- log.error("Couldn't serialize response for content type application/json", e);
+ log.error(SERIALIZE_RESPONSE_FAILURE_MSG, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -102,7 +106,7 @@ class StubUtils {
ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> getStubbedResponseStatistics() {
var accept = request.getHeader(ACCEPT);
- if (accept != null && accept.contains("application/json")) {
+ if (accept != null && accept.contains(APPLICATION_JSON)) {
Map<String, Map<String, List<PdpStatistics>>> map = new HashMap<>();
return new ResponseEntity<>(map, HttpStatus.OK);
}