aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main
diff options
context:
space:
mode:
authorMichal Kabaj <michal.kabaj@nokia.com>2019-05-28 14:45:08 +0200
committerMichal Kabaj <michal.kabaj@nokia.com>2019-05-31 11:38:26 +0200
commitf6a92aaee1e89499e18aae942a672dc420b26b35 (patch)
treeccc9b66e2663623565e18eeda1baa8bb8f1da37d /vid-app-common/src/main
parentbd42250f5046225cfb155d004c839eb9e1de1899 (diff)
AaiController unit tests
- unit tests for getAicZones - fixed encapsulation and immutability issues in AicZones and Zone objects Change-Id: I3f71d45bb3c4e2238966e245f0ab77031c4dcb60 Issue-ID: VID-478 Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java18
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java28
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java4
3 files changed, 38 insertions, 12 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java
index 4efaf055e..77553a687 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java
@@ -3,6 +3,7 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nokia.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +21,22 @@
package org.onap.vid.aai.model.AaiGetAicZone;
+import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Collections;
import java.util.List;
-public class AicZones {
- @JsonProperty("zone")
- public List<Zone> zones;
+public final class AicZones {
+
+ private final List<Zone> zones;
+
+ @JsonCreator
+ public AicZones(@JsonProperty("zone") List<Zone> zones) {
+ this.zones = Collections.unmodifiableList(zones);
+ }
+
+ public List<Zone> getZones() {
+ return zones;
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java
index 343a87f02..c36618024 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nokia.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,14 +21,27 @@
package org.onap.vid.aai.model.AaiGetAicZone;
+import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
-public class Zone {
- @JsonProperty("zone-id")
- public String zoneId;
+public final class Zone {
- @JsonProperty("zone-name")
- public String zoneName;
+ private final String zoneId;
+ private final String zoneName;
+
+ @JsonCreator
+ public Zone(@JsonProperty("zone-id") String zoneId, @JsonProperty("zone-name") String zoneName) {
+ this.zoneId = zoneId;
+ this.zoneName = zoneName;
+ }
+
+ public String getZoneId() {
+ return zoneId;
+ }
+
+ public String getZoneName() {
+ return zoneName;
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
index 6a3b4f9eb..ca40b7d0c 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
@@ -149,14 +149,14 @@ public class AaiController extends RestrictedBaseController {
private ResponseEntity<String> aaiResponseToResponseEntity(AaiResponse aaiResponseData)
throws IOException {
ResponseEntity<String> responseEntity;
- ObjectMapper objectMapper = new ObjectMapper();
if (aaiResponseData.getHttpCode() == 200) {
- responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(aaiResponseData.getT()),
+ responseEntity = new ResponseEntity<>(new ObjectMapper().writeValueAsString(aaiResponseData.getT()),
HttpStatus.OK);
} else {
responseEntity = new ResponseEntity<>(aaiResponseData.getErrorMessage(),
HttpStatus.valueOf(aaiResponseData.getHttpCode()));
}
+
return responseEntity;
}