Generate rApp packages for unit test 95/12595/6
authoraravind.est <aravindhan.a@est.tech>
Wed, 6 Mar 2024 09:27:03 +0000 (09:27 +0000)
committeraravind.est <aravindhan.a@est.tech>
Thu, 7 Mar 2024 16:43:06 +0000 (16:43 +0000)
rApp packages for the unit tests are generated as part of the build process.
This script needs to be updated whenever there is a need to add new rApp package in unit tests.

Issue-ID: NONRTRIC-986
Change-Id: Ia883ec27c4275c04463a9bd8efd16471b7b24e9e
Signed-off-by: aravind.est <aravindhan.a@est.tech>
25 files changed:
.gitignore
pom.xml
rapp-manager-acm/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappInstanceControllerTest.java
rapp-manager-application/src/test/java/com/oransc/rappmanager/service/DeploymentArtifactsServiceTest.java
rapp-manager-application/src/test/resources/application.yaml [new file with mode: 0644]
rapp-manager-application/src/test/resources/invalid-rapp-package.csar [deleted file]
rapp-manager-application/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar [deleted file]
rapp-manager-dme/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/ArtifactDefinitionValidatorTest.java
rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package.csar [deleted file]
rapp-manager-models/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-sme/pom.xml
rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java
rapp-manager-sme/src/test/resources/valid-rapp-package.csar [deleted file]
scripts/init/generate-test-rapp-packages/generatetestrapppackages.go [new file with mode: 0755]
scripts/init/generate-test-rapp-packages/go.mod [new file with mode: 0644]
scripts/init/generate-test-rapp-packages/go.sum [new file with mode: 0644]

index 2cdd29e..a44c9cd 100755 (executable)
@@ -34,3 +34,4 @@ build/
 
 
 openapi/sme/
+*.csar
diff --git a/pom.xml b/pom.xml
index b772daa..79d2934 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
         <exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
         <apache.compress.version>1.25.0</apache.compress.version>
     </properties>
+    <profiles>
+        <profile>
+            <id>Windows</id>
+            <activation>
+                <os>
+                    <family>Windows</family>
+                </os>
+            </activation>
+            <properties>
+                <script.extension>.bat</script.extension>
+                <file.separator>\</file.separator>
+            </properties>
+        </profile>
+        <profile>
+            <id>unix</id>
+            <activation>
+                <os>
+                    <family>unix</family>
+                </os>
+            </activation>
+            <properties>
+                <script.extension>.sh</script.extension>
+                <file.separator>/</file.separator>
+            </properties>
+        </profile>
+    </profiles>
     <build>
         <plugins>
             <plugin>
                     <skipTests>false</skipTests>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <version>${exec-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <id>generate-test-csar-packages</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>exec</goal>
+                        </goals>
+                        <configuration>
+                            <workingDirectory>
+                                scripts/init/generate-test-rapp-packages
+                            </workingDirectory>
+                            <executable>
+                                go
+                            </executable>
+                            <arguments>
+                                <argument>run</argument>
+                                <argument>generatetestrapppackages.go</argument>
+                            </arguments>
+                        </configuration>
+                        <inherited>false</inherited>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
diff --git a/rapp-manager-acm/src/test/resources/valid-rapp-package.csar b/rapp-manager-acm/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index b6318e8..0000000
Binary files a/rapp-manager-acm/src/test/resources/valid-rapp-package.csar and /dev/null differ
index 5848fee..931901e 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START======================================================================
- * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2023-2024 OpenInfra Foundation Europe. 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.
@@ -27,13 +27,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.acm.service.AcmDeployer;
 import com.oransc.rappmanager.dme.service.DmeDeployer;
-import com.oransc.rappmanager.models.rappinstance.DeployOrder;
+import com.oransc.rappmanager.models.cache.RappCacheService;
 import com.oransc.rappmanager.models.rapp.Rapp;
+import com.oransc.rappmanager.models.rapp.RappState;
+import com.oransc.rappmanager.models.rappinstance.DeployOrder;
 import com.oransc.rappmanager.models.rappinstance.RappInstance;
 import com.oransc.rappmanager.models.rappinstance.RappInstanceDeployOrder;
 import com.oransc.rappmanager.models.rappinstance.RappInstanceState;
-import com.oransc.rappmanager.models.rapp.RappState;
-import com.oransc.rappmanager.models.cache.RappCacheService;
 import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine;
 import com.oransc.rappmanager.sme.service.SmeDeployer;
 import com.oransc.rappmanager.sme.service.SmeLifecycleManager;
@@ -76,7 +76,6 @@ class RappInstanceControllerTest {
 
     private final String validRappFile = "valid-rapp-package.csar";
 
-    private final String invalidRappFile = "invalid-rapp-package.csar";
     private final String validCsarFileLocation = "src/test/resources/";
 
     private final ObjectMapper objectMapper = new ObjectMapper();
index 5de2050..b8364d9 100755 (executable)
@@ -93,7 +93,7 @@ class DeploymentArtifactsServiceTest {
 
     @Test
     void testChartUploadNoArtifacts() {
-        String invalidRappFile = "invalid-rapp-package.csar";
+        String invalidRappFile = "valid-rapp-package-no-artifacts.csar";
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(invalidRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
diff --git a/rapp-manager-application/src/test/resources/application.yaml b/rapp-manager-application/src/test/resources/application.yaml
new file mode 100644 (file)
index 0000000..2a8489a
--- /dev/null
@@ -0,0 +1,39 @@
+rappmanager:
+  csarlocation: src/test/resources/csar
+  acm:
+    baseurl: http://localhost:30442/onap/policy/clamp/acm/v2/
+    username: runtimeUser
+    password: zb!XztG34
+    maxRetries: 10
+    retryInterval: 2 #seconds
+  sme:
+    baseurl: http://localhost:56571
+    providerBasePath: /api-provider-management/v1/
+    invokerBasePath: /api-invoker-management/v1/
+    publishApiBasePath: /published-apis/v1/
+    maxRetries: 3
+    retryInterval: 2 #seconds
+  dme:
+    baseurl: http://localhost:63475
+
+  rapps:
+    env:
+      smeDiscoveryEndpoint: http://localhost:53012/service-apis/v1/allServiceAPIs
+
+spring:
+  jackson:
+    default-property-inclusion: non_null
+
+logging:
+  level:
+    root: INFO
+    com.oransc: DEBUG
+    org.apache.http: DEBUG
+    httpclient.wire: DEBUG
+    org.springframework.web.client.RestTemplate: TRACE
+
+management:
+  endpoints:
+    web:
+      exposure:
+        include: "*"
diff --git a/rapp-manager-application/src/test/resources/invalid-rapp-package.csar b/rapp-manager-application/src/test/resources/invalid-rapp-package.csar
deleted file mode 100755 (executable)
index 81d084b..0000000
Binary files a/rapp-manager-application/src/test/resources/invalid-rapp-package.csar and /dev/null differ
diff --git a/rapp-manager-application/src/test/resources/valid-rapp-package.csar b/rapp-manager-application/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index 1dddd4a..0000000
Binary files a/rapp-manager-application/src/test/resources/valid-rapp-package.csar and /dev/null differ
diff --git a/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar b/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar
deleted file mode 100755 (executable)
index 36dd2e9..0000000
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar and /dev/null differ
diff --git a/rapp-manager-dme/src/test/resources/valid-rapp-package.csar b/rapp-manager-dme/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index 45a40e4..0000000
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package.csar and /dev/null differ
index be4e002..f1d3044 100755 (executable)
@@ -141,7 +141,7 @@ class RappCsarConfigurationHandlerTest {
         assertThat(rappResources).isNotNull();
         assertNotNull(rappResources.getAcm().getCompositionDefinitions());
         assertThat(rappResources.getAcm().getCompositionInstances()).hasSize(4);
-        assertThat(rappResources.getSme().getProviderFunctions()).hasSize(4);
+        assertThat(rappResources.getSme().getProviderFunctions()).hasSize(3);
         assertThat(rappResources.getSme().getServiceApis()).hasSize(2);
         assertThat(rappResources.getSme().getInvokers()).hasSize(2);
         assertThat(rappResources.getDme().getProducerInfoTypes()).hasSize(2);
index fa4377c..c220c54 100755 (executable)
@@ -58,8 +58,7 @@ class ArtifactDefinitionValidatorTest {
     RappValidationUtils rappValidationUtils;
     String validCsarFileLocation = "src/test/resources/";
     String validRappFile = "valid-rapp-package.csar";
-    String invalidRappFile = "invalid-rapp-package.csar";
-    String invalidRappAsdEmptyFile = "invalid-rapp-package-empty-asd-yaml.csar";
+    String invalidRappMissingArtifactFile = "invalid-rapp-package-missing-artifact.csar";
 
     @Test
     void testCsarContainsValidAsdFile() throws IOException {
@@ -72,7 +71,7 @@ class ArtifactDefinitionValidatorTest {
 
     @Test
     void testCsarContainsValidAsdFileFailure() throws IOException {
-        String rappCsarPath = validCsarFileLocation + File.separator + invalidRappFile;
+        String rappCsarPath = validCsarFileLocation + File.separator + invalidRappMissingArtifactFile;
         MultipartFile multipartFile =
                 new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
                         new FileInputStream(rappCsarPath));
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar
deleted file mode 100755 (executable)
index e146e59..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar
deleted file mode 100755 (executable)
index 39dd363..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar
deleted file mode 100755 (executable)
index 03e466f..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar
deleted file mode 100755 (executable)
index dade078..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar
deleted file mode 100755 (executable)
index 406a56d..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package.csar
deleted file mode 100755 (executable)
index d2d9e5e..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/valid-rapp-package.csar b/rapp-manager-models/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index a24a8c8..0000000
Binary files a/rapp-manager-models/src/test/resources/valid-rapp-package.csar and /dev/null differ
index 8463777..eb82cfa 100755 (executable)
@@ -4,6 +4,7 @@
 * O-RAN-SC
 * %%
 * Copyright (C) 2023 Nordix Foundation
+* Copyright (C) 2023-2024 OpenInfra Foundation Europe. 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.
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
     </properties>
-
-    <profiles>
-        <profile>
-            <id>Windows</id>
-            <activation>
-                <os>
-                    <family>Windows</family>
-                </os>
-            </activation>
-            <properties>
-                <script.extension>.bat</script.extension>
-                <file.separator>\</file.separator>
-            </properties>
-        </profile>
-        <profile>
-            <id>unix</id>
-            <activation>
-                <os>
-                    <family>unix</family>
-                </os>
-            </activation>
-            <properties>
-                <script.extension>.sh</script.extension>
-                <file.separator>/</file.separator>
-            </properties>
-        </profile>
-    </profiles>
-
     <dependencies>
         <dependency>
             <groupId>org.o-ran-sc.nonrtric.plt.rappmanager</groupId>
index b7bcab0..3daab9e 100755 (executable)
@@ -533,7 +533,7 @@ class SmeDeployerTest {
         rappSMEInstance.setServiceApis("api-set-1");
         rappSMEInstance.setAefId("TEST_AEF_ID");
         rappSMEInstance.setApfId(String.valueOf(UUID.randomUUID()));
-        rappSMEInstance.setProviderFunction("aef-provider-function");
+        rappSMEInstance.setProviderFunction("provider-function-1");
         RappInstance rappInstance = new RappInstance();
         rappInstance.setSme(rappSMEInstance);
         return rappInstance;
diff --git a/rapp-manager-sme/src/test/resources/valid-rapp-package.csar b/rapp-manager-sme/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index a269a48..0000000
Binary files a/rapp-manager-sme/src/test/resources/valid-rapp-package.csar and /dev/null differ
diff --git a/scripts/init/generate-test-rapp-packages/generatetestrapppackages.go b/scripts/init/generate-test-rapp-packages/generatetestrapppackages.go
new file mode 100755 (executable)
index 0000000..8d39e68
--- /dev/null
@@ -0,0 +1,242 @@
+// -
+//
+//     ========================LICENSE_START=================================
+//     O-RAN-SC
+//     %%
+//     Copyright (C) 2024 OpenInfra Foundation Europe. 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 main
+
+import (
+       "archive/zip"
+       "encoding/json"
+       "fmt"
+       "io"
+       "os"
+       "path/filepath"
+       "strings"
+
+       cp "github.com/otiai10/copy"
+       "gopkg.in/yaml.v2"
+)
+
+func replaceStringsInDirectory(directory, stringToFind, stringToReplace string) error {
+       files, err := os.ReadDir(directory)
+       checkError(err)
+       for _, file := range files {
+               filePath := filepath.Join(directory, file.Name())
+               if file.IsDir() {
+                       if err := replaceStringsInDirectory(filePath, stringToFind, stringToReplace); err != nil {
+                               return err
+                       }
+               } else {
+                       if err := replaceString(filePath, stringToFind, stringToReplace); err != nil {
+                               return err
+                       }
+               }
+       }
+       return nil
+}
+
+func replaceString(fileLocation, stringToFind, stringToReplace string) error {
+       fileContent, err := os.ReadFile(fileLocation)
+       checkError(err)
+       if !strings.Contains(string(fileContent), stringToFind) {
+               return nil
+       }
+       updatedContent := strings.ReplaceAll(string(fileContent), stringToFind, stringToReplace)
+       err = os.WriteFile(fileLocation, []byte(updatedContent), 0644)
+       checkError(err)
+       return nil
+}
+
+func updateChartMuseumUri(directory string) error {
+       CHART_MUSEUM_GET_URI := "http://localhost:8879/charts"
+       CHART_MUSEUM_POST_URI := "http://localhost:8879/charts/api/charts"
+       err := replaceStringsInDirectory(directory, "UPDATE_THIS_CHART_MUSEUM_POST_CHARTS_URI", CHART_MUSEUM_POST_URI)
+       checkError(err)
+       err = replaceStringsInDirectory(directory, "UPDATE_THIS_CHART_MUSEUM_GET_CHARTS_URI", CHART_MUSEUM_GET_URI)
+       checkError(err)
+       return nil
+}
+
+func generateCsarPackage(directory, fileName string) error {
+       csarFile, err := os.Create(fileName)
+       checkError(err)
+       defer csarFile.Close()
+       csarWriter := zip.NewWriter(csarFile)
+       defer csarWriter.Close()
+       err = filepath.Walk(directory, func(filePath string, fileInfo os.FileInfo, err error) error {
+               if fileInfo.IsDir() {
+                       return nil
+               }
+               relPath, err := filepath.Rel(directory, filePath)
+               checkError(err)
+               relPath = strings.ReplaceAll(relPath, "\\", "/")
+               zipFile, err := csarWriter.Create(relPath)
+               checkError(err)
+               fsFile, err := os.Open(filePath)
+               checkError(err)
+               _, err = io.Copy(zipFile, fsFile)
+               checkError(err)
+               defer fsFile.Close()
+               return nil
+       })
+       checkError(err)
+       return nil
+}
+
+func createCsarAndCopy(directory string, paths ...string) error {
+       packageName := directory + ".csar"
+       err := generateCsarPackage(directory, packageName)
+       checkError(err)
+       for _, path := range paths {
+               fmt.Printf("Copying %s to %s \n", packageName, path)
+               copy(packageName, path+packageName)
+       }
+       os.Remove(packageName)
+       os.RemoveAll(directory)
+       return nil
+}
+
+func copy(srcFile string, targetFile string) {
+       data, err := os.ReadFile(srcFile)
+       checkError(err)
+       err = os.WriteFile(targetFile, data, 0644)
+       checkError(err)
+}
+
+func checkError(err error) error {
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+func removeYamlElement(filePath string, elements ...string) error {
+       fileData, err := os.ReadFile(filePath)
+       checkError(err)
+       var yamlContent map[interface{}]interface{}
+       err = yaml.Unmarshal(fileData, &yamlContent)
+       checkError(err)
+       index := len(elements) - 1
+       dataMap := yamlContent
+       for i := 0; i < index; i++ {
+               resultMap, ok := dataMap[elements[i]].(map[interface{}]interface{})
+               if !ok {
+                       return nil
+               }
+               dataMap = resultMap
+       }
+       delete(dataMap, elements[index])
+       updatedYamlContent, err := yaml.Marshal(&yamlContent)
+       checkError(err)
+       err = os.WriteFile(filePath, updatedYamlContent, 0644)
+       checkError(err)
+       return nil
+}
+
+func addJsonElement(filePath string, element string, index string) error {
+       fileData, err := os.ReadFile(filePath)
+       checkError(err)
+       var jsonContent map[string]interface{}
+       err = json.Unmarshal(fileData, &jsonContent)
+       checkError(err)
+       array, ok := jsonContent[index].([]interface{})
+       if !ok {
+               return nil
+       }
+       jsonContent[index] = append(array, element)
+       updatedJsonContent, err := json.Marshal(&jsonContent)
+       checkError(err)
+       err = os.WriteFile(filePath, updatedJsonContent, 0644)
+       checkError(err)
+       return nil
+}
+
+func main() {
+
+       SAMPLE_RAPP_GENERATOR := "sample-rapp-generator"
+       RAPP_BASE_PACKAGE := "rapp-all"
+       TEST_RESOURCES := "/src/test/resources/"
+       ACM_TEST_RESOURCES := "../rapp-manager-acm" + TEST_RESOURCES
+       APPLICATION_TEST_RESOURCES := "../rapp-manager-application" + TEST_RESOURCES
+       MODELS_TEST_RESOURCES := "../rapp-manager-models" + TEST_RESOURCES
+       DME_TEST_RESOURCES := "../rapp-manager-dme" + TEST_RESOURCES
+       SME_TEST_RESOURCES := "../rapp-manager-sme" + TEST_RESOURCES
+
+       if err := os.Chdir("../../../" + SAMPLE_RAPP_GENERATOR); err != nil {
+               fmt.Println("Error changing working directory:", err)
+               return
+       }
+
+       fmt.Println("Generating valid rApp package... ")
+       VALID_RAPP_PACKAGE_FOLDER_NAME := "valid-rapp-package"
+       cp.Copy(RAPP_BASE_PACKAGE, VALID_RAPP_PACKAGE_FOLDER_NAME)
+       updateChartMuseumUri(VALID_RAPP_PACKAGE_FOLDER_NAME)
+       createCsarAndCopy(VALID_RAPP_PACKAGE_FOLDER_NAME, ACM_TEST_RESOURCES, DME_TEST_RESOURCES, SME_TEST_RESOURCES, MODELS_TEST_RESOURCES, APPLICATION_TEST_RESOURCES)
+
+       fmt.Println("Generating valid rApp package without artifacts...")
+       VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME := "valid-rapp-package-no-artifacts"
+       cp.Copy(RAPP_BASE_PACKAGE, VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME)
+       updateChartMuseumUri(VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME)
+       removeYamlElement(VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME+"/Definitions/asd.yaml", "topology_template", "node_templates", "applicationServiceDescriptor", "artifacts")
+       createCsarAndCopy(VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME, APPLICATION_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package...")
+       INVALID_RAPP_PACKAGE_FOLDER_NAME := "invalid-rapp-package"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_FOLDER_NAME)
+       os.RemoveAll(INVALID_RAPP_PACKAGE_FOLDER_NAME + "/Files")
+       os.RemoveAll(INVALID_RAPP_PACKAGE_FOLDER_NAME + "/Artifacts")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_FOLDER_NAME, MODELS_TEST_RESOURCES, APPLICATION_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without tosca...")
+       INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME := "invalid-rapp-package-no-tosca"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME + "/TOSCA-Metadata/TOSCA.meta")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without asd yaml...")
+       INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME := "invalid-rapp-package-no-asd-yaml"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME + "/Definitions/asd.yaml")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without ACM composition...")
+       INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME := "invalid-rapp-package-no-acm-composition"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME + "/Files/Acm/definition/compositions.json")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without Artifacts...")
+       INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME := "invalid-rapp-package-missing-artifact"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME + "/Artifacts/Deployment/HELM/orufhrecovery-1.0.0.tgz")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package with empty asd yaml...")
+       INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME := "invalid-rapp-package-empty-asd-yaml"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME)
+       os.Truncate(INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME+"/Definitions/asd.yaml", 0)
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating valid rApp package with new dme info type...")
+       VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME := "valid-rapp-package-new-info-type"
+       DME_PRODUCER_FILE := VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME + "/Files/Dme/infoproducers/json-file-data-producer.json"
+       cp.Copy(RAPP_BASE_PACKAGE, VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME)
+       addJsonElement(DME_PRODUCER_FILE, "new-info-type-not-available", "supported_info_types")
+       createCsarAndCopy(VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME, DME_TEST_RESOURCES)
+
+}
diff --git a/scripts/init/generate-test-rapp-packages/go.mod b/scripts/init/generate-test-rapp-packages/go.mod
new file mode 100644 (file)
index 0000000..7be5956
--- /dev/null
@@ -0,0 +1,13 @@
+module oransc.org/nonrtric/rappmanager/generatetestrapppackages
+
+go 1.22
+
+require (
+       github.com/otiai10/copy v1.14.0
+       gopkg.in/yaml.v2 v2.4.0
+)
+
+require (
+       golang.org/x/sync v0.3.0 // indirect
+       golang.org/x/sys v0.8.0 // indirect
+)
diff --git a/scripts/init/generate-test-rapp-packages/go.sum b/scripts/init/generate-test-rapp-packages/go.sum
new file mode 100644 (file)
index 0000000..96997a3
--- /dev/null
@@ -0,0 +1,12 @@
+github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
+github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
+github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
+github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
+golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
+golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
+golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=