Fix ASD CSAR file processing when the contents are in alphabetical order 20/134420/1
authoraravind.est <aravindhan.a@est.tech>
Tue, 2 May 2023 15:13:29 +0000 (16:13 +0100)
committeraravind.est <aravindhan.a@est.tech>
Tue, 2 May 2023 15:13:29 +0000 (16:13 +0100)
Fixed the CSAR file processing when the contents of the CSAR file is in alphabetical order (Definitions/asd.yaml file before TOSCA-Metadata/TOSCA.meta).

Issue-ID: SO-4098
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: I0e9c0730825eca4069ac4cb0f7ae2f97ed56efaf

so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/sdc/SdcCsarPackageParser.java
so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/test/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/sdc/SdcCsarPackageParserTest.java
so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/test/resources/resource-Generatedasdpackage-csar-alphabetical.csar [new file with mode: 0755]

index c06d42f..cc4b783 100644 (file)
@@ -70,9 +70,11 @@ public class SdcCsarPackageParser {
     public Map<String, Object> getAsdProperties(final byte[] onapPackage) {
 
         try (final ByteArrayInputStream stream = new ByteArrayInputStream(onapPackage);
-                final ZipInputStream zipInputStream = new ZipInputStream(stream);) {
-            final String asdLocation = getAsdLocation(zipInputStream);
-            final String onapAsdContent = getFileInZip(zipInputStream, asdLocation).toString();
+                final ZipInputStream zipInputStreamAsdLocation = new ZipInputStream(stream);
+             final ZipInputStream zipInputStreamAsdContent = new ZipInputStream(stream);) {
+            final String asdLocation = getAsdLocation(zipInputStreamAsdLocation);
+            stream.reset();
+            final String onapAsdContent = getFileInZip(zipInputStreamAsdContent, asdLocation).toString();
             logger.debug("ASD CONTENTS: {}", onapAsdContent);
             final JsonObject root = new Gson().toJsonTree(new Yaml().load(onapAsdContent)).getAsJsonObject();
 
index 8374faa..9de5419 100644 (file)
@@ -29,25 +29,41 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  *
  * @author Waqas Ikram (waqas.ikram@est.tech)
  *
  */
+@RunWith(Parameterized.class)
 public class SdcCsarPackageParserTest {
 
     private static final String RESOURCE_ASD_PACKAGE_CSAR_PATH =
             "src/test/resources/resource-Generatedasdpackage-csar.csar";
 
+    private static final String RESOURCE_ASD_ALPHABETICAL_PACKAGE_CSAR_PATH =
+            "src/test/resources/resource-Generatedasdpackage-csar-alphabetical.csar";
+
+
+    @Parameterized.Parameter
+    public String resourceCsarPath;
+
+    @Parameterized.Parameters
+    public static Iterable<String> data() {
+        return Arrays.asList(RESOURCE_ASD_PACKAGE_CSAR_PATH, RESOURCE_ASD_ALPHABETICAL_PACKAGE_CSAR_PATH);
+    }
+
     @Test
     public void testResourceAsdCsar() throws IOException {
         final SdcCsarPackageParser objUnderTest = new SdcCsarPackageParser();
 
-        final byte[] content = getFileContent(Paths.get(getAbsolutePath(RESOURCE_ASD_PACKAGE_CSAR_PATH)));
+        final byte[] content = getFileContent(Paths.get(getAbsolutePath(resourceCsarPath)));
 
         final Map<String, Object> properties = objUnderTest.getAsdProperties(content);
         assertEquals("123e4567-e89b-12d3-a456-426614174000", properties.get(DESCRIPTOR_ID_PARAM_NAME));
diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/test/resources/resource-Generatedasdpackage-csar-alphabetical.csar b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/test/resources/resource-Generatedasdpackage-csar-alphabetical.csar
new file mode 100755 (executable)
index 0000000..42f2f86
Binary files /dev/null and b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/test/resources/resource-Generatedasdpackage-csar-alphabetical.csar differ