aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
diff options
context:
space:
mode:
authorEinat Vinouze <einat.vinouze@intl.att.com>2019-07-16 17:17:36 +0300
committerIttay Stern <ittay.stern@att.com>2019-07-30 06:01:44 +0300
commite601bbdc43bae9a08e2e10c5139a6f76b47860d7 (patch)
tree1913f0b369ead3f2ea5557e5649d8281eca9871c /vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
parent76c6ee4a697617ec4cdee2f3b48bc83136c858c5 (diff)
Implant vid-app-common org.onap.vid.job (main and test)
Issue-ID: VID-378 Change-Id: I41b0bdc2c4e3635f3f3319b1cd63cefc61912dfc Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com> Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java51
1 files changed, 44 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 756d17534..5fc583274 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
@@ -20,10 +20,14 @@
package org.onap.vid.testUtils;
+import static com.fasterxml.jackson.module.kotlin.ExtensionsKt.jacksonObjectMapper;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptors;
+import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
+import static org.apache.commons.text.CharacterPredicates.DIGITS;
+import static org.apache.commons.text.CharacterPredicates.LETTERS;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.RETURNS_DEFAULTS;
import static org.mockito.Mockito.mock;
@@ -33,6 +37,7 @@ import static org.testng.Assert.fail;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.code.beanmatchers.BeanMatchers;
import com.google.common.collect.ImmutableList;
import java.beans.PropertyDescriptor;
import java.io.ByteArrayInputStream;
@@ -50,7 +55,9 @@ import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
+import org.apache.commons.text.RandomStringGenerator;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.json.JSONArray;
@@ -62,8 +69,9 @@ 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.onap.vid.mso.model.CloudConfiguration;
import org.springframework.core.env.Environment;
-import org.springframework.mock.env.MockEnvironment;
+import org.testng.annotations.DataProvider;
/**
* Created by Oren on 6/7/17.
@@ -127,13 +135,22 @@ public class TestUtils {
return readJsonResourceFileAsObject(pathInResource, valueType, false);
}
- public static <T> T readJsonResourceFileAsObject(String pathInResource, Class<T> valueType, boolean ignoreUnknownProperties)
- throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, ignoreUnknownProperties);
+ public static <T> T readJsonResourceFileAsObject(String pathInResource, Class<T> valueType,
+ boolean failOnUnknownProperties)
+ throws IOException {
+ ObjectMapper objectMapper = jacksonObjectMapper()
+ .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, failOnUnknownProperties);
return objectMapper.readValue(
- TestUtils.class.getResource(pathInResource),
- valueType);
+ TestUtils.class.getResource(pathInResource),
+ valueType);
+ }
+
+ public static String readFileAsString(String pathInResource) {
+ try {
+ return IOUtils.toString(TestUtils.class.getResource(pathInResource), "UTF-8");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
public static String[] allPropertiesOf(Class<?> aClass) {
@@ -169,6 +186,12 @@ public class TestUtils {
}
}
+ public static void registerCloudConfigurationValueGenerator() {
+ BeanMatchers.registerValueGenerator(() -> new CloudConfiguration(
+ randomAlphabetic(7), randomAlphabetic(7), randomAlphabetic(7)
+ ), CloudConfiguration.class);
+ }
+
public static class JavaxRsClientMocks {
private final javax.ws.rs.client.Client fakeClient;
@@ -277,4 +300,18 @@ public class TestUtils {
}
}
+ private static RandomStringGenerator generator = new RandomStringGenerator.Builder()
+ .withinRange('0', 'z')
+ .filteredBy(LETTERS, DIGITS)
+ .build();
+
+ public static String generateRandomAlphaNumeric(int length) {
+ return generator.generate(length);
+ }
+
+ @DataProvider
+ public static Object[][] trueAndFalse() {
+ return new Object[][]{{true}, {false}};
+ }
+
}