Merge "Merge from ecomp 3374149f - AngularJS UI"
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 3011013..2df28d9 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
@@ -22,7 +22,9 @@
 package org.onap.vid.controller;
 
 import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
@@ -34,6 +36,7 @@
 import com.google.common.collect.Multimap;
 import java.util.Map;
 import java.util.UUID;
+import javax.ws.rs.core.Response;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -50,6 +53,7 @@
 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError;
 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk;
 import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.model.VersionByInvariantIdsRequest;
 import org.onap.vid.roles.RoleProvider;
 import org.onap.vid.services.AaiService;
 import org.onap.vid.utils.SystemPropertiesWrapper;
@@ -224,5 +228,24 @@
             .andExpect(status().isOk())
             .andExpect(content().string(expectedResponseBody));
     }
+
+    @Test
+    public void getVersionByInvariantId_shouldReturnOKResponse() throws Exception {
+        String expectedResponse = "OKResponse";
+        VersionByInvariantIdsRequest request = new VersionByInvariantIdsRequest();
+        request.versions = ImmutableList.of("ver1", "ver2");
+        Response response = mock(Response.class);
+        given(response.readEntity(String.class)).willReturn(expectedResponse);
+        given(aaiService
+            .getVersionByInvariantId(request.versions)).willReturn(response);
+
+        mockMvc.perform(
+            post("/aai_get_version_by_invariant_id")
+                .content(new ObjectMapper().writeValueAsString(request))
+                .contentType(MediaType.APPLICATION_JSON)
+                .accept(MediaType.APPLICATION_JSON))
+            .andExpect(status().isOk())
+            .andExpect(content().string(expectedResponse));
+    }
 }
 
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java
index 527ba17..31dbc9f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java
@@ -58,6 +58,7 @@
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.*;
 import static org.onap.vid.job.Job.JobStatus.*;
+import static org.onap.vid.testUtils.TestUtils.testWithSystemProperty;
 
 public class ServiceInProgressStatusCommandTest {
 
@@ -218,11 +219,9 @@
     }
 
     @Test(dataProvider = "isExpiredJobStatusData")
-    public void isExpiredJobStatusTest(ZonedDateTime jobStartTime, String configValue, boolean expectedResult) {
-        SystemProperties systemProperties = new SystemProperties();
-        systemProperties.setEnvironment(environment);
-        when(environment.getRequiredProperty(VidProperties.VID_JOB_MAX_HOURS_IN_PROGRESS)).thenReturn(configValue);
-        when(environment.containsProperty(VidProperties.VID_JOB_MAX_HOURS_IN_PROGRESS)).thenReturn(true);
-        Assert.assertEquals(command.getExpiryChecker().isExpired(jobStartTime), expectedResult);
+    public void isExpiredJobStatusTest(ZonedDateTime jobStartTime, String configValue, boolean expectedResult) throws Exception {
+        testWithSystemProperty(VidProperties.VID_JOB_MAX_HOURS_IN_PROGRESS, configValue, ()->
+            Assert.assertEquals(command.getExpiryChecker().isExpired(jobStartTime), expectedResult)
+        );
     }
 }
diff --git a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
index 3d919d7..756d175 100644
--- a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
+++ b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
@@ -50,6 +50,7 @@
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.json.JSONArray;
@@ -61,6 +62,7 @@
 import org.mockito.stubbing.Answer;
 import org.onap.portalsdk.core.util.SystemProperties;
 import org.onap.vid.asdc.beans.Service;
+import org.springframework.core.env.Environment;
 import org.springframework.mock.env.MockEnvironment;
 
 /**
@@ -252,18 +254,27 @@
     }
 
 
-    //Please use resetSystemProperties after using this method, so other test won't be affected
-    public static void mockSystemPropertyWithKeyValue(String key, String value) {
-        MockEnvironment mockEnvironment = new MockEnvironment();
-        mockEnvironment.setProperty(key, value);
+    public interface Test {
 
-        SystemProperties systemProperties = new SystemProperties();
-        systemProperties.setEnvironment(mockEnvironment);
+        void apply();
     }
 
-    public static void resetSystemProperties() {
+    public static void testWithSystemProperty(String key, String value, Test test) throws Exception {
         SystemProperties systemProperties = new SystemProperties();
-        systemProperties.setEnvironment(null);
+        //use reflection to invoke protected method
+        Environment originalEnvironment = (Environment) MethodUtils
+            .invokeMethod(systemProperties, true, "getEnvironment");
+
+        try {
+            Environment environment = mock(Environment.class);
+            systemProperties.setEnvironment(environment);
+            when(environment.getRequiredProperty(key)).thenReturn(value);
+            when(environment.containsProperty(key)).thenReturn(true);
+            test.apply();
+        }
+        finally {
+            systemProperties.setEnvironment(originalEnvironment);
+        }
     }
 
 }