aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/TestResourcesUtil.java27
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/YamlTestUtil.java67
2 files changed, 92 insertions, 2 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/TestResourcesUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/TestResourcesUtil.java
index 34559f5386..7d89bb3eab 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/TestResourcesUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/TestResourcesUtil.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import org.apache.commons.io.IOUtils;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
@@ -47,7 +48,7 @@ public class TestResourcesUtil {
* @throws IOException
* When the file was not found or the input stream could not be opened
*/
- public static byte[] getFileResource(final String resourcePath) throws IOException {
+ public static byte[] getFileResourceBytes(final String resourcePath) throws IOException {
try(final InputStream inputStream = ClassLoader.class.getResourceAsStream(resourcePath)) {
if (inputStream == null) {
throw new IOException(String.format("Could not find the resource on path \"%s\"", resourcePath));
@@ -67,7 +68,7 @@ public class TestResourcesUtil {
*/
public static byte[] getResourceBytesOrFail(final String resourcePath) {
try {
- return getFileResource(resourcePath);
+ return getFileResourceBytes(resourcePath);
} catch (final IOException e) {
final String errorMsg = String.format("Could not load resource '%s'", resourcePath);
LOGGER.error(errorMsg, e);
@@ -77,4 +78,26 @@ public class TestResourcesUtil {
return null;
}
+ /**
+ * Gets the input stream of a resource file
+ *
+ * @param resourcePath The resource file path
+ * @return
+ * The resource input stream
+ */
+ public static InputStream getFileResourceAsStream(final String resourcePath) {
+ return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
+ }
+
+ /**
+ * Gets the input stream of a resource file
+ *
+ * @param resourcePath The resource file path
+ * @return
+ * The resource input stream
+ */
+ public static URL getFileUrl(final String resourcePath) {
+ return Thread.currentThread().getContextClassLoader().getResource(resourcePath);
+ }
+
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/YamlTestUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/YamlTestUtil.java
new file mode 100644
index 0000000000..b095d13ed7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/YamlTestUtil.java
@@ -0,0 +1,67 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.util;
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.onap.sdc.tosca.services.YamlUtil;
+
+public class YamlTestUtil {
+
+ private YamlTestUtil() {
+ }
+
+ /**
+ * Reads the description file that has the required YAML format.
+ *
+ * @param yamlFile The yaml file
+ * @return The yaml parsed to Object
+ */
+ public static Object read(final File yamlFile) throws IOException {
+ try (final InputStream fileInputStream = new FileInputStream(yamlFile)) {
+ return read(fileInputStream);
+ }
+ }
+
+ public static Object read(final String yamlFilePath) throws IOException {
+ try (final InputStream resourceInputStream = TestResourcesUtil.getFileResourceAsStream(yamlFilePath)) {
+ return read(resourceInputStream);
+ }
+ }
+
+ public static Object read(final InputStream yamlFileInputStream) {
+ return YamlUtil.read(yamlFileInputStream);
+ }
+
+ public static Object readOrFail(final String yamlFilePath) {
+ try {
+ return read(yamlFilePath);
+ } catch (final IOException ignored) {
+ fail(String.format("Could not load '%s'", yamlFilePath));
+ return null;
+ }
+ }
+
+
+}