diff options
author | s00370346 <swarup.nayak1@huawei.com> | 2019-07-12 11:35:54 +0530 |
---|---|---|
committer | s00370346 <swarup.nayak1@huawei.com> | 2019-07-12 14:50:21 +0530 |
commit | c818065d90aad39e61992ee44fa13568b80ee7b3 (patch) | |
tree | 02126cd73fbdd7c825b7a120a54699fb340ba3ac /src/test/java/org/onap/dcae/TestingUtilities.java | |
parent | 20d8093fd688f0385b7bb9b8e4b09ff60ef23f26 (diff) |
Issue-ID: DCAEGEN2-1661 Fix Some Compilation warnings, sonar issue
Signed-off-by: s00370346 <swarup.nayak1@huawei.com>
Change-Id: Id01028b87c101ff2544d93c68a59f9cc46020d8d
Diffstat (limited to 'src/test/java/org/onap/dcae/TestingUtilities.java')
-rw-r--r-- | src/test/java/org/onap/dcae/TestingUtilities.java | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/src/test/java/org/onap/dcae/TestingUtilities.java b/src/test/java/org/onap/dcae/TestingUtilities.java index 5ae238a..14c34c9 100644 --- a/src/test/java/org/onap/dcae/TestingUtilities.java +++ b/src/test/java/org/onap/dcae/TestingUtilities.java @@ -19,25 +19,20 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcae; import static java.nio.file.Files.readAllBytes; import static org.assertj.core.api.Assertions.assertThat; import io.vavr.control.Try; - import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; - +import javax.net.ssl.SSLContext; import org.apache.http.client.HttpClient; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.HttpClients; @@ -48,7 +43,7 @@ import org.json.JSONObject; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -import javax.net.ssl.SSLContext; + public final class TestingUtilities { @@ -56,21 +51,41 @@ public final class TestingUtilities { // utility class, no objects allowed } - public static void assertJSONObjectsEqual(JSONObject o1, JSONObject o2) { + /** + * Assert if JSON Objects are Equal. + * @param o1 JSONObject one. + * @param o2 JSONObject two. + */ + public static void assertJsonObjectsEqual(JSONObject o1, JSONObject o2) { assertThat(o1.toString()).isEqualTo(o2.toString()); } - public static JSONObject readJSONFromFile(Path path) { + /** + * Read JSON From File. + * @param path path of file. + * @return JSON Object. + */ + public static JSONObject readJsonFromFile(Path path) { return rethrow(() -> new JSONObject(readFile(path))); } + /** + * Read File from givn path. + * @param path path of file. + * @return String content. + */ public static String readFile(Path path) { return rethrow(() -> new String(readAllBytes(path))); } - public static Path createTemporaryFile(String content) { + /** + * Create Temporary File. + * @param content content of file. + * @return Path. + */ + public static Path createTemporaryFile(String name, String content) { return rethrow(() -> { - File temp = File.createTempFile("restconf-collector-tests-created-this-file", ".tmp"); + File temp = File.createTempFile(name, ".tmp"); temp.deleteOnExit(); Path filePath = Paths.get(temp.toString()); Files.write(filePath, content.getBytes()); @@ -82,6 +97,7 @@ public final class TestingUtilities { * Exception in test case usually means there is something wrong, it should never be catched, but rather thrown to * be handled by JUnit framework. */ + public static <T> T rethrow(CheckedSupplier<T> supplier) { try { return supplier.get(); @@ -90,21 +106,36 @@ public final class TestingUtilities { } } + /** + * + * @param <T> . + */ @FunctionalInterface interface CheckedSupplier<T> { T get() throws Exception; } + /** Assert if Failure Has Info. + * + * @param any any object + * @param msgPart msg part + */ public static void assertFailureHasInfo(Try any, String... msgPart) { Java6Assertions.assertThat(any.isFailure()).isTrue(); - AbstractThrowableAssert<?, ? extends Throwable> o = Java6Assertions.assertThat(any.getCause()) + AbstractThrowableAssert<?, ? extends Throwable> instance = Java6Assertions.assertThat(any.getCause()) .hasCauseInstanceOf(Exception.class); for (String s : msgPart) { - o.hasStackTraceContaining(s); + instance.hasStackTraceContaining(s); } } + /** + * SSL Builder With TrustStore. + * @param trustStore path of file. + * @param pass password. + * @return SSLContextBuilder. + */ public static SSLContextBuilder sslBuilderWithTrustStore(final Path trustStore, final String pass) { return rethrow(() -> new SSLContextBuilder() @@ -112,6 +143,13 @@ public final class TestingUtilities { ); } + /** + * Configure Key Store for testing. + * @param builder class builder. + * @param keyStore path of file. + * @param pass password. + * @return SSLContextBuilder. + */ public static SSLContextBuilder configureKeyStore( final SSLContextBuilder builder, final Path keyStore, @@ -126,6 +164,11 @@ public final class TestingUtilities { }); } + /** + * Create Rest Template With Ssl. + * @param context ssl context + * @return RestTemplate + */ public static RestTemplate createRestTemplateWithSsl(final SSLContext context) { final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(context); final HttpClient httpClient = HttpClients |