aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/testUtils
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2018-12-31 17:21:27 +0200
committerIttay Stern <ittay.stern@att.com>2019-01-09 20:19:55 +0200
commit6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 (patch)
tree3bd672dff83e3218232cd8665680416b7fc26a5d /vid-app-common/src/test/java/org/onap/vid/testUtils
parent5ec29ff5e3864f1ba6ecac71f8bffbefa400cf27 (diff)
Merge from ECOMP's repository
Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/testUtils')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java58
1 files changed, 51 insertions, 7 deletions
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 b4c7828b..b80c75e5 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
@@ -3,6 +3,8 @@ package org.onap.vid.testUtils;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
@@ -10,20 +12,26 @@ import org.mockito.MockSettings;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.asdc.beans.Service;
+import org.springframework.mock.env.MockEnvironment;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
+import java.net.URI;
import java.util.Iterator;
import java.util.List;
import static fj.parser.Parser.fail;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
/**
@@ -31,6 +39,8 @@ import static org.mockito.Mockito.*;
*/
public class TestUtils {
+ private static final Logger logger = LogManager.getLogger(TestUtils.class);
+
/**
* The method compares between two jsons. the function assert that the actual object does not reduce or change the functionallity/parsing of the expected json.
* This means that if the expected JSON has a key which is null or the JSON doesn't have a key which contained in the expected JSON the assert will succeed and the will pass.
@@ -77,7 +87,7 @@ public class TestUtils {
}
}
else {
- Assert.assertEquals(expectedValue, actualValue);
+ Assert.assertEquals("assertion fail for key:"+key, expectedValue, actualValue);
}
}
}
@@ -99,6 +109,7 @@ public class TestUtils {
public static class JavaxRsClientMocks {
private final javax.ws.rs.client.Client fakeClient;
private final javax.ws.rs.client.Invocation.Builder fakeBuilder;
+ private final javax.ws.rs.client.Invocation fakeInvocation;
private final Response fakeResponse;
public javax.ws.rs.client.Client getFakeClient() {
@@ -118,6 +129,7 @@ public class TestUtils {
fakeClient = mock(javax.ws.rs.client.Client.class, mockSettings);
fakeBuilder = mock(javax.ws.rs.client.Invocation.Builder.class, mockSettings);
+ fakeInvocation = mock(javax.ws.rs.client.Invocation.class, mockSettings);
fakeResponse = mock(Response.class, mockSettings);
final javax.ws.rs.client.WebTarget fakeWebTarget = mock(javax.ws.rs.client.WebTarget.class, mockSettings);
@@ -125,16 +137,16 @@ public class TestUtils {
fakeClient,
fakeWebTarget,
fakeBuilder,
+ fakeInvocation,
fakeResponse
);
-
Mockito.when(fakeBuilder.get(any(Class.class))).thenReturn(null);
- Mockito.when(fakeBuilder.get(eq(InputStream.class))).thenReturn(new ByteArrayInputStream(new byte[]{}));
Mockito.when(fakeBuilder.get(any(GenericType.class))).thenReturn(null);
-
Mockito.when(fakeResponse.getStatus()).thenReturn(200);
Mockito.when(fakeResponse.getStatusInfo()).thenReturn(Response.Status.OK);
Mockito.when(fakeResponse.readEntity(Service.class)).thenReturn(null);
+ Mockito.when(fakeResponse.readEntity(InputStream.class)).thenReturn(new ByteArrayInputStream(new byte[]{}));
+ Mockito.when(fakeResponse.readEntity(String.class)).thenReturn(null);
}
}
@@ -155,9 +167,41 @@ public class TestUtils {
return availableMocks.stream()
.filter(mock -> methodReturnType.isAssignableFrom(mock.getClass()))
- //.peek(m -> System.out.println("found a mock: " + m.getClass().getName()))
+ //.peek(m -> logger.info("found a mock: " + m.getClass().getName()))
.findFirst()
.orElse(defaultReturn.answer(invocation));
}
}
+
+
+ //The method mocks only some methods used in my case
+ //You may add some other when for your test here
+ public static Response mockResponseForJavaxClient(Client javaxClientMock) {
+ Response mockResponse = mock(Response.class);
+ WebTarget webTarget = mock(WebTarget.class);
+ Invocation.Builder builder = mock(Invocation.Builder.class);
+ when(javaxClientMock.target(any(URI.class))).thenReturn(webTarget);
+ when(webTarget.path(any())).thenReturn(webTarget);
+ when(webTarget.request(any(MediaType.class))).thenReturn(builder);
+ when(builder.headers(any())).thenReturn(builder);
+ when(builder.header(any(), any())).thenReturn(builder);
+ when(builder.get()).thenReturn(mockResponse);
+ return mockResponse;
+ }
+
+
+ //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);
+
+ SystemProperties systemProperties = new SystemProperties();
+ systemProperties.setEnvironment(mockEnvironment);
+ }
+
+ public static void resetSystemProperties() {
+ SystemProperties systemProperties = new SystemProperties();
+ systemProperties.setEnvironment(null);
+ }
+
}