summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>2019-06-05 02:42:32 -0400
committerTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>2019-06-05 02:42:32 -0400
commit4480a6cac93693cef4515a0f5588c58bbe270f06 (patch)
tree02de13d7fa12b064c08afd79862e9dbb30d44f54
parentfc596b9d71dddc87b58de486f0f5af26ea8755b4 (diff)
junits for AaiController
-Added new test for getSpecificPnf method Change-Id: I1837a364673c3dd04b559eacccd7baeeeb82208f Issue-ID: VID-478 Signed-off-by: Tomasz Gwozdecki <tomasz.gwozdecki@nokia.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java5
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java35
2 files changed, 37 insertions, 3 deletions
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 ca40b7d0c..4a4f3d300 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
@@ -401,13 +401,12 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_get_pnfs/pnf/{pnf_id}", method = RequestMethod.GET)
public ResponseEntity getSpecificPnf(@PathVariable("pnf_id") String pnfId) {
- AaiResponse<Pnf> resp;
ResponseEntity<Pnf> re;
try {
- resp = aaiService.getSpecificPnf(pnfId);
+ AaiResponse<Pnf> resp = aaiService.getSpecificPnf(pnfId);
re = new ResponseEntity<>(resp.getT(), HttpStatus.valueOf(resp.getHttpCode()));
} catch (Exception e) {
- return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return re;
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
index 2f0d1cd0c..35e098c1b 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
@@ -45,6 +45,7 @@ import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError;
import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk;
import org.onap.vid.aai.model.AaiGetAicZone.AicZones;
import org.onap.vid.aai.model.AaiGetAicZone.Zone;
+import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
import org.onap.vid.aai.model.PortDetailsTranslator.PortDetails;
import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError;
import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk;
@@ -164,5 +165,39 @@ public class AaiControllerTest {
.andExpect(status().isInternalServerError())
.andExpect(content().string(expectedErrorMessage));
}
+
+ @Test
+ public void getSpecificPnf_shouldReturnPnfObjectForPnfId() throws Exception {
+ String pnfId = "MyPnfId";
+ Pnf pnf = createPnf(pnfId);
+ AaiResponse<Pnf> aaiResponse = new AaiResponse<>(pnf, "", HttpStatus.OK.value());
+ given(aaiService.getSpecificPnf(pnfId)).willReturn(aaiResponse);
+
+ mockMvc.perform(get("/aai_get_pnfs/pnf/{pnf_id}", pnfId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(pnf)));
+ }
+
+ @Test
+ public void getSpecificPnf_shouldHandleAAIServiceException() throws Exception {
+ String pnfId = "MyPnfId";
+ String expectedErrorMessage = "AAI Service Error";
+ given(aaiService.getSpecificPnf(pnfId)).willThrow(new RuntimeException(expectedErrorMessage));
+
+ mockMvc.perform(get("/aai_get_pnfs/pnf/{pnf_id}", pnfId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isInternalServerError())
+ .andExpect(content().string(expectedErrorMessage));
+ }
+
+ private Pnf createPnf(String pnfId) {
+ Pnf pnf = new Pnf();
+ pnf.setPnfId(pnfId);
+ pnf.setPnfName("TestPnf");
+ return pnf;
+ }
}