summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java
diff options
context:
space:
mode:
authorWojciech Sliwka <wojciech.sliwka@nokia.com>2019-05-31 10:33:40 +0000
committerGerrit Code Review <gerrit@onap.org>2019-05-31 10:33:40 +0000
commite0c59bc9b16bb69f0f0a47268742c9f030aa3aa6 (patch)
treecf0cb07123ba24e2154144b676773fea643eb401 /vid-app-common/src/test/java
parentba76048291feeb83a3596ebf04c9c0f384706d7b (diff)
parentf6a92aaee1e89499e18aae942a672dc420b26b35 (diff)
Merge "AaiController unit tests"
Diffstat (limited to 'vid-app-common/src/test/java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java34
1 files changed, 31 insertions, 3 deletions
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 bd6e0f986..2f0d1cd0c 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
@@ -27,6 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Lists;
@@ -42,6 +43,8 @@ import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
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.PortDetailsTranslator.PortDetails;
import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError;
import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk;
@@ -59,6 +62,7 @@ public class AaiControllerTest {
private static final String ID_1 = "id1";
private static final String ID_2 = "id2";
+ private final ObjectMapper objectMapper = new ObjectMapper();
@Mock
private AaiService aaiService;
@Mock
@@ -67,7 +71,6 @@ public class AaiControllerTest {
private RoleProvider roleProvider;
@Mock
private SystemPropertiesWrapper systemPropertiesWrapper;
-
private MockMvc mockMvc;
private AaiController aaiController;
@@ -93,7 +96,7 @@ public class AaiControllerTest {
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
- .andExpect(content().json(new ObjectMapper().writeValueAsString(expectedJson)));
+ .andExpect(content().json(objectMapper.writeValueAsString(expectedJson)));
}
@Test
@@ -112,7 +115,7 @@ public class AaiControllerTest {
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
- .andExpect(content().json(new ObjectMapper().writeValueAsString(expectedJson.asMap())));
+ .andExpect(content().json(objectMapper.writeValueAsString(expectedJson.asMap())));
}
@Test
@@ -136,5 +139,30 @@ public class AaiControllerTest {
.andExpect(status().isOk())
.andExpect(content().string(expectedResponseBody));
}
+
+ @Test
+ public void getAicZones_shouldReturnAaiZones_whenAaiHttpStatusIsOK() throws Exception {
+ AicZones aicZones = new AicZones(ImmutableList.of(new Zone("TEST_ZONE_ID", "TEST_ZONE_NAME")));
+ given(aaiService.getAaiZones()).willReturn(new AaiResponse(aicZones, "", HttpStatus.OK.value()));
+
+ mockMvc.perform(get("/aai_get_aic_zones")
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(aicZones)));
+ }
+
+ @Test
+ public void getAicZones_shouldReturnErrorResponse_whenAaiHttpStatusOtherThanOK() throws Exception {
+ String expectedErrorMessage = "Calling AAI Failed";
+ given(aaiService.getAaiZones())
+ .willReturn(new AaiResponse(null, expectedErrorMessage, HttpStatus.INTERNAL_SERVER_ERROR.value()));
+
+ mockMvc.perform(get("/aai_get_aic_zones")
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isInternalServerError())
+ .andExpect(content().string(expectedErrorMessage));
+ }
}