summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/pom.xml7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareInformation.java68
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareVersion.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParser.java89
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java34
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java59
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java4
-rw-r--r--catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information.yaml8
9 files changed, 21 insertions, 299 deletions
diff --git a/catalog-be/pom.xml b/catalog-be/pom.xml
index 1318866d5a..a0a6fde6ef 100644
--- a/catalog-be/pom.xml
+++ b/catalog-be/pom.xml
@@ -76,6 +76,13 @@
</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.openecomp.sdc.be</groupId>
<artifactId>catalog-dao</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareInformation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareInformation.java
deleted file mode 100644
index 8595fc9698..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareInformation.java
+++ /dev/null
@@ -1,68 +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.sdc.be.components.csar;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-import lombok.AccessLevel;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Represents the Pnf software information non-mano yaml
- */
-@Getter
-@Setter
-public class PnfSoftwareInformation {
-
- private String description;
- private String provider;
- private String version;
- @Setter(AccessLevel.NONE)
- private Set<PnfSoftwareVersion> softwareVersionSet = new LinkedHashSet<>();
-
- /**
- * Adds a {@link PnfSoftwareVersion} instance to the software version set
- * @param softwareVersion the pnf software version to add
- */
- public void addToSoftwareVersionSet(final PnfSoftwareVersion softwareVersion) {
- softwareVersionSet.add(softwareVersion);
- }
-
- public Set<PnfSoftwareVersion> getSoftwareVersionSet() {
- return new LinkedHashSet<>(softwareVersionSet);
- }
-
- /**
- * Stores the software information yaml field names.
- */
- @AllArgsConstructor
- @Getter
- public enum PnfSoftwareInformationField {
- DESCRIPTION("description"),
- PROVIDER("provider"),
- VERSION("version"),
- PNF_SOFTWARE_INFORMATION("pnf_software_information");
-
- private final String fieldName;
-
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareVersion.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareVersion.java
deleted file mode 100644
index 0dc4679e53..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareVersion.java
+++ /dev/null
@@ -1,45 +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.sdc.be.components.csar;
-
-import lombok.AllArgsConstructor;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-
-@AllArgsConstructor
-@EqualsAndHashCode
-@Getter
-public class PnfSoftwareVersion {
-
- private final String version;
- private final String description;
-
- /**
- * Stores the pnf software version yaml fields.
- */
- @Getter
- @AllArgsConstructor
- public enum PnfSoftwareVersionField {
- DESCRIPTION("description"),
- PNF_SOFTWARE_VERSION("pnf_software_version");
-
- private final String fieldName;
- }
-} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParser.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParser.java
deleted file mode 100644
index ec34e21945..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParser.java
+++ /dev/null
@@ -1,89 +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.sdc.be.components.csar;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import org.apache.commons.collections.CollectionUtils;
-import org.onap.sdc.tosca.services.YamlUtil;
-import org.openecomp.sdc.be.components.csar.PnfSoftwareInformation.PnfSoftwareInformationField;
-import org.openecomp.sdc.be.components.csar.PnfSoftwareVersion.PnfSoftwareVersionField;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.error.YAMLException;
-
-/**
- * Handles the parsing of the non-mano software information file.
- */
-public class SoftwareInformationArtifactYamlParser {
- private static final Logger LOGGER = LoggerFactory.getLogger(SoftwareInformationArtifactYamlParser.class);
-
- private SoftwareInformationArtifactYamlParser() {
-
- }
-
- /**
- * Parses the non-mano software information yaml file.
- *
- * @param softwareInformationYamlFileBytes the file byte array
- * @return an {@code Optional<PnfSoftwareInformation>} if the file was successful parsed, otherwise {@code
- * Optional.empty()}
- */
- @SuppressWarnings("unchecked")
- public static Optional<PnfSoftwareInformation> parse(final byte[] softwareInformationYamlFileBytes) {
- final Map<String, Object> softwareVersionYamlObject;
- try (final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(softwareInformationYamlFileBytes)) {
- final Object yaml = YamlUtil.read(byteArrayInputStream);
- if (!(yaml instanceof Map)) {
- return Optional.empty();
- }
-
- softwareVersionYamlObject = (Map<String, Object>) yaml; // unchecked warning suppressed
- } catch (final IOException | YAMLException e) {
- LOGGER.warn("Could not parse the software information yaml file", e);
- return Optional.empty();
- }
-
- final PnfSoftwareInformation pnfSoftwareInformation = new PnfSoftwareInformation();
- pnfSoftwareInformation.setDescription(
- (String) softwareVersionYamlObject.get(PnfSoftwareInformationField.DESCRIPTION.getFieldName()));
- pnfSoftwareInformation.setProvider(
- (String) softwareVersionYamlObject.get(PnfSoftwareInformationField.PROVIDER.getFieldName()));
- pnfSoftwareInformation.setVersion(
- (String) softwareVersionYamlObject.get(PnfSoftwareInformationField.VERSION.getFieldName()));
- final List<Map<String, String>> pnfSoftwareInformationYaml = (List<Map<String, String>>) softwareVersionYamlObject
- .get(PnfSoftwareInformationField.PNF_SOFTWARE_INFORMATION.getFieldName()); // unchecked warning suppressed
-
- if (CollectionUtils.isNotEmpty(pnfSoftwareInformationYaml)) {
- pnfSoftwareInformationYaml.forEach(stringStringMap -> {
- final String description = stringStringMap.get(PnfSoftwareVersionField.DESCRIPTION.getFieldName());
- final String version = stringStringMap.get(PnfSoftwareVersionField.PNF_SOFTWARE_VERSION.getFieldName());
- pnfSoftwareInformation.addToSoftwareVersionSet(new PnfSoftwareVersion(version, description));
- });
- }
-
- return Optional.of(pnfSoftwareInformation);
- }
-
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java
index 9355921252..3129befb8c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java
@@ -26,9 +26,9 @@ import java.util.List;
import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.components.csar.CsarInfo;
-import org.openecomp.sdc.be.components.csar.PnfSoftwareInformation;
-import org.openecomp.sdc.be.components.csar.PnfSoftwareVersion;
-import org.openecomp.sdc.be.components.csar.SoftwareInformationArtifactYamlParser;
+import org.openecomp.sdc.be.csar.pnf.PnfSoftwareInformation;
+import org.openecomp.sdc.be.csar.pnf.PnfSoftwareVersion;
+import org.openecomp.sdc.be.csar.pnf.SoftwareInformationArtifactYamlParser;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
index 809dc7ddb0..cb0e5e8a9b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
@@ -20,36 +20,20 @@
package org.openecomp.sdc;
-import org.apache.commons.io.IOUtils;
+import static org.junit.Assert.assertArrayEquals;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
import java.io.InputStream;
-
-import static org.junit.Assert.assertArrayEquals;
+import javax.ws.rs.core.Response;
+import org.apache.commons.io.IOUtils;
public class TestUtils {
- public static boolean downloadedPayloadMatchesExpected(Response response, byte[] expected) {
- boolean result = false;
- try (InputStream is = response.readEntity(InputStream.class)) {
- byte[] body = IOUtils.toByteArray(is);
+ public static boolean downloadedPayloadMatchesExpected(final Response response, final byte[] expected) {
+ try (final InputStream is = response.readEntity(InputStream.class)) {
+ final byte[] body = IOUtils.toByteArray(is);
assertArrayEquals(expected, body);
- result = true;
- } catch(Exception ex) {
- result = false;
- }
- return result;
- }
-
- public static InputStream getResourceAsStream(final String resourcePath) {
- return TestUtils.class.getClassLoader().getResourceAsStream(resourcePath);
- }
-
- public static byte[] getResourceAsByteArray(final String resourcePath) throws IOException {
- final InputStream resourceAsStream = getResourceAsStream(resourcePath);
- if (resourceAsStream == null) {
- throw new IOException("Could not find file: " + resourcePath);
+ return true;
+ } catch (final Exception ignored) {
+ return false;
}
- return IOUtils.toByteArray(resourceAsStream);
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java
deleted file mode 100644
index 6f826047a4..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java
+++ /dev/null
@@ -1,59 +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.sdc.be.components.csar;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.io.IOException;
-import java.util.Optional;
-import org.junit.Test;
-import org.openecomp.sdc.TestUtils;
-
-public class SoftwareInformationArtifactYamlParserTest {
-
- @Test
- public void parse() throws IOException {
- //given
- final byte[] resourceAsByteArray = TestUtils
- .getResourceAsByteArray("artifacts/pnfSoftwareInformation/pnf-sw-information.yaml");
- //when
- final Optional<PnfSoftwareInformation> pnfSoftwareInformation = SoftwareInformationArtifactYamlParser
- .parse(resourceAsByteArray);
- //then
- final PnfSoftwareVersion expectedPnfSoftwareVersion1 = new PnfSoftwareVersion("version1", "first software version of PNF");
- final PnfSoftwareVersion expectedPnfSoftwareVersion2 = new PnfSoftwareVersion("version2", "second software version of PNF");
- assertThat("The software information should be parsed", pnfSoftwareInformation.isPresent(), is(true));
- pnfSoftwareInformation.ifPresent(softwareInformation -> {
- assertThat("The software information provider should be as expected",
- softwareInformation.getProvider(), is(equalTo("Ericsson")));
- assertThat("The software information description should be as expected",
- softwareInformation.getDescription(), is(equalTo("pnf software information")));
- assertThat("The software information version should be as expected",
- softwareInformation.getVersion(), is(equalTo("1.0")));
- assertThat("The software versions should contain expected versions",
- softwareInformation.getSoftwareVersionSet(),
- hasItems(expectedPnfSoftwareVersion1, expectedPnfSoftwareVersion2));
- });
- }
-
-} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java
index 2eda76fa16..99bccfc566 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java
@@ -34,11 +34,11 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.TestUtils;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.test.util.TestResourcesHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -148,7 +148,7 @@ public class SoftwareInformationBusinessLogicTest {
private void mockCsarFileMap(final String softwareInformationArtifactPath) {
final byte[] softwareInformationFile;
try {
- softwareInformationFile = TestUtils.getResourceAsByteArray(softwareInformationArtifactPath);
+ softwareInformationFile = TestResourcesHandler.getResourceAsByteArray(softwareInformationArtifactPath);
} catch (final IOException e) {
final String errorMsg = "Could not find software information artifact " + softwareInformationArtifactPath;
LOGGER.error(errorMsg, e);
diff --git a/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information.yaml b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information.yaml
deleted file mode 100644
index 31f4bc6173..0000000000
--- a/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-description: "pnf software information"
-provider: "Ericsson"
-version: "1.0"
-pnf_software_information:
- - description: "first software version of PNF"
- pnf_software_version: "version1"
- - description: "second software version of PNF"
- pnf_software_version: "version2"