aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2019-10-08 18:27:36 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-11-20 17:23:14 +0000
commit13af621442b4c74d9e63ede8e42dbae48aaa64c9 (patch)
tree93b192acc70f6b9eed7fba41402bf33bf9970442
parent86655742cf36bdc056837f5b74bc32c58201a600 (diff)
Onboard PNF software version
Change-Id: Id9e32e01f6c2f4c39c8ff10816d982cbb3063bf7 Issue-ID: SDC-2589 Signed-off-by: andre.schmid <andre.schmid@est.tech>
-rw-r--r--catalog-be/pom.xml3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java88
-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/PropertyBusinessLogic.java122
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java61
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java129
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/BusinessLogicException.java32
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java191
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java226
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java36
-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/ResourceBusinessLogicMockitoTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java173
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java6
-rw-r--r--catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/invalid.yaml4
-rw-r--r--catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-corrupt.yaml1
-rw-r--r--catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-1.yaml6
-rw-r--r--catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-2.yaml6
-rw-r--r--catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-3.yaml7
-rw-r--r--catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information.yaml8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java63
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java36
-rw-r--r--common-be/pom.xml17
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/config/NonManoArtifactType.java (renamed from openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/NonManoArtifactType.java)2
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java42
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfigurationManager.java68
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java35
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/config/exception/LoadConfigurationException.java31
-rw-r--r--common-be/src/main/resources/config/nonManoConfig.yaml (renamed from openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/resources/nonManoConfig.yaml)0
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/config/NonManoConfigurationManagerTest.java50
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java4
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java8
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java6
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/Configuration.java30
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java38
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/NonManoType.java29
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java5
-rw-r--r--test-apis-ci/sdc-api-tests/chef-repo/cookbooks/sdc-api-tests/files/default/Files/PNFs/sample-pnf-1.0.1-non-mano-software-information.csarbin0 -> 24623 bytes
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/sanity/Onboard.java53
43 files changed, 1429 insertions, 472 deletions
diff --git a/catalog-be/pom.xml b/catalog-be/pom.xml
index 8248727949..1318866d5a 100644
--- a/catalog-be/pom.xml
+++ b/catalog-be/pom.xml
@@ -658,6 +658,9 @@
<include>src/main/resources/**/*.y*ml</include>
<include>src/test/resources/**/*.y*ml</include>
</includes>
+ <excludes>
+ <exclude>src/test/resources/artifacts/pnfSoftwareInformation/**</exclude>
+ </excludes>
</validationSet>
<validationSet>
<includes>
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
index 1d49394b17..05c36b3ae0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
@@ -21,9 +21,17 @@
*/
package org.openecomp.sdc.be.components.csar;
+import com.google.common.annotations.VisibleForTesting;
import fj.data.Either;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.NonManoArtifactType;
+import org.openecomp.sdc.be.config.NonManoConfiguration;
+import org.openecomp.sdc.be.config.NonManoConfigurationManager;
+import org.openecomp.sdc.be.config.NonManoFolderType;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Resource;
@@ -42,17 +50,31 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.*;
public class CsarInfo {
private static final Logger log = Logger.getLogger(CsarInfo.class);
+ @Getter
+ @Setter
private String vfResourceName;
+ @Getter
+ @Setter
private User modifier;
+ @Getter
+ @Setter
private String csarUUID;
+ @Getter
+ @Setter
private Map<String, byte[]> csar;
+ @Getter
private String mainTemplateName;
+ @Getter
private String mainTemplateContent;
+ @Getter
private Map<String, Object> mappedToscaMainTemplate;
+ @Getter
private Map<String, String> createdNodesToscaResourceNames;
private Queue<String> cvfcToCreateQueue;
private boolean isUpdate;
+ @Getter
private Map<String, Resource> createdNodes;
+ private final NonManoConfiguration nonManoConfiguration;
@SuppressWarnings("unchecked")
public CsarInfo(User modifier, String csarUUID, Map<String, byte[]> csar, String vfResourceName, String mainTemplateName, String mainTemplateContent, boolean isUpdate){
@@ -67,46 +89,12 @@ public class CsarInfo {
this.cvfcToCreateQueue = new PriorityQueue<>();
this.isUpdate = isUpdate;
this.createdNodes = new HashMap<>();
+ this.nonManoConfiguration = NonManoConfigurationManager.getInstance().getNonManoConfiguration();
}
- public String getVfResourceName() {
- return vfResourceName;
- }
-
- public void setVfResourceName(String vfResourceName) {
- this.vfResourceName = vfResourceName;
- }
-
- public User getModifier() {
- return modifier;
- }
-
- public void setModifier(User modifier) {
- this.modifier = modifier;
- }
-
- public String getCsarUUID() {
- return csarUUID;
- }
-
- public void setCsarUUID(String csarUUID) {
- this.csarUUID = csarUUID;
- }
-
- public Map<String, byte[]> getCsar() {
- return csar;
- }
-
- public void setCsar(Map<String, byte[]> csar) {
- this.csar = csar;
- }
-
- public Map<String, Object> getMappedToscaMainTemplate() {
- return mappedToscaMainTemplate;
- }
-
- public Map<String, String> getCreatedNodesToscaResourceNames() {
- return createdNodesToscaResourceNames;
+ @VisibleForTesting
+ CsarInfo(final NonManoConfiguration nonManoConfiguration) {
+ this.nonManoConfiguration = nonManoConfiguration;
}
public void addNodeToQueue(String nodeName) {
@@ -132,10 +120,6 @@ public class CsarInfo {
this.isUpdate = isUpdate;
}
- public Map<String, Resource> getCreatedNodes() {
- return createdNodes;
- }
-
public Map<String,NodeTypeInfo> extractNodeTypesInfo() {
Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
List<Map.Entry<String, byte[]>> globalSubstitutes = new ArrayList<>();
@@ -236,11 +220,19 @@ public class CsarInfo {
}
}
- public String getMainTemplateName() {
- return mainTemplateName;
- }
-
- public String getMainTemplateContent() {
- return mainTemplateContent;
+ /**
+ * Gets the software information yaml path from the csar file map.
+ *
+ * @return the software information yaml path if it is present in the csar file map
+ */
+ public Optional<String> getSoftwareInformationPath() {
+ if (MapUtils.isEmpty(csar)) {
+ return Optional.empty();
+ }
+ final NonManoFolderType softwareInformationType =
+ nonManoConfiguration.getNonManoType(NonManoArtifactType.ONAP_SW_INFORMATION);
+ return csar.keySet().stream()
+ .filter(filePath -> filePath.startsWith(softwareInformationType.getPath()))
+ .findFirst();
}
}
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
new file mode 100644
index 0000000000..8595fc9698
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareInformation.java
@@ -0,0 +1,68 @@
+/*
+ * ============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
new file mode 100644
index 0000000000..0dc4679e53
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/PnfSoftwareVersion.java
@@ -0,0 +1,45 @@
+/*
+ * ============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
new file mode 100644
index 0000000000..ec34e21945
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParser.java
@@ -0,0 +1,89 @@
+/*
+ * ============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/PropertyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
index 950971ef0b..1391e205cd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
@@ -32,6 +32,7 @@ import javax.servlet.ServletContext;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -51,18 +52,21 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ToscaOperationException;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
import org.openecomp.sdc.be.model.tosca.validators.PropertyTypeValidator;
import org.openecomp.sdc.be.resources.data.EntryData;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
@@ -217,6 +221,75 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
}
/**
+ * Copies a list of properties to a component.
+ *
+ * @param component the component to add the copied properties
+ * @param propertiesToCopyList the properties to be copied
+ * @return the updated component with the copied properties.
+ * @throws ToscaOperationException when a problem happens during the copy operation
+ */
+ public Component copyPropertyToComponent(final Component component,
+ final List<PropertyDefinition> propertiesToCopyList) throws ToscaOperationException {
+ return copyPropertyToComponent(component, propertiesToCopyList, true);
+ }
+
+ /**
+ * Copies a list of properties to a component.
+ *
+ * @param component the component to add the copied properties
+ * @param propertiesToCopyList the properties to be copied
+ * @param refreshComponent refresh the component from database after update
+ * @return the component refreshed from database if refreshComponent is {@code true}, the same component reference
+ * otherwise
+ * @throws ToscaOperationException when a problem happens during the copy operation
+ */
+ public Component copyPropertyToComponent(final Component component,
+ final List<PropertyDefinition> propertiesToCopyList,
+ final boolean refreshComponent) throws ToscaOperationException {
+ if (CollectionUtils.isEmpty(propertiesToCopyList)) {
+ return component;
+ }
+
+ for (final PropertyDefinition propertyDefinition : propertiesToCopyList) {
+ copyPropertyToComponent(component, propertyDefinition);
+ }
+
+ if (refreshComponent) {
+ return toscaOperationFacade.getToscaElement(component.getUniqueId()).left().value();
+ }
+
+ return component;
+ }
+
+ /**
+ * Copies one property to a component.
+ *
+ * @param component the component to add the copied property
+ * @param propertyDefinition the property to be copied
+ * @throws ToscaOperationException when a problem happens during the copy operation
+ */
+ private void copyPropertyToComponent(final Component component,
+ final PropertyDefinition propertyDefinition) throws ToscaOperationException {
+ final PropertyDefinition copiedPropertyDefinition = new PropertyDefinition(propertyDefinition);
+ final String componentId = component.getUniqueId();
+ final String propertyName = copiedPropertyDefinition.getName();
+ copiedPropertyDefinition.setUniqueId(
+ UniqueIdBuilder.buildPropertyUniqueId(componentId, propertyName)
+ );
+ copiedPropertyDefinition.setParentUniqueId(componentId);
+ final Either<PropertyDefinition, StorageOperationStatus> operationResult = toscaOperationFacade
+ .addPropertyToComponent(propertyName, copiedPropertyDefinition, component);
+ if (operationResult.isRight()) {
+ final String error = String.format(
+ "Failed to add copied property '%s' to component '%s'. Operation status: '%s'",
+ propertyDefinition.getUniqueId(), componentId, operationResult.right().value()
+ );
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, PropertyBusinessLogic.class.getName(), "catalog-be", error);
+ throw new ToscaOperationException(error, operationResult.right().value());
+ }
+ }
+
+ /**
* Get property of component
*
* @param componentId
@@ -477,6 +550,55 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
}
+ /**
+ * Finds a component by id,
+ *
+ * @param componentId the component id to find
+ * @return an Optional<Component> if the component with given id was found, otherwise Optional.empty()
+ * @throws BusinessLogicException when a problem happens during the find operation
+ */
+ public Optional<Component> findComponentById(final String componentId) throws BusinessLogicException {
+ final Either<Component, StorageOperationStatus> status = toscaOperationFacade.getToscaElement(componentId);
+ if (status.isRight()) {
+ final StorageOperationStatus operationStatus = status.right().value();
+ if (operationStatus == StorageOperationStatus.NOT_FOUND) {
+ return Optional.empty();
+ }
+ final ResponseFormat responseFormat = componentsUtils.getResponseFormat(operationStatus);
+ throw new BusinessLogicException(responseFormat);
+ }
+ return Optional.ofNullable(status.left().value());
+ }
+
+ /**
+ * Updates a component property.
+ *
+ * @param componentId the component id that owns the property
+ * @param propertyDefinition the existing property to update
+ * @return the updated property
+ * @throws BusinessLogicException if the component was not found or if there was a problem during the update
+ * operation.
+ */
+ public PropertyDefinition updateComponentProperty(final String componentId,
+ final PropertyDefinition propertyDefinition)
+ throws BusinessLogicException {
+ final Component component = findComponentById(componentId).orElse(null);
+ if (component == null) {
+ throw new BusinessLogicException(
+ componentsUtils.getResponseFormatByResource(ActionStatus.RESOURCE_NOT_FOUND, componentId));
+ }
+ final Either<PropertyDefinition, StorageOperationStatus> updateResultEither =
+ toscaOperationFacade.updatePropertyOfComponent(component, propertyDefinition);
+ if (updateResultEither.isRight()) {
+ final ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
+ componentsUtils.convertFromStorageResponse(updateResultEither.right().value()), component.getName()
+ );
+ throw new BusinessLogicException(responseFormat);
+ }
+
+ return updateResultEither.left().value();
+ }
+
private boolean isPropertyExistInComponent(List<PropertyDefinition> properties, String propertyName) {
if(CollectionUtils.isEmpty(properties)) {
return false;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 12345e7802..bf848bf8f3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -33,6 +33,7 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStr
import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
+import fj.data.Either;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
@@ -48,8 +49,7 @@ import java.util.Set;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-
-import fj.data.Either;
+import javax.servlet.ServletContext;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -62,6 +62,7 @@ import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
@@ -131,6 +132,7 @@ import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ToscaOperationException;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
@@ -159,21 +161,23 @@ import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.context.WebApplicationContext;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
-import javax.servlet.ServletContext;
-
@org.springframework.stereotype.Component("resourceBusinessLogic")
public class ResourceBusinessLogic extends ComponentBusinessLogic {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ResourceBusinessLogic.class);
+
private static final String DELETE_RESOURCE = "Delete Resource";
private static final String IN_RESOURCE = " in resource {} ";
private static final String PLACE_HOLDER_RESOURCE_TYPES = "validForResourceTypes";
@@ -200,6 +204,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private final MergeInstanceUtils mergeInstanceUtils;
private final UiComponentDataConverter uiComponentDataConverter;
private final CsarBusinessLogic csarBusinessLogic;
+ private final PropertyBusinessLogic propertyBusinessLogic;
+ private final SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
@Autowired
public ResourceBusinessLogic(IElementOperation elementDao,
@@ -215,7 +221,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic,
CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic, MergeInstanceUtils mergeInstanceUtils,
UiComponentDataConverter uiComponentDataConverter, CsarBusinessLogic csarBusinessLogic,
- ArtifactsOperations artifactToscaOperation) {
+ ArtifactsOperations artifactToscaOperation, PropertyBusinessLogic propertyBusinessLogic,
+ SoftwareInformationBusinessLogic softwareInformationBusinessLogic) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation);
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
@@ -227,6 +234,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
this.mergeInstanceUtils = mergeInstanceUtils;
this.uiComponentDataConverter = uiComponentDataConverter;
this.csarBusinessLogic = csarBusinessLogic;
+ this.propertyBusinessLogic = propertyBusinessLogic;
+ this.softwareInformationBusinessLogic = softwareInformationBusinessLogic;
}
public LifecycleBusinessLogic getLifecycleBusinessLogic() {
@@ -1346,26 +1355,37 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
try {
log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
- Resource genericResource = fetchAndSetDerivedFromGenericType(resource);
- resource = createResourceTransaction(resource,
- csarInfo.getModifier(), isNormative);
+ final Resource genericResource = fetchAndSetDerivedFromGenericType(resource);
+ resource = createResourceTransaction(resource, csarInfo.getModifier(), isNormative);
log.trace("************* createResourceFromYaml after full create resource {}", yamlName);
log.trace("************* Going to add inputs from yaml {}", yamlName);
- if (resource.shouldGenerateInputs())
+ if (resource.shouldGenerateInputs()) {
generateAndAddInputsFromGenericTypeProperties(resource, genericResource);
-
- Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
+ }
+ final Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
resource = createInputsOnResource(resource, inputs);
log.trace("************* Finish to add inputs from yaml {}", yamlName);
+ if (resource.getResourceType() == ResourceTypeEnum.PNF) {
+ log.trace("************* Adding generic properties to PNF");
+ resource = (Resource) propertyBusinessLogic.copyPropertyToComponent(resource, genericResource.getProperties());
+ log.trace("************* Adding software information to PNF");
+ softwareInformationBusinessLogic.setSoftwareInformation(resource, csarInfo);
+ log.trace("************* Removing non-mano software information file from PNF");
+ if (csarInfo.getSoftwareInformationPath().isPresent() &&
+ !softwareInformationBusinessLogic.removeSoftwareInformationFile(csarInfo)) {
+ log.warn(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR , ResourceBusinessLogic.class.getName(),
+ "catalog-be", "Could not remove the software information file.");
+ }
+ }
Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo
.getInstances();
- log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
-
+ log.trace("************* Going to create nodes, Resource Instances and Relations from yaml {}", yamlName);
resource = createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap,
topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, nodeName);
- log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
+
+ log.trace("************* Finished to create nodes, Resource Instances and Relations from yaml {}", yamlName);
// validate update vf module group names
Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic
.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), resource.getSystemName());
@@ -1373,6 +1393,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value());
}
+
// add groups to resource
Map<String, GroupDefinition> groups;
log.trace("************* Going to add groups from yaml {}", yamlName);
@@ -1411,9 +1432,19 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ASDCKpiApi.countCreatedResourcesKPI();
return resource;
- } catch(ComponentException|StorageException e) {
+ } catch (final ComponentException | StorageException e) {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw e;
+ } catch (final ToscaOperationException e) {
+ LOGGER.error("An error has occurred during resource and resource instance creation", e);
+ rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR
+ , ResourceBusinessLogic.class.getName(), "catalog-be", e.getMessage());
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ } catch (final BusinessLogicException e) {
+ LOGGER.error("An error has occurred during resource and resource instance creation", e);
+ rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ throw new ByResponseFormatComponentException(e.getResponseFormat());
} finally {
if (!inTransaction) {
janusGraphDao.commit();
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
new file mode 100644
index 0000000000..9355921252
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java
@@ -0,0 +1,129 @@
+/*
+ * ============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.impl;
+
+import static java.util.stream.Collectors.toList;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
+
+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.components.impl.exceptions.BusinessLogicException;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component("softwareInformationBusinessLogic")
+public class SoftwareInformationBusinessLogic {
+
+ private final PropertyBusinessLogic propertyBusinessLogic;
+ private static final String SOFTWARE_VERSION_PROPERTY_NAME = "software_versions";
+
+ @Autowired
+ public SoftwareInformationBusinessLogic(final PropertyBusinessLogic propertyBusinessLogic) {
+ this.propertyBusinessLogic = propertyBusinessLogic;
+ }
+
+ /**
+ * Adds the software information from a csar package to the resource {@link SoftwareInformationBusinessLogic#SOFTWARE_VERSION_PROPERTY_NAME}
+ * property.<br/> The csar package must contain the expected non-mano yaml file with the software information. Also
+ * the resource must have the {@link SoftwareInformationBusinessLogic#SOFTWARE_VERSION_PROPERTY_NAME} property.
+ *
+ * @param resource the resource to add the software information
+ * @param csarInfo the csar package representation
+ * @return if the expected property exists in the resource and the csar package contains the software information
+ * file, an Optional<PropertyDefinition> with the updated property; otherwise Optional.empty().
+ * @throws BusinessLogicException when there was a problem while updating the property
+ */
+ public Optional<PropertyDefinition> setSoftwareInformation(final Resource resource,
+ final CsarInfo csarInfo) throws BusinessLogicException {
+ final Optional<String> softwareInformation = csarInfo.getSoftwareInformationPath();
+ if (!softwareInformation.isPresent()) {
+ return Optional.empty();
+ }
+ final PropertyDefinition propertyDefinition = findSoftwareVersionPropertyDefinition(resource).orElse(null);
+ if (propertyDefinition == null) {
+ return Optional.empty();
+ }
+ final byte[] softwareInformationYaml = csarInfo.getCsar().get(softwareInformation.get());
+ final PnfSoftwareInformation pnfSoftwareInformation =
+ parseSoftwareInformation(softwareInformationYaml).orElse(null);
+ if (pnfSoftwareInformation == null) {
+ return Optional.empty();
+ }
+
+ final List<String> versionList = pnfSoftwareInformation.getSoftwareVersionSet().stream()
+ .map(PnfSoftwareVersion::getVersion).collect(toList());
+ final String softwareVersionInformation =
+ getPropertyJsonStringValue(versionList, ToscaPropertyType.LIST.getType());
+ propertyDefinition.setValue(softwareVersionInformation);
+
+ final PropertyDefinition updatedPropertyDefinition =
+ propertyBusinessLogic.updateComponentProperty(resource.getUniqueId(), propertyDefinition);
+ return Optional.ofNullable(updatedPropertyDefinition);
+ }
+
+ /**
+ * Parses the non-mano software information yaml file.
+ *
+ * @param softwareInformationYaml the file byte array
+ * @return an {@code Optional<PnfSoftwareInformation>} if the file was successful parsed, otherwise {@code
+ * Optional.empty()}
+ */
+ private Optional<PnfSoftwareInformation> parseSoftwareInformation(byte[] softwareInformationYaml) {
+ return SoftwareInformationArtifactYamlParser.parse(softwareInformationYaml);
+ }
+
+ /**
+ * Finds the {@link SoftwareInformationBusinessLogic#SOFTWARE_VERSION_PROPERTY_NAME} property in a Resource
+ * @param resource the resource to search for the property
+ * @return an {@code Optional<PnfSoftwareInformation>} if the property was found, otherwise {@code Optional.empty()}
+ */
+ private Optional<PropertyDefinition> findSoftwareVersionPropertyDefinition(final Resource resource) {
+ if (CollectionUtils.isEmpty(resource.getProperties())) {
+ return Optional.empty();
+ }
+ return resource.getProperties().stream()
+ .filter(propertyDefinition -> propertyDefinition.getName().equals(SOFTWARE_VERSION_PROPERTY_NAME))
+ .findFirst();
+ }
+
+ /**
+ * Removes the non-mano software information file from the csar package
+ *
+ * @param csarInfo the csar package representation
+ * @return {@code true} if the file was removed, otherwise {@code false}
+ */
+ public boolean removeSoftwareInformationFile(final CsarInfo csarInfo) {
+ final Optional<String> softwareInformation = csarInfo.getSoftwareInformationPath();
+ if (!softwareInformation.isPresent()) {
+ return false;
+ }
+
+ csarInfo.getCsar().remove(softwareInformation.get());
+ return true;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/BusinessLogicException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/BusinessLogicException.java
new file mode 100644
index 0000000000..acf80cb5d0
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/BusinessLogicException.java
@@ -0,0 +1,32 @@
+/*
+ * ============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.impl.exceptions;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@AllArgsConstructor
+public class BusinessLogicException extends Exception {
+
+ @Getter
+ private final ResponseFormat responseFormat;
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java
deleted file mode 100644
index deb9e6a0bb..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc;
-
-import java.util.Map;
-import java.util.Queue;
-import org.openecomp.sdc.be.components.csar.CsarInfo;
-import org.junit.Test;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
-
-
-public class CsarInfoTest {
-
- private CsarInfo createTestSubject() {
- return new CsarInfo( new User(), "", null, "","","", false);
- }
-
-
- @Test
- public void testGetVfResourceName() throws Exception {
- CsarInfo testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getVfResourceName();
- }
-
-
- @Test
- public void testSetVfResourceName() throws Exception {
- CsarInfo testSubject;
- String vfResourceName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setVfResourceName(vfResourceName);
- }
-
-
- @Test
- public void testGetModifier() throws Exception {
- CsarInfo testSubject;
- User result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getModifier();
- }
-
-
- @Test
- public void testSetModifier() throws Exception {
- CsarInfo testSubject;
- User modifier = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setModifier(modifier);
- }
-
-
- @Test
- public void testGetCsarUUID() throws Exception {
- CsarInfo testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCsarUUID();
- }
-
-
- @Test
- public void testSetCsarUUID() throws Exception {
- CsarInfo testSubject;
- String csarUUID = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCsarUUID(csarUUID);
- }
-
-
- @Test
- public void testGetCsar() throws Exception {
- CsarInfo testSubject;
- Map<String, byte[]> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCsar();
- }
-
-
- @Test
- public void testSetCsar() throws Exception {
- CsarInfo testSubject;
- Map<String, byte[]> csar = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCsar(csar);
- }
-
-
- @Test
- public void testGetMainTemplateContent() throws Exception {
- CsarInfo testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMainTemplateContent();
- }
-
-
- @Test
- public void testGetMappedToscaMainTemplate() throws Exception {
- CsarInfo testSubject;
- Map<String, Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMappedToscaMainTemplate();
- }
-
-
- @Test
- public void testGetCreatedNodesToscaResourceNames() throws Exception {
- CsarInfo testSubject;
- Map<String, String> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreatedNodesToscaResourceNames();
- }
-
-
-
- @Test
- public void testIsUpdate() throws Exception {
- CsarInfo testSubject;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isUpdate();
- }
-
-
- @Test
- public void testSetUpdate() throws Exception {
- CsarInfo testSubject;
- boolean isUpdate = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setUpdate(isUpdate);
- }
-
-
- @Test
- public void testGetCreatedNodes() throws Exception {
- CsarInfo testSubject;
- Map<String, Resource> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreatedNodes();
- }
-}
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 2c06f22632..809dc7ddb0 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
@@ -40,4 +40,16 @@ public class TestUtils {
}
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 IOUtils.toByteArray(resourceAsStream);
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
index 95e6cceb78..aeccf7d817 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
@@ -29,9 +29,9 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogicMock;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -40,9 +40,11 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ToscaOperationException;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -51,21 +53,25 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import javax.servlet.ServletContext;
import java.lang.reflect.Field;
import java.util.*;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
- private static final Logger log = LoggerFactory.getLogger(PropertyBusinessLogicTest.class);
@Mock
private ServletContext servletContext;
@Mock
@@ -88,7 +94,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
JanusGraphDao janusGraphDao;
@InjectMocks
- private PropertyBusinessLogic bl = new PropertyBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
+ private PropertyBusinessLogic propertyBusinessLogic = new PropertyBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
private User user = null;
private String resourceId = "resourceforproperty.0.1";
@@ -123,8 +129,6 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
when(servletContext.getAttribute(Constants.PROPERTY_OPERATION_MANAGER)).thenReturn(propertyOperation);
when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
-
-
}
@Test
@@ -137,7 +141,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> nonExistingProperty = bl.getComponentProperty(resourceId, "NonExistingProperty", user.getUserId());
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> nonExistingProperty = propertyBusinessLogic
+ .getComponentProperty(resourceId, "NonExistingProperty", user.getUserId());
assertTrue(nonExistingProperty.isRight());
Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
}
@@ -151,7 +156,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> notFoundProperty = bl.getComponentProperty(resourceId, "invalidId", user.getUserId());
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> notFoundProperty = propertyBusinessLogic
+ .getComponentProperty(resourceId, "invalidId", user.getUserId());
assertTrue(notFoundProperty.isRight());
Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
}
@@ -164,7 +170,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setProperties(Arrays.asList(property1));
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> foundProperty = bl.getComponentProperty(resourceId, property1.getUniqueId(), user.getUserId());
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> foundProperty = propertyBusinessLogic
+ .getComponentProperty(resourceId, property1.getUniqueId(), user.getUserId());
assertTrue(foundProperty.isLeft());
assertEquals(foundProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
}
@@ -179,7 +186,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
- bl.getComponentProperty(serviceId, property1.getUniqueId(), user.getUserId());
+ propertyBusinessLogic.getComponentProperty(serviceId, property1.getUniqueId(), user.getUserId());
assertTrue(serviceProperty.isLeft());
assertEquals(serviceProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
@@ -195,7 +202,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
- bl.getComponentProperty(serviceId, "notExistingPropId", user.getUserId());
+ propertyBusinessLogic.getComponentProperty(serviceId, "notExistingPropId", user.getUserId());
assertTrue(serviceProperty.isRight());
}
@@ -208,12 +215,12 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
PropertyDefinition propDef1 = new PropertyDefinition();
propDef1.setUniqueId("ComponentInput1_uniqueId");
- assertTrue(bl.isPropertyUsedByOperation(service, propDef1));
+ assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
PropertyDefinition propDef2 = new PropertyDefinition();
propDef1.setUniqueId("inputId2");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
- assertFalse(bl.isPropertyUsedByOperation(service, propDef2));
+ assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
}
@Test
@@ -230,12 +237,12 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
PropertyDefinition propDef1 = new PropertyDefinition();
propDef1.setUniqueId("ComponentInput1_uniqueId");
- assertTrue(bl.isPropertyUsedByOperation(service, propDef1));
+ assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
PropertyDefinition propDef2 = new PropertyDefinition();
propDef1.setUniqueId("inputId2");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
- assertFalse(bl.isPropertyUsedByOperation(service, propDef2));
+ assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
}
@Test
@@ -254,17 +261,16 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
PropertyDefinition propDef1 = new PropertyDefinition();
propDef1.setUniqueId("ComponentInput1_uniqueId");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(Arrays.asList(parentService)));
- assertTrue(bl.isPropertyUsedByOperation(childService, propDef1));
+ assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef1));
PropertyDefinition propDef2 = new PropertyDefinition();
propDef1.setUniqueId("inputId2");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
- assertFalse(bl.isPropertyUsedByOperation(childService, propDef2));
+ assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef2));
}
-
- private PropertyDefinition createPropertyObject(String propertyName, String resourceId) {
- PropertyDefinition pd = new PropertyDefinition();
+ private PropertyDefinition createPropertyObject(final String propertyName, final String resourceId) {
+ final PropertyDefinition pd = new PropertyDefinition();
pd.setConstraints(null);
pd.setDefaultValue("100");
pd.setDescription("Size of thasdasdasdasde local disk, in Gigabytes (GB), available to applications running on the Compute node");
@@ -272,6 +278,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
pd.setRequired(true);
pd.setType("Integer");
pd.setOwnerId(resourceId);
+ pd.setName(propertyName);
pd.setUniqueId(resourceId + "." + propertyName);
return pd;
}
@@ -281,7 +288,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
StorageOperationStatus lockResult = StorageOperationStatus.CONNECTION_FAILURE;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(new Resource()));
- assertTrue(bl.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty","i726").isRight());
}
@Test
@@ -295,18 +302,14 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Field baseBusinessLogic3;
- baseBusinessLogic3 = bl.getClass().getSuperclass().getDeclaredField("janusGraphDao");
+ baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
baseBusinessLogic3.setAccessible(true);
- baseBusinessLogic3.set(bl, janusGraphDao);
-
+ baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
StorageOperationStatus lockResult = StorageOperationStatus.OK;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
- //doNothing().when(janusGraphDao).commit();
-
- Either<PropertyDefinition, ResponseFormat> result;
Component resourcereturn= new Resource();
resourcereturn.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
@@ -316,13 +319,11 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
-
- assertTrue(bl.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
}
@Test
public void deleteProperty_RESTRICTED_OPERATION() throws Exception {
-
Resource resource = new Resource();
PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
@@ -331,20 +332,15 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Field baseBusinessLogic3;
- baseBusinessLogic3 = bl.getClass().getSuperclass().getDeclaredField("janusGraphDao");
+ baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
baseBusinessLogic3.setAccessible(true);
- baseBusinessLogic3.set(bl, janusGraphDao);
-
+ baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
StorageOperationStatus lockResult = StorageOperationStatus.OK;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
- //doNothing().when(janusGraphDao).commit();
-
- Either<PropertyDefinition, ResponseFormat> result;
- Component resourcereturn= new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
@@ -353,43 +349,155 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
- assertTrue(bl.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
}
@Test
public void deleteProperty_RESTRICTED_() throws Exception {
-
- Resource resource = new Resource();
- PropertyDefinition property1 = createPropertyObject("PROP", "RES01");
- property1.setUniqueId("PROP");
- resource.setProperties(Arrays.asList(property1));
- String resourceId = "myResource";
+ final PropertyDefinition property1 = createPropertyObject("PROP", "RES01");
+ final Resource resource = new Resource();
+ final String resourceId = "myResource";
resource.setUniqueId(resourceId);
+ resource.setProperties(Arrays.asList(property1));
- Field baseBusinessLogic3;
- baseBusinessLogic3 = bl.getClass().getSuperclass().getDeclaredField("janusGraphDao");
+ final Field baseBusinessLogic3 =
+ propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
baseBusinessLogic3.setAccessible(true);
- baseBusinessLogic3.set(bl, janusGraphDao);
-
+ baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- StorageOperationStatus lockResult = StorageOperationStatus.OK;
- when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
- //doNothing().when(janusGraphDao).commit();
-
- Either<PropertyDefinition, ResponseFormat> result;
+ when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- Component resourcereturn= new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
- Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
- when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
- when(toscaOperationFacade.deletePropertyOfComponent(anyObject(),anyString())).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.deletePropertyOfComponent(anyObject(), anyString())).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.getParentComponents(anyString())).thenReturn(Either.left(new ArrayList<>()));
- assertTrue(bl.deletePropertyFromComponent("RES01", "PROP","USR01").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "PROP","USR01").isRight());
+ }
+
+ @Test
+ public void findComponentByIdTest() throws BusinessLogicException {
+ //give
+ final Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ //when
+ final Component actualResource = propertyBusinessLogic.findComponentById(resourceId).orElse(null);
+ //then
+ assertThat("Actual resource should not be null", actualResource, is(notNullValue()));
+ assertThat("Actual resource must have the expected id",
+ actualResource.getUniqueId(), is(equalTo(resource.getUniqueId())));
+ }
+
+ @Test(expected = BusinessLogicException.class)
+ public void findComponentById_resourceNotFoundTest() throws BusinessLogicException {
+ //given
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.right(null));
+ Mockito.when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, "")).thenReturn(new ResponseFormat());
+ //when
+ propertyBusinessLogic.findComponentById(resourceId);
+ }
+
+ @Test
+ public void updateComponentPropertyTest() throws BusinessLogicException {
+ //given
+ final Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.left(propertyDefinition));
+ //when
+ final PropertyDefinition actualPropertyDefinition = propertyBusinessLogic
+ .updateComponentProperty(resourceId, propertyDefinition);
+ //then
+ assertThat("Actual property definition should not be null", actualPropertyDefinition, is(notNullValue()));
+ assertThat("Actual property definition must have the expected id",
+ actualPropertyDefinition.getOwnerId(), is(equalTo(resource.getUniqueId())));
+ assertThat("Actual property definition must have the expected id",
+ actualPropertyDefinition.getName(), is(equalTo(propertyDefinition.getName())));
+ }
+
+ @Test(expected = BusinessLogicException.class)
+ public void updateComponentProperty_updateFailedTest() throws BusinessLogicException {
+ //given
+ final Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.right(null));
+ when(componentsUtils.getResponseFormatByResource(Mockito.any(), Mockito.anyString())).thenReturn(new ResponseFormat());
+ when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(null);
+ //when
+ propertyBusinessLogic.updateComponentProperty(resourceId, propertyDefinition);
+ }
+
+ @Test
+ public void copyPropertyToComponentTest() throws ToscaOperationException {
+ //given
+ final Resource expectedResource = new Resource();
+ expectedResource.setUniqueId(resourceId);
+ final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
+ final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
+ propertiesToCopyList.add(property1);
+ final PropertyDefinition property2 = createPropertyObject("property2", resourceId);
+ propertiesToCopyList.add(property2);
+
+ final PropertyDefinition copiedProperty1 = new PropertyDefinition(property1);
+ copiedProperty1.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty1.getName()));
+ expectedResource.addProperty(copiedProperty1);
+ final PropertyDefinition copiedProperty2 = new PropertyDefinition(property2);
+ copiedProperty2.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty2.getName()));
+ expectedResource.addProperty(copiedProperty2);
+
+ Mockito.when(toscaOperationFacade
+ .addPropertyToComponent(eq(property1.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .thenReturn(Either.left(copiedProperty1));
+ Mockito.when(toscaOperationFacade
+ .addPropertyToComponent(eq(property2.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .thenReturn(Either.left(copiedProperty2));
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
+ //when
+ final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
+ //then
+ assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
+ assertThat("Actual component should be an instance of Resource", actualComponent, is(instanceOf(Resource.class)));
+ assertThat("Actual component should have the expected id", actualComponent.getUniqueId(), is(equalTo(expectedResource.getUniqueId())));
+ assertThat("Actual component should have 2 properties", actualComponent.getProperties(), hasSize(2));
+ assertThat("Actual component should have the expected properties", actualComponent.getProperties(), hasItems(copiedProperty1, copiedProperty2));
+ }
+
+ @Test
+ public void copyPropertyToComponent1() throws ToscaOperationException {
+ //given
+ final Resource expectedResource = new Resource();
+ expectedResource.setUniqueId(resourceId);
+ //when
+ final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, null);
+ //then
+ assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
+ assertThat("Actual component should be an instance of Resource", actualComponent, is(instanceOf(Resource.class)));
+ assertThat("Actual component should have the expected id", actualComponent.getUniqueId(), is(equalTo(expectedResource.getUniqueId())));
+ assertThat("Actual component should have no properties", actualComponent.getProperties(), is(nullValue()));
+ }
+
+ @Test(expected = ToscaOperationException.class)
+ public void copyPropertyToComponent_copyFailed() throws ToscaOperationException {
+ //given
+ final Resource expectedResource = new Resource();
+ expectedResource.setUniqueId(resourceId);
+ final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
+ final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
+ propertiesToCopyList.add(property1);
+ Mockito.when(toscaOperationFacade
+ .addPropertyToComponent(eq(property1.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
+ //when
+ propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
index 69f9f5704d..7537935816 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
@@ -20,24 +20,34 @@
package org.openecomp.sdc.be.components.csar;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
import java.io.File;
import java.net.URISyntaxException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.NonManoArtifactType;
+import org.openecomp.sdc.be.config.NonManoConfiguration;
+import org.openecomp.sdc.be.config.NonManoFolderType;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.User;
@@ -112,4 +122,30 @@ public class CsarInfoTest {
assertEquals(MAIN_TEMPLATE_NAME, csarInfo.getMainTemplateName());
assertEquals(csarInfo.getMainTemplateName(), nodeTypeInfo.getTemplateFileName());
}
+
+ @Test
+ public void getSoftwareInformationPathTest() {
+ final NonManoConfiguration nonManoConfigurationMock = Mockito.mock(NonManoConfiguration.class);
+ final CsarInfo csarInfo = new CsarInfo(nonManoConfigurationMock);
+ final NonManoFolderType testNonManoFolderType = new NonManoFolderType();
+ testNonManoFolderType.setLocation("sw-location-test");
+ testNonManoFolderType.setType("informational-test");
+ when(nonManoConfigurationMock.getNonManoType(NonManoArtifactType.ONAP_SW_INFORMATION)).thenReturn(testNonManoFolderType);
+ final Map<String, byte[]> csarFileMap = new HashMap<>();
+ final String expectedPath = testNonManoFolderType.getPath() + "/" + "software-file.yaml";
+ csarFileMap.put(expectedPath, new byte[0]);
+ csarInfo.setCsar(csarFileMap);
+ final Optional<String> softwareInformationPath = csarInfo.getSoftwareInformationPath();
+ assertThat("The software information yaml path should be present", softwareInformationPath.isPresent(), is(true));
+ softwareInformationPath.ifPresent(path -> {
+ assertThat("The software information yaml ", path, is(equalTo(expectedPath)));
+ });
+ }
+
+ @Test
+ public void getSoftwareInformationPathTest_emptyCsar() {
+ csarInfo.setCsar(new HashMap<>());
+ final Optional<String> softwareInformationPath = csarInfo.getSoftwareInformationPath();
+ assertThat("The software information yaml path should not be present", softwareInformationPath.isPresent(), is(false));
+ }
}
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
new file mode 100644
index 0000000000..6f826047a4
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java
@@ -0,0 +1,59 @@
+/*
+ * ============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/ResourceBusinessLogicMockitoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java
index 75a00822f6..65559d4b28 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java
@@ -145,6 +145,10 @@ public class ResourceBusinessLogicMockitoTest {
private IGraphLockOperation graphLockOperation;
@Mock
private GenericTypeBusinessLogic genericTypeBusinessLogic;
+ @Mock
+ private PropertyBusinessLogic propertyBusinessLogic;
+ @Mock
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
private ResourceBusinessLogic resourceBusinessLogic;
@@ -167,7 +171,9 @@ public class ResourceBusinessLogicMockitoTest {
mergeInstanceUtils,
uiComponentDataConverter,
csarBusinessLogic,
- artifactToscaOperation);
+ artifactToscaOperation,
+ propertyBusinessLogic,
+ softwareInformationBusinessLogic);
resourceBusinessLogic.setLifecycleManager(lifecycleManager);
resourceBusinessLogic.setApplicationDataTypeCache(applicationDataTypeCache);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 18f39b1892..f5b42e1dde 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -175,6 +175,7 @@ public class ResourceBusinessLogicTest extends ComponentBusinessLogicMock {
GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
+ private PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
ArtifactsResolver artifactsResolver = Mockito.mock(ArtifactsResolver.class);
InterfaceLifecycleOperation interfaceLifecycleTypeOperation = Mockito.mock(InterfaceLifecycleOperation.class);
ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
@@ -185,6 +186,7 @@ public class ResourceBusinessLogicTest extends ComponentBusinessLogicMock {
CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
ResponseFormatManager responseManager = null;
GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
@@ -278,7 +280,7 @@ public class ResourceBusinessLogicTest extends ComponentBusinessLogicMock {
interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic,
resourceImportManager, inputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
- artifactToscaOperation);
+ artifactToscaOperation, propertyBusinessLogic, softwareInformationBusinessLogic);
artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
bl.setUserAdmin(mockUserAdmin);
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
new file mode 100644
index 0000000000..2eda76fa16
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java
@@ -0,0 +1,173 @@
+/*
+ * ============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.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SoftwareInformationBusinessLogicTest {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SoftwareInformationBusinessLogicTest.class);
+ private final String softwareInformationPath = "Artifact/Informational/SW_INFORMATION";
+
+ @Mock
+ private PropertyBusinessLogic propertyBusinessLogic;
+ @Mock
+ private CsarInfo csarInfo;
+ @Mock
+ private Resource resource;
+
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
+
+ @Before
+ public void setup() {
+ softwareInformationBusinessLogic = new SoftwareInformationBusinessLogic(propertyBusinessLogic);
+ mockCsarInfo();
+ }
+
+ private void mockCsarInfo() {
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information.yaml");
+ when(csarInfo.getSoftwareInformationPath()).thenReturn(Optional.of(softwareInformationPath));
+ }
+
+ @Test
+ public void testRemoveSoftwareInformationFile() {
+ boolean result = softwareInformationBusinessLogic.removeSoftwareInformationFile(csarInfo);
+ assertThat("The software information file should be removed", result, is(true));
+ when(csarInfo.getSoftwareInformationPath()).thenReturn(Optional.empty());
+ result = softwareInformationBusinessLogic.removeSoftwareInformationFile(csarInfo);
+ assertThat("The software information file should not be removed", result, is(false));
+ }
+
+ @Test
+ public void testSetSoftwareInformation() throws BusinessLogicException {
+ final PropertyDefinition propertyDefinition = mockSoftwareInformationPropertyDefinition();
+ mockResource(propertyDefinition);
+ when(propertyBusinessLogic.updateComponentProperty(Mockito.any(), Mockito.any()))
+ .thenReturn(propertyDefinition);
+ final Optional<PropertyDefinition> actualPropertyDefinition = softwareInformationBusinessLogic
+ .setSoftwareInformation(resource, csarInfo);
+ assertThat("The updated property should be present", actualPropertyDefinition.isPresent(), is(true));
+ actualPropertyDefinition.ifPresent(propertyDefinition1 -> {
+ assertThat("The updated property should have the expected name", propertyDefinition1.getName(),
+ is("software_versions"));
+ assertThat("The updated property should have the expected value", propertyDefinition1.getValue(),
+ is("[\"version1\",\"version2\"]"));
+ });
+ }
+
+ @Test
+ public void testSetSoftwareInformationWithInvalidArtifact() throws BusinessLogicException {
+ //given
+ final PropertyDefinition propertyDefinition = mockSoftwareInformationPropertyDefinition();
+ mockResource(propertyDefinition);
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-corrupt.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/invalid.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-1.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-2.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-3.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+ }
+
+ private void assertNotPresentPropertyDefinition() throws BusinessLogicException {
+ final Optional<PropertyDefinition> actualPropertyDefinition =
+ softwareInformationBusinessLogic.setSoftwareInformation(resource, csarInfo);
+ assertThat("The updated property should not be present",
+ actualPropertyDefinition.isPresent(), is(false));
+ }
+
+ @Test
+ public void testSetSoftwareInformationWithNoResourceSoftwareInformationProperty() throws BusinessLogicException {
+ //when and then
+ assertNotPresentPropertyDefinition();
+ }
+
+ @Test
+ public void testSetSoftwareInformationWithNoCsarSoftwareInformation() throws BusinessLogicException {
+ //given
+ when(csarInfo.getSoftwareInformationPath()).thenReturn(Optional.empty());
+ //when and then
+ assertNotPresentPropertyDefinition();
+ }
+
+ private void mockCsarFileMap(final String softwareInformationArtifactPath) {
+ final byte[] softwareInformationFile;
+ try {
+ softwareInformationFile = TestUtils.getResourceAsByteArray(softwareInformationArtifactPath);
+ } catch (final IOException e) {
+ final String errorMsg = "Could not find software information artifact " + softwareInformationArtifactPath;
+ LOGGER.error(errorMsg, e);
+ fail(errorMsg);
+ return;
+ }
+ final HashMap<String, byte[]> csarFileMap = new HashMap<>();
+ csarFileMap.put(softwareInformationPath, softwareInformationFile);
+ when(csarInfo.getCsar()).thenReturn(csarFileMap);
+ }
+
+ private PropertyDefinition mockSoftwareInformationPropertyDefinition() {
+ final PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName("software_versions");
+ return propertyDefinition;
+ }
+
+ private void mockResource(final PropertyDefinition... propertyDefinition) {
+ when(resource.getProperties()).thenReturn(Arrays.asList(propertyDefinition));
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
index e48148c5cb..7e2c2acce5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -30,8 +30,10 @@ import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.SoftwareInformationBusinessLogic;
import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -58,13 +60,15 @@ public class CheckoutTest extends LifecycleTestBase {
private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
private final CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class);
+ private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
+ private final SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
componentInstanceBusinessLogic, resourceImportManager, inputsBusinessLogic, compositionBusinessLogic,
resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils,
- uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation);
+ uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic, softwareInformationBusinessLogic);
@Before
public void setup() {
diff --git a/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/invalid.yaml b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/invalid.yaml
new file mode 100644
index 0000000000..5430ba574b
--- /dev/null
+++ b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/invalid.yaml
@@ -0,0 +1,4 @@
+this: "is"
+- a
+invalid=
+ yaml: \ No newline at end of file
diff --git a/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-corrupt.yaml b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-corrupt.yaml
new file mode 100644
index 0000000000..855994bacf
--- /dev/null
+++ b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-corrupt.yaml
@@ -0,0 +1 @@
+¬öF²Ø¢ÃHp| \ No newline at end of file
diff --git a/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-1.yaml b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-1.yaml
new file mode 100644
index 0000000000..3c5e5fdd0c
--- /dev/null
+++ b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-1.yaml
@@ -0,0 +1,6 @@
+description: "pnf software information"
+provider: "Ericsson"
+version: "1.0"
+pnf_software_information_invalid:
+ - description: "first software version of PNF"
+ pnf_software_version: "version1"
diff --git a/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-2.yaml b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-2.yaml
new file mode 100644
index 0000000000..5fd938851e
--- /dev/null
+++ b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-2.yaml
@@ -0,0 +1,6 @@
+description: "pnf software information"
+provider: "Ericsson"
+version: "1.0"
+pnf_software_information_invalid:
+ description: "first software version of PNF"
+ pnf_software_version: "version1"
diff --git a/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-3.yaml b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-3.yaml
new file mode 100644
index 0000000000..36ee3f2335
--- /dev/null
+++ b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-3.yaml
@@ -0,0 +1,7 @@
+description: "pnf software information"
+provider: "Ericsson"
+version: "1.0"
+pnf_software_information:
+ - description_invalid: "first software version of PNF"
+ pnf_software_version_invalid: "version1"
+
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
new file mode 100644
index 0000000000..31f4bc6173
--- /dev/null
+++ b/catalog-be/src/test/resources/artifacts/pnfSoftwareInformation/pnf-sw-information.yaml
@@ -0,0 +1,8 @@
+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"
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 43f3487924..ab08f5c339 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -2229,50 +2229,45 @@ public class ToscaOperationFacade {
return nodeTemplateOperation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
}
- public Either<PropertyDefinition, StorageOperationStatus> addPropertyToComponent(String propertyName,
+ public Either<PropertyDefinition, StorageOperationStatus> addPropertyToComponent(String propertyName,
PropertyDefinition newPropertyDefinition,
Component component) {
-
- Either<PropertyDefinition, StorageOperationStatus> result = null;
- Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
newPropertyDefinition.setName(propertyName);
StorageOperationStatus status = getToscaElementOperation(component)
.addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME);
if (status != StorageOperationStatus.OK) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the component {}. Status is {}. ", propertyName, component.getName(), status);
- result = Either.right(status);
- }
- if (result == null) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreProperties(false);
- filter.setIgnoreInputs(false);
- getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
- if (getUpdatedComponentRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated component {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
- result = Either.right(status);
- }
- }
- if (result == null) {
- PropertyDefinition newProperty = null;
- List<PropertyDefinition> properties =
- (getUpdatedComponentRes.left().value()).getProperties();
- if (CollectionUtils.isNotEmpty(properties)) {
- Optional<PropertyDefinition> propertyOptional = properties.stream().filter(
- propertyEntry -> propertyEntry.getName().equals(propertyName)).findAny();
- if (propertyOptional.isPresent()) {
- newProperty = propertyOptional.get();
- }
- }
- if (newProperty == null) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the component {}. Status is {}. ", propertyName, component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
- result = Either.right(StorageOperationStatus.NOT_FOUND);
- } else {
- result = Either.left(newProperty);
- }
+ return Either.right(status);
}
- return result;
+
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreProperties(false);
+ filter.setIgnoreInputs(false);
+ Either<Component, StorageOperationStatus> getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
+ if (getUpdatedComponentRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated component {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
+ return Either.right(status);
+ }
+
+ PropertyDefinition newProperty = null;
+ List<PropertyDefinition> properties =
+ (getUpdatedComponentRes.left().value()).getProperties();
+ if (CollectionUtils.isNotEmpty(properties)) {
+ Optional<PropertyDefinition> propertyOptional = properties.stream().filter(
+ propertyEntry -> propertyEntry.getName().equals(propertyName)).findAny();
+ if (propertyOptional.isPresent()) {
+ newProperty = propertyOptional.get();
+ }
+ }
+ if (newProperty == null) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the component {}. Status is {}. ", propertyName, component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+
+ return Either.left(newProperty);
}
+
public StorageOperationStatus deletePropertyOfComponent(Component component, String propertyName) {
return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java
new file mode 100644
index 0000000000..b5b7da8d26
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java
@@ -0,0 +1,36 @@
+/*
+ * ============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.model.jsonjanusgraph.operations.exception;
+
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public class ToscaOperationException extends Exception {
+
+ private final StorageOperationStatus storageOperationStatus;
+
+ public ToscaOperationException(String s, StorageOperationStatus storageOperationStatus) {
+ super(String.format("%s. Operation Status: %s", s, storageOperationStatus.name()));
+ this.storageOperationStatus = storageOperationStatus;
+ }
+
+ public StorageOperationStatus getStorageOperationStatus() {
+ return storageOperationStatus;
+ }
+}
diff --git a/common-be/pom.xml b/common-be/pom.xml
index 025e3a9ec0..564f200bcc 100644
--- a/common-be/pom.xml
+++ b/common-be/pom.xml
@@ -55,6 +55,18 @@
</dependency>
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <version>${hamcrest.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>${hamcrest.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
@@ -72,6 +84,11 @@
<version>${tosca.datatype.version}</version>
</dependency>
<dependency>
+ <groupId>org.onap.sdc.sdc-tosca</groupId>
+ <artifactId>sdc-tosca</artifactId>
+ <version>${sdc-tosca-parser.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/NonManoArtifactType.java b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoArtifactType.java
index bcf697cdbe..35917f88a7 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/NonManoArtifactType.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoArtifactType.java
@@ -17,7 +17,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+package org.openecomp.sdc.be.config;
/**
* Stores non mano artifact types.
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java
new file mode 100644
index 0000000000..9471fed0fe
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java
@@ -0,0 +1,42 @@
+/*
+ * ============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.config;
+
+import java.util.Map;
+
+import lombok.Data;
+
+/**
+ * Represents the non-mano configuration yaml.
+ */
+@Data
+public class NonManoConfiguration {
+ private Map<String, NonManoFolderType> nonManoKeyFolderMapping;
+
+ /**
+ * Gets the non mano folder type based on the non mano artifact type.
+ * @param nonManoArtifactType the artifact type
+ * @return
+ * The NonManoType for the artifact type
+ */
+ public NonManoFolderType getNonManoType(final NonManoArtifactType nonManoArtifactType) {
+ return nonManoKeyFolderMapping.get(nonManoArtifactType.getType());
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfigurationManager.java b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfigurationManager.java
new file mode 100644
index 0000000000..028f16ab6e
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfigurationManager.java
@@ -0,0 +1,68 @@
+/*
+ * ============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.config;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.IOUtils;
+import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter;
+import org.openecomp.sdc.be.config.exception.LoadConfigurationException;
+
+/**
+ * Singleton that loads and stores the Non Mano configuration
+ */
+public class NonManoConfigurationManager {
+ private static NonManoConfigurationManager nonManoConfigurationManager = null;
+ private NonManoConfiguration nonManoConfiguration;
+
+ private NonManoConfigurationManager() {
+ loadConfiguration();
+ }
+
+ /**
+ * Loads the configuration yaml from the resources.
+ */
+ private void loadConfiguration() {
+ final InputStream configYamlAsStream = getClass().getClassLoader().getResourceAsStream("config/nonManoConfig.yaml");
+ if (configYamlAsStream == null) {
+ throw new LoadConfigurationException("Expected non-mano configuration file 'config/nonManoConfig.yaml' not found in resources");
+ }
+ final String data;
+ try {
+ data = IOUtils.toString(configYamlAsStream, StandardCharsets.UTF_8);
+ } catch (final IOException e) {
+ throw new LoadConfigurationException("Could not parse non-mano configuration file 'config/nonManoConfig.yaml' to string", e);
+ }
+ nonManoConfiguration = new YamlToObjectConverter().convertFromString(data, NonManoConfiguration.class);
+ }
+
+ public static NonManoConfigurationManager getInstance() {
+ if (nonManoConfigurationManager == null) {
+ nonManoConfigurationManager = new NonManoConfigurationManager();
+ }
+
+ return nonManoConfigurationManager;
+ }
+
+ public NonManoConfiguration getNonManoConfiguration() {
+ return nonManoConfiguration;
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java
new file mode 100644
index 0000000000..4d815e3f57
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java
@@ -0,0 +1,35 @@
+/*
+ * ============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.config;
+
+import lombok.Data;
+
+@Data
+public class NonManoFolderType {
+ private String location;
+ private String type;
+
+ /**
+ * Gets the expected folder path
+ * @return
+ */
+ public String getPath() {
+ return String.format("Artifacts/%s/%s", type, location);
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/config/exception/LoadConfigurationException.java b/common-be/src/main/java/org/openecomp/sdc/be/config/exception/LoadConfigurationException.java
new file mode 100644
index 0000000000..53432a3490
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/config/exception/LoadConfigurationException.java
@@ -0,0 +1,31 @@
+/*
+ * ============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.config.exception;
+
+public class LoadConfigurationException extends RuntimeException {
+
+ public LoadConfigurationException(final String s) {
+ super(s);
+ }
+
+ public LoadConfigurationException(final String s, final Throwable throwable) {
+ super(s, throwable);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/resources/nonManoConfig.yaml b/common-be/src/main/resources/config/nonManoConfig.yaml
index 4ace330392..4ace330392 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/resources/nonManoConfig.yaml
+++ b/common-be/src/main/resources/config/nonManoConfig.yaml
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/config/NonManoConfigurationManagerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/config/NonManoConfigurationManagerTest.java
new file mode 100644
index 0000000000..bbe8623ed8
--- /dev/null
+++ b/common-be/src/test/java/org/openecomp/sdc/be/config/NonManoConfigurationManagerTest.java
@@ -0,0 +1,50 @@
+/*
+ * ============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.config;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.Matchers.anEmptyMap;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class NonManoConfigurationManagerTest {
+
+ @Test
+ public void getInstance() {
+ final NonManoConfigurationManager instance = NonManoConfigurationManager.getInstance();
+ assertThat("Singleton instance should never be null", instance, is(notNullValue()));
+ }
+
+ @Test
+ public void getNonManoConfiguration() {
+ final NonManoConfiguration nonManoConfiguration = NonManoConfigurationManager.getInstance()
+ .getNonManoConfiguration();
+ assertThat("NonManoConfiguration instance should never be null", nonManoConfiguration, is(notNullValue()));
+ assertThat("NonManoConfiguration FolderMapping configuration should no be empty",
+ nonManoConfiguration.getNonManoKeyFolderMapping(), is(not(anEmptyMap())));
+
+ for (final NonManoArtifactType value : NonManoArtifactType.values()) {
+ assertThat(String.format("Expected %s value should not be null", value), nonManoConfiguration.getNonManoType(value), is(notNullValue()));
+ }
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
index 9481a021e2..b0b8971e71 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
@@ -21,6 +21,8 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_PM_DICTIONARY;
+import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_VES_EVENTS;
import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_0;
import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_1;
import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_METADATA_LIMIT;
@@ -37,8 +39,6 @@ import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
import java.io.IOException;
import java.io.InputStream;
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
index 5079ecc0ac..b91a1156ce 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
@@ -20,16 +20,16 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.isEmptyString;
+import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_PM_DICTIONARY;
+import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_VES_EVENTS;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_ARCHIVE_VERSION;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_NAME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_PROVIDER;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_RELEASE_DATE_TIME;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
@@ -53,7 +53,7 @@ public class ManifestBuilderTest {
@Test
public void givenNoManifestInformation_whenBuildingManifest_thenEmptyStringShouldBeReturned() {
final String manifest = manifestBuilder.build();
- assertThat("Manifest should be empty", manifest, isEmptyString());
+ assertThat("Manifest should be empty", manifest, is(emptyString()));
}
@Test
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
index 7ff800d07b..fc05b5ba7b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
@@ -28,6 +28,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_PM_DICTIONARY;
+import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_VES_EVENTS;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_ARCHIVE_VERSION;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_NAME;
@@ -36,7 +38,6 @@ import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PACKAGE_VERSION
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PRODUCT_NAME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PROVIDER_ID;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_RELEASE_DATE_TIME;
-import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CSAR_VERSION_ENTRY;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
@@ -46,8 +47,7 @@ import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_LICENSES;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_TESTS;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.EMPTY_YAML_FILE_PATH;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.INVALID_YAML_FILE_PATH;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_FILE_PATH;
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/Configuration.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/Configuration.java
deleted file mode 100644
index 77507b58b2..0000000000
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/Configuration.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
-
-import java.util.Map;
-
-import lombok.Data;
-
-@Data
-public class Configuration {
- private Map<String, NonManoType> nonManoKeyFolderMapping;
-}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
index d6b1194b81..671c3be0a8 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
@@ -31,7 +31,6 @@ import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_N
import java.io.IOException;
import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
@@ -41,11 +40,12 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
-import org.apache.commons.io.IOUtils;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.be.config.NonManoConfiguration;
+import org.openecomp.sdc.be.config.NonManoConfigurationManager;
+import org.openecomp.sdc.be.config.NonManoFolderType;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
@@ -59,20 +59,14 @@ public class ETSIServiceImpl implements ETSIService {
private static final Logger LOGGER = LoggerFactory.getLogger(ETSIServiceImpl.class);
- private Configuration configuration;
+ private final NonManoConfiguration nonManoConfiguration;
- public ETSIServiceImpl() throws IOException {
- final InputStream io = getClass().getClassLoader().getResourceAsStream("nonManoConfig.yaml");
- if (io == null) {
- throw new IOException("Non Mano configuration not found");
- }
- final String data = IOUtils.toString(io, StandardCharsets.UTF_8);
- final YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
- configuration = yamlToObjectConverter.convertFromString(data, Configuration.class);
+ public ETSIServiceImpl() {
+ nonManoConfiguration = NonManoConfigurationManager.getInstance().getNonManoConfiguration();
}
- public ETSIServiceImpl(Configuration configuration) {
- this.configuration = configuration;
+ public ETSIServiceImpl(final NonManoConfiguration nonManoConfiguration) {
+ this.nonManoConfiguration = nonManoConfiguration;
}
@Override
@@ -102,16 +96,16 @@ public class ETSIServiceImpl implements ETSIService {
throw ex;
}
final Map<String, Path> fromToPathMap = new HashMap<>();
- final Map<String, NonManoType> nonManoKeyFolderMapping = configuration.getNonManoKeyFolderMapping();
+ final Map<String, NonManoFolderType> nonManoKeyFolderMapping = nonManoConfiguration.getNonManoKeyFolderMapping();
manifest.getNonManoSources().entrySet().stream()
.filter(manifestNonManoSourceEntry -> nonManoKeyFolderMapping.containsKey(manifestNonManoSourceEntry.getKey()))
.forEach(manifestNonManoSourceEntry -> {
- final NonManoType nonManoType = nonManoKeyFolderMapping.get(manifestNonManoSourceEntry.getKey());
+ final NonManoFolderType nonManoFolderType = nonManoKeyFolderMapping.get(manifestNonManoSourceEntry.getKey());
final List<String> nonManoFileList = manifestNonManoSourceEntry.getValue();
final Map<String, Path> actualFromToPathMap = nonManoFileList.stream()
.map(nonManoFilePath -> {
final Path normalizedFilePath = resolveNonManoFilePath(originalManifestPath, nonManoFilePath);
- final Optional<Path> changedPath = updateNonManoPathInHandler(handler, nonManoType, normalizedFilePath);
+ final Optional<Path> changedPath = updateNonManoPathInHandler(handler, nonManoFolderType, normalizedFilePath);
if (changedPath.isPresent()) {
final Map<String, Path> fromAndToPathMap = new HashMap<>();
fromAndToPathMap.put(nonManoFilePath, Paths.get(ARTIFACTS_FOLDER).resolve(changedPath.get()));
@@ -145,15 +139,15 @@ public class ETSIServiceImpl implements ETSIService {
* Updates the non mano file path in the package file handler based on the non mano type.
*
* @param handler The package file handler
- * @param nonManoType The Non Mano type of the file to update
+ * @param nonManoFolderType The Non Mano type of the file to update
* @param nonManoOriginalFilePath The Non Mano file original path
* @return The new file path if it was updated in the package file handler, otherwise empty.
*/
- private Optional<Path> updateNonManoPathInHandler(final FileContentHandler handler, final NonManoType nonManoType,
+ private Optional<Path> updateNonManoPathInHandler(final FileContentHandler handler, final NonManoFolderType nonManoFolderType,
final Path nonManoOriginalFilePath) {
final Path fixedSourcePath = fixNonManoPath(nonManoOriginalFilePath);
if (handler.containsFile(fixedSourcePath.toString())) {
- final Path newNonManoPath = Paths.get(nonManoType.getType(), nonManoType.getLocation()
+ final Path newNonManoPath = Paths.get(nonManoFolderType.getType(), nonManoFolderType.getLocation()
, fixedSourcePath.getFileName().toString());
if (!handler.containsFile(newNonManoPath.toString())) {
handler.addFile(newNonManoPath.toString(), handler.remove(fixedSourcePath.toString()));
@@ -285,4 +279,8 @@ public class ETSIServiceImpl implements ETSIService {
}
return io;
}
+
+ public NonManoConfiguration getConfiguration() {
+ return nonManoConfiguration;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/NonManoType.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/NonManoType.java
deleted file mode 100644
index e10c102593..0000000000
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/NonManoType.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019, Nordix Foundation. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
-
-
-import lombok.Data;
-
-@Data
-public class NonManoType {
- private String location;
- private String type;
-}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java
index 3d70948b2f..f03d561375 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java
@@ -49,6 +49,7 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter;
+import org.openecomp.sdc.be.config.NonManoConfiguration;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.tosca.csar.Manifest;
@@ -73,8 +74,8 @@ public class ETSIServiceImplTest {
@Before
public void setUp() throws IOException {
YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
- Configuration configuration = yamlToObjectConverter.convert("src/test/resources",
- Configuration.class, "nonManoConfig.yaml");
+ NonManoConfiguration configuration = yamlToObjectConverter.convert("src/test/resources",
+ NonManoConfiguration.class, "nonManoConfig.yaml");
etsiService = Mockito.spy(new ETSIServiceImpl(configuration));
}
diff --git a/test-apis-ci/sdc-api-tests/chef-repo/cookbooks/sdc-api-tests/files/default/Files/PNFs/sample-pnf-1.0.1-non-mano-software-information.csar b/test-apis-ci/sdc-api-tests/chef-repo/cookbooks/sdc-api-tests/files/default/Files/PNFs/sample-pnf-1.0.1-non-mano-software-information.csar
new file mode 100644
index 0000000000..b4d2b3eda3
--- /dev/null
+++ b/test-apis-ci/sdc-api-tests/chef-repo/cookbooks/sdc-api-tests/files/default/Files/PNFs/sample-pnf-1.0.1-non-mano-software-information.csar
Binary files differ
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/sanity/Onboard.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/sanity/Onboard.java
index 1f8e8b5c06..c4faf2c9dc 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/sanity/Onboard.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/sanity/Onboard.java
@@ -25,6 +25,7 @@ import com.aventstack.extentreports.Status;
import fj.data.Either;
import org.junit.Rule;
import org.junit.rules.TestName;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
@@ -43,23 +44,17 @@ import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtillViaApis;
import org.testng.annotations.*;
-
-
-
-
-
public class Onboard extends ComponentBaseTest {
-
-
+
+ private String makeDistributionValue;
+ private String makeToscaValidationValue;
@Rule
- public static TestName name = new TestName();
+ public static final TestName name = new TestName();
public Onboard() {
super(name, Onboard.class.getName());
}
- protected String makeDistributionValue;
- protected String makeToscaValidationValue;
@Parameters({ "makeDistribution" })
@@ -78,62 +73,58 @@ public class Onboard extends ComponentBaseTest {
@Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
- public void onboardVNFShotFlow(String filePath, String vnfFile) throws Exception, Throwable {
+ public void onboardVNFShotFlow(String filePath, String vnfFile) throws Exception {
setLog(vnfFile);
- runOnboardToDistributionFlow(filePath, vnfFile);
+ runOnboardToDistributionFlow(filePath, vnfFile, ResourceTypeEnum.VF);
}
@Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "PNF_List")
- public void onboardPNFFlow(String filePath, String pnfFile) throws Exception, Throwable {
+ public void onboardPNFFlow(String filePath, String pnfFile) throws Exception {
setLog(pnfFile);
- runOnboardToDistributionFlow(filePath, pnfFile);
+ runOnboardToDistributionFlow(filePath, pnfFile, ResourceTypeEnum.PNF);
}
@Test
public void passTest() {
System.out.println("print - >" + "test Passed");
}
-
-
-
-
- public void runOnboardToDistributionFlow(String filePath, String vnfFile) throws Exception {
-
- ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
+ private void runOnboardToDistributionFlow(String packageFilePath, String packageFileName, ResourceTypeEnum resourceTypeEnum) throws Exception {
+ ExtentTestActions.log(Status.INFO, String.format("Going to onboard the %s %s", resourceTypeEnum.getValue(), packageFileName));
User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
- VendorSoftwareProductObject vendorSoftwareProductObject = OnboardingUtillViaApis.createVspViaApis(resourceReqDetails, filePath, vnfFile, user);
+ resourceReqDetails.setResourceType(resourceTypeEnum.getValue());
+ VendorSoftwareProductObject vendorSoftwareProductObject = OnboardingUtillViaApis.createVspViaApis(resourceReqDetails, packageFilePath, packageFileName, user);
// create VF base on VNF imported from previous step - have, resourceReqDetails object include part of resource metadata
- resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
- ExtentTestActions.log(Status.INFO, String.format("Create VF %s From VSP", resourceReqDetails.getName()));
+ OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
+ resourceReqDetails.setResourceType(resourceTypeEnum.getValue());
+ ExtentTestActions.log(Status.INFO, String.format("Create %s %s From VSP", resourceTypeEnum.getValue(), resourceReqDetails.getName()));
Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails, UserRoleEnum.DESIGNER);
- ExtentTestActions.log(Status.INFO, String.format("Certify VF"));
+ ExtentTestActions.log(Status.INFO, String.format("Certify %s", resourceTypeEnum.getValue()));
resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
//--------------------------SERVICE--------------------------------
ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(user);
ExtentTestActions.log(Status.INFO, String.format("Create Service %s", serviceReqDetails.getName()));
Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
- ExtentTestActions.log(Status.INFO, String.format("add VF to Service"));
+ ExtentTestActions.log(Status.INFO, String.format("Add %s to Service", resourceTypeEnum.getValue()));
Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
addComponentInstanceToComponentContainer.left().value();
- ExtentTestActions.log(Status.INFO, String.format("Certify Service"));
+ ExtentTestActions.log(Status.INFO,"Certify Service");
service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
if (makeDistributionValue.equals("true")) {
- ExtentTestActions.log(Status.INFO, String.format("Distribute Service"));
+ ExtentTestActions.log(Status.INFO, "Distribute Service");
AtomicOperationUtils.distributeService(service, true);
}
if (makeToscaValidationValue.equals("true")) {
-
ExtentTestActions.log(Status.INFO, "Start tosca validation");
- AtomicOperationUtils.toscaValidation(service ,vnfFile);
+ AtomicOperationUtils.toscaValidation(service ,packageFileName);
}
- ExtentTestActions.log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
+ ExtentTestActions.log(Status.INFO, String.format("The onboarding process for '%s' finished with success", packageFileName));
}
}