summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml7
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java9
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java9
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java50
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/TestResourcesUtil.java103
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/YamlTestUtil.java3
6 files changed, 57 insertions, 124 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml
index f1e0ae5b4c..5067c4a7c8 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml
@@ -25,6 +25,13 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.openecomp.sdc.be</groupId>
+ <artifactId>common-be</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java
index cb901b6f3c..b57bf74571 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java
@@ -29,22 +29,25 @@ import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TO_
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.junit.Test;
import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
import org.openecomp.core.converter.pnfd.model.ConversionStrategyType;
-import org.openecomp.core.util.TestResourcesUtil;
import org.openecomp.core.util.YamlTestUtil;
+import org.openecomp.sdc.be.test.util.TestResourcesHandler;
public class ConversionDefinitionYamlParserTest {
@Test
public void shouldBuildDefinition() {
final Map<String, Object> definitionYaml;
- final String definitionYamlFilePath = "transformation/conversionDefinition/conversionDefinitionWithReplaceStrategy.yaml";
- try (final InputStream resourceInputStream = TestResourcesUtil.getFileResourceAsStream(definitionYamlFilePath)) {
+ final Path definitionYamlFilePath =
+ Paths.get("transformation", "conversionDefinition", "conversionDefinitionWithReplaceStrategy.yaml");
+ try (final InputStream resourceInputStream = TestResourcesHandler.getResourceAsStream(definitionYamlFilePath)) {
definitionYaml = (Map<String, Object>) YamlTestUtil.read(resourceInputStream);
} catch (final IOException e) {
fail(String.format("Could not load %s", definitionYamlFilePath));
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java
index 1eab214980..18d10436be 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java
@@ -25,20 +25,23 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Map;
import java.util.Optional;
import org.junit.Test;
import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
-import org.openecomp.core.util.TestResourcesUtil;
import org.openecomp.core.util.YamlTestUtil;
+import org.openecomp.sdc.be.test.util.TestResourcesHandler;
public class PnfdConversionStrategyYamlParserTest {
@Test
public void parseInvalidYamlObject() {
final Object replaceStrategyYaml;
- final String strategyYamlFilePath = "transformation/strategy/strategyMissingStrategyAttribute.yaml";
- try (final InputStream resourceInputStream = TestResourcesUtil.getFileResourceAsStream(strategyYamlFilePath)) {
+ final Path strategyYamlFilePath =
+ Paths.get("transformation", "strategy", "strategyMissingStrategyAttribute.yaml");
+ try (final InputStream resourceInputStream = TestResourcesHandler.getResourceAsStream(strategyYamlFilePath)) {
replaceStrategyYaml = YamlTestUtil.read(resourceInputStream);
} catch (final IOException e) {
fail(String.format("Could not load %s", strategyYamlFilePath));
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java
index 30cba677f2..fe0d5a8620 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java
@@ -22,8 +22,10 @@ package org.openecomp.core.impl;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
-import static org.openecomp.core.util.TestResourcesUtil.getResourceBytesOrFail;
+import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -39,7 +41,7 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage;
public class ToscaDefinitionImportHandlerTest {
- private static final String RESOURCES_FILE_PATH = "/toscaDefinitionImportHandler/";
+ private static final Path RESOURCES_FILE_PATH = Paths.get("toscaDefinitionImportHandler");
private Map<String, byte[]> descriptorFileMap;
@Before
@@ -56,7 +58,9 @@ public class ToscaDefinitionImportHandlerTest {
"Definitions/descriptorWithRelativePaths.yaml", "Artifacts/descriptorWithAbsolutePaths.yaml",
"Artifacts/descriptorCyclicReference.yaml");
- filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH + file)));
+ filesToHandleList.forEach(file ->
+ descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file)))
+ );
final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler(
descriptorFileMap,
@@ -108,7 +112,9 @@ public class ToscaDefinitionImportHandlerTest {
final List<String> filesToHandleList = Arrays.asList("Definitions/Main.yaml",
"Definitions/descriptorBasicImport.yaml", "Definitions/descriptorWithRelativePaths.yaml",
"Artifacts/descriptorWithAbsolutePaths.yaml");
- filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH + file)));
+ filesToHandleList.forEach(file ->
+ descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file)))
+ );
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR,
@@ -140,7 +146,9 @@ public class ToscaDefinitionImportHandlerTest {
final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile,
"Definitions/descriptorInvalidImportStatement.yaml");
- filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH + file)));
+ filesToHandleList.forEach(file ->
+ descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file)))
+ );
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR,
@@ -172,7 +180,9 @@ public class ToscaDefinitionImportHandlerTest {
final String invalidMainDefinitionFilePath = "../Definitions/InvalidMainDefinitionFile.yaml";
final List<String> filesToHandleList = Arrays.asList(mainDefinitionFilePath);
- filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH + file)));
+ filesToHandleList.forEach(file ->
+ descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file)))
+ );
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, Messages.MISSING_IMPORT_FILE.formatMessage(invalidMainDefinitionFilePath)));
@@ -200,7 +210,9 @@ public class ToscaDefinitionImportHandlerTest {
final String mainDefinitionFile = "Definitions/descriptorInvalid.yaml";
final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile);
- filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH + file)));
+ filesToHandleList.forEach(file ->
+ descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file)))
+ );
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, String.format(Messages.INVALID_YAML_FORMAT.getErrorMessage()
@@ -236,7 +248,9 @@ public class ToscaDefinitionImportHandlerTest {
final String mainDefinitionFile = "Definitions/descriptorFileWithValidImportStatements.yaml";
final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile, "Artifacts/descriptorCyclicReference.yaml");
- filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH + file)));
+ filesToHandleList.forEach(file ->
+ descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file)))
+ );
final ToscaDefinitionImportHandler toscaDefinitionImportHandler =
new ToscaDefinitionImportHandler(descriptorFileMap, mainDefinitionFile);
@@ -258,17 +272,25 @@ public class ToscaDefinitionImportHandlerTest {
public void testGivenDescriptorFileWithNonexistentRelativeImport_whenIncorrectMainDescriptorIsHandled_aMissingFileErrorIsReported() {
final String mainDefinitionFile = "Definitions/MainWithNonexistentReferences.yaml";
- final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile, "Definitions/descriptorNonexistentImport.yaml",
- "Artifacts/descriptorCyclicReference.yaml");
- filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH + file)));
+ final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile,
+ "Definitions/descriptorNonexistentImport.yaml", "Artifacts/descriptorCyclicReference.yaml");
+ filesToHandleList.forEach(file ->
+ descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file)))
+ );
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR,
- String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), "Definitions/descriptorCyclicReference.yaml")));
+ String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(),
+ "Definitions/descriptorCyclicReference.yaml"))
+ );
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR,
- String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), "Definitions/descriptorCyclicReference.yaml")));
+ String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(),
+ "Definitions/descriptorCyclicReference.yaml"))
+ );
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR,
- String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), "Definitions/descriptorCyclicReference.yaml")));
+ String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(),
+ "Definitions/descriptorCyclicReference.yaml"))
+ );
final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler(
descriptorFileMap,
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
deleted file mode 100644
index 7d89bb3eab..0000000000
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/util/TestResourcesUtil.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * ============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.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;
-
-/**
- * Test resources utility class.
- */
-public class TestResourcesUtil {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(TestResourcesUtil.class);
-
- private TestResourcesUtil() {
-
- }
-
- /**
- * Reads a file and coverts it to a byte array.
- *
- * @param resourcePath The resource file path
- * @return
- * The resource file byte array
- * @throws IOException
- * When the file was not found or the input stream could not be opened
- */
- 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));
- }
- return IOUtils.toByteArray(inputStream);
- } catch (final IOException ex) {
- throw new IOException(String.format("Could not open the input stream for resource on path \"%s\"", resourcePath), ex);
- }
- }
-
- /**
- * Reads a file in the given path.
- * The method forces an assertion fail if the resource could not be loaded.
- * @param resourcePath The resource file path
- * @return
- * The resource file byte array
- */
- public static byte[] getResourceBytesOrFail(final String resourcePath) {
- try {
- return getFileResourceBytes(resourcePath);
- } catch (final IOException e) {
- final String errorMsg = String.format("Could not load resource '%s'", resourcePath);
- LOGGER.error(errorMsg, e);
- fail(errorMsg);
- }
-
- 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
index b095d13ed7..3229c1ce46 100644
--- 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
@@ -26,6 +26,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.sdc.be.test.util.TestResourcesHandler;
public class YamlTestUtil {
@@ -45,7 +46,7 @@ public class YamlTestUtil {
}
public static Object read(final String yamlFilePath) throws IOException {
- try (final InputStream resourceInputStream = TestResourcesUtil.getFileResourceAsStream(yamlFilePath)) {
+ try (final InputStream resourceInputStream = TestResourcesHandler.getResourceAsStream(yamlFilePath)) {
return read(resourceInputStream);
}
}