aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2019-11-08 10:53:56 +0000
committerOren Kleks <oren.kleks@amdocs.com>2019-11-10 06:50:57 +0000
commit57a8c14ed7b5ef6b39b7e63e76d14dfcac32fb69 (patch)
tree6515dbe523e20375fbb4a661c0e4b68624bd8ea5 /openecomp-be/lib
parent3042f71ec5761450e46a3f22c3eb46a117771145 (diff)
Fix sonarQube issue.
Issue-ID: SDC-2646 Change-Id: Ic426e1cccf50e3db40381896ee50b74e647129ee Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java7
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/pom.xml12
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java3
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java5
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java28
-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.java8
6 files changed, 60 insertions, 3 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java
index a3f7ca0626..ff3e19bd1b 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java
@@ -27,6 +27,8 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
/**
* Represents a transformation from the PNFD transformation descriptor.
@@ -35,6 +37,8 @@ import org.apache.commons.lang3.StringUtils;
@Setter
public class Transformation {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Transformation.class);
+
private String name;
private String description;
private TransformationBlock block;
@@ -90,7 +94,8 @@ public class Transformation {
try {
T value = clazz.cast(transformationProperty.get().getValue());
return Optional.of(value);
- } catch (final ClassCastException ignored) {
+ } catch (final ClassCastException e) {
+ LOGGER.warn("Could not get property value.", e);
return Optional.empty();
}
}
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 6f6dd19ad8..f1e0ae5b4c 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
@@ -41,6 +41,18 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit</artifactId>
+ <version>${jmockit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${mockito.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<parent>
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java
index b2038a00dd..3c996462fe 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java
@@ -81,6 +81,9 @@ public class PnfdNodeTemplateTransformationEngine extends AbstractPnfdTransforma
*/
@Override
protected void executeTransformations() {
+ if (transformationDescription == null) {
+ return;
+ }
final Set<Transformation> transformationSet = transformationDescription.getTransformationSet();
if (CollectionUtils.isEmpty(transformationSet)) {
return;
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java
index 6ad04b0f7a..92e1d8f392 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java
@@ -181,8 +181,9 @@ public class TransformationYamlParser {
private static Optional<String> parseStringAttribute(final String attribute, final Map<String, Object> transformationYaml) {
try {
return Optional.of((String) transformationYaml.get(attribute));
- } catch (final Exception ignore) {
- LOGGER.warn("Could not parse the String '{}' in transformation '{}'", attribute, transformationYaml.toString());
+ } catch (final Exception e) {
+ LOGGER.warn("Could not parse the String '{}' in transformation '{}'",
+ attribute, transformationYaml.toString(), e);
return Optional.empty();
}
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java
index be13d775e3..63a7d890d0 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java
@@ -20,6 +20,8 @@
package org.openecomp.core.converter.impl.pnfd;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.spy;
import java.io.IOException;
import java.io.InputStream;
@@ -27,17 +29,24 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import mockit.Deencapsulation;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
+import org.mockito.Mockito;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.converter.impl.pnfd.parser.PnfdCustomNodeTypeBlockParser;
import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
+import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
@RunWith(Parameterized.class)
@@ -79,6 +88,25 @@ public class PnfTransformationEngineTest {
assertEquals(expectedResult, result);
}
+ @Test
+ public void testBuildParseBlock() {
+ final PnfdCustomNodeTypeBlockParser blockParser = spy(new PnfdCustomNodeTypeBlockParser(null));
+ final ConversionDefinition conversionDefinition = Mockito.mock(ConversionDefinition.class);
+ final Map<String, Object> stringObjectMap = new HashMap<>();
+ stringObjectMap.put("type", null);
+ stringObjectMap.put("name", null);
+ assertEquals(Optional.empty(), Deencapsulation.invoke(blockParser, "buildParsedBlock",
+ stringObjectMap, stringObjectMap, conversionDefinition));
+ }
+
+ @Test
+ public void testReadDefinition() {
+ final PnfdTransformationEngine engine = spy(
+ new PnfdNodeTemplateTransformationEngine(null, null, "test.txt"));
+ Deencapsulation.invoke(engine, "readDefinition");
+ assertNull(Deencapsulation.getField(engine, "transformationDescription"));
+ }
+
private String getExpectedResultFor(final String inputFilename) throws IOException {
try (final InputStream inputStream = getOutputFileResourceCorrespondingTo(inputFilename)) {
final ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(inputStream, ServiceTemplate.class);
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 2326318657..cb901b6f3c 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
@@ -21,6 +21,7 @@ package org.openecomp.core.converter.impl.pnfd.parser;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.QUERY;
@@ -28,7 +29,9 @@ import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TO_
import java.io.IOException;
import java.io.InputStream;
+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;
@@ -51,6 +54,11 @@ public class ConversionDefinitionYamlParserTest {
assertConversionDefinition(definitionYaml, conversionDefinition);
}
+ @Test
+ public void shouldReturnEmpty() {
+ assertEquals(Optional.empty(), ConversionDefinitionYamlParser.parse(new HashMap<>()));
+ }
+
private void assertConversionDefinition(final Map<String, Object> definitionYaml,
final ConversionDefinition conversionDefinition) {
assertThat("The conversion definition should have been built"