AaiController tests 59/97259/1
authorMichal Kabaj <michal.kabaj@nokia.com>
Thu, 17 Oct 2019 13:08:15 +0000 (15:08 +0200)
committerMichal Kabaj <michal.kabaj@nokia.com>
Thu, 17 Oct 2019 13:08:15 +0000 (15:08 +0200)
added new unit tests to AaiControllerTest

Issue-ID: VID-684
Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Change-Id: Ib6a7aaa932ff2909b8a1fd81d5128713d1dc3eb5

vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java

index 3882423..563c9ff 100644 (file)
@@ -38,8 +38,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.portalsdk.core.controller.RestrictedBaseController;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.vid.aai.AaiGetVnfResponse;
 import org.onap.vid.aai.AaiResponse;
 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
 import org.onap.vid.aai.ServiceInstancesSearchResults;
@@ -201,7 +199,7 @@ public class AaiController extends RestrictedBaseController {
 
     @RequestMapping(value = "/get_system_prop_vnf_prov_status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
     public ResponseEntity<String> getTargetProvStatus() {
-        String p = SystemProperties.getProperty("aai.vnf.provstatus");
+        String p = systemPropertiesWrapper.getProperty("aai.vnf.provstatus");
         return new ResponseEntity<>(p, HttpStatus.OK);
     }
 
index 83cc61e..51bdec8 100644 (file)
@@ -50,6 +50,8 @@ import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.util.SystemProperties;
 import org.onap.vid.aai.AaiResponse;
 import org.onap.vid.aai.AaiResponseTranslator;
 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
@@ -531,5 +533,33 @@ public class AaiControllerTest {
             .andExpect(content().json(objectMapper.writeValueAsString(expectedPnfs)));
     }
 
+    @Test
+    public void getUserID_shouldReturnOKResponse_withExtractedUserId() throws Exception {
+        String userPropertyKey = "user";
+        String expectedUserLoginId = "testUserLoginId";
+        User user = new User();
+        user.setLoginId(expectedUserLoginId);
+        given(systemPropertiesWrapper.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).willReturn(userPropertyKey);
+
+        mockMvc.perform(get("/getuserID")
+            .contentType(MediaType.APPLICATION_JSON)
+            .accept(MediaType.APPLICATION_JSON)
+            .sessionAttr(userPropertyKey, user))
+            .andExpect(status().isOk())
+            .andExpect(content().string(expectedUserLoginId));
+    }
+
+    @Test
+    public void getTargetProvStatus_shouldReturnProperty() throws Exception {
+        String expectedResponse = "targetProvStatus";
+        given(systemPropertiesWrapper.getProperty("aai.vnf.provstatus")).willReturn(expectedResponse);
+
+        mockMvc.perform(get("/get_system_prop_vnf_prov_status")
+            .contentType(MediaType.APPLICATION_JSON)
+            .accept(MediaType.APPLICATION_JSON))
+            .andExpect(status().isOk())
+            .andExpect(content().string(expectedResponse));
+    }
+
 }