Add validation for asd descriptor and invariant id 63/12563/1
authoraravind.est <aravindhan.a@est.tech>
Thu, 22 Feb 2024 16:01:11 +0000 (16:01 +0000)
committeraravind.est <aravindhan.a@est.tech>
Thu, 22 Feb 2024 16:05:01 +0000 (16:05 +0000)
ASD package validation has been added for descriptor and invariant id.
This validates based on the rApp already created. If the application restarts the cache gets cleared.

Issue-ID: NONRTRIC-984
Change-Id: Icf76553dbe5dca710801fefa551ae9e81d986ca5
Signed-off-by: aravind.est <aravindhan.a@est.tech>
29 files changed:
rapp-manager-acm/src/test/resources/valid-rapp-package.csar
rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java
rapp-manager-application/src/main/java/com/oransc/rappmanager/service/DeploymentArtifactsService.java
rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappControllerTest.java
rapp-manager-application/src/test/java/com/oransc/rappmanager/service/DeploymentArtifactsServiceTest.java
rapp-manager-application/src/test/resources/invalid-rapp-package.csar
rapp-manager-application/src/test/resources/valid-rapp-package.csar
rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar
rapp-manager-dme/src/test/resources/valid-rapp-package.csar
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/AsdMetadata.java [new file with mode: 0755]
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarPathProvider.java
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/validator/ArtifactDefinitionValidator.java
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/validator/AsdDescriptorValidator.java [new file with mode: 0755]
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/Rapp.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/BeanTestConfiguration.java [moved from rapp-manager-models/src/test/java/com/oransc/rappmanager/models/cache/BeanTestConfiguration.java with 88% similarity]
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/cache/RappCacheServiceTest.java
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/java/com/oransc/rappmanager/models/csar/validator/AsdDescriptorValidatorTest.java [new file with mode: 0755]
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/RappValidationHandlerTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/RappValidationUtilsTest.java
rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar
rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar
rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar
rapp-manager-models/src/test/resources/invalid-rapp-package.csar
rapp-manager-models/src/test/resources/valid-rapp-package.csar
rapp-manager-sme/src/test/resources/valid-rapp-package.csar
sample-rapp-generator/rapp-all/Definitions/asd.yaml

index 4856dab..b6318e8 100755 (executable)
Binary files a/rapp-manager-acm/src/test/resources/valid-rapp-package.csar and b/rapp-manager-acm/src/test/resources/valid-rapp-package.csar differ
index 85e1a44..9b448cd 100755 (executable)
@@ -87,6 +87,7 @@ public class RappController {
             Rapp rapp = Rapp.builder().name(rappId).packageLocation(rappManagerConfiguration.getCsarLocation())
                                 .packageName(csarFile.getName()).state(RappState.COMMISSIONED).build();
             rapp.setRappResources(rappCsarConfigurationHandler.getRappResource(rapp));
             Rapp rapp = Rapp.builder().name(rappId).packageLocation(rappManagerConfiguration.getCsarLocation())
                                 .packageName(csarFile.getName()).state(RappState.COMMISSIONED).build();
             rapp.setRappResources(rappCsarConfigurationHandler.getRappResource(rapp));
+            rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
             rappCacheService.putRapp(rapp);
             return ResponseEntity.accepted().build();
         } else {
             rappCacheService.putRapp(rapp);
             return ResponseEntity.accepted().build();
         } else {
index aaafdb2..a037f02 100755 (executable)
@@ -24,7 +24,6 @@ import com.oransc.rappmanager.models.csar.DeploymentItemArtifactType;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappHandlerException;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappHandlerException;
 import com.oransc.rappmanager.models.rapp.Rapp;
-import java.util.List;
 import lombok.RequiredArgsConstructor;
 import org.springframework.core.io.ByteArrayResource;
 import org.springframework.http.HttpEntity;
 import lombok.RequiredArgsConstructor;
 import org.springframework.core.io.ByteArrayResource;
 import org.springframework.http.HttpEntity;
@@ -45,9 +44,9 @@ public class DeploymentArtifactsService {
     private final RappCsarConfigurationHandler rappCsarConfigurationHandler;
 
     public boolean configureDeploymentArtifacts(Rapp rapp) {
     private final RappCsarConfigurationHandler rappCsarConfigurationHandler;
 
     public boolean configureDeploymentArtifacts(Rapp rapp) {
-        List<DeploymentItem> deploymentItems = rappCsarConfigurationHandler.getDeploymentItems(rapp);
-        return deploymentItems.stream().filter(deploymentItem -> deploymentItem.getArtifactType()
-                                                                         .equals(DeploymentItemArtifactType.HELMCHART))
+        return rapp.getAsdMetadata().getDeploymentItems().stream()
+                       .filter(deploymentItem -> deploymentItem.getArtifactType()
+                                                         .equals(DeploymentItemArtifactType.HELMCHART))
                        .allMatch(deploymentItem -> uploadHelmChart(rapp, deploymentItem));
     }
 
                        .allMatch(deploymentItem -> uploadHelmChart(rapp, deploymentItem));
     }
 
index 51fc204..6e7566d 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START======================================================================
 /*
  * ============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.
  * ===============================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ 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.cache.RappCacheService;
 import com.oransc.rappmanager.acm.service.AcmDeployer;
 import com.oransc.rappmanager.dme.service.DmeDeployer;
 import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.csar.AsdMetadata;
 import com.oransc.rappmanager.models.rapp.PrimeOrder;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappPrimeOrder;
 import com.oransc.rappmanager.models.rapp.PrimeOrder;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappPrimeOrder;
@@ -35,6 +36,7 @@ import com.oransc.rappmanager.models.rapp.RappState;
 import com.oransc.rappmanager.sme.service.SmeLifecycleManager;
 import java.io.File;
 import java.io.FileInputStream;
 import com.oransc.rappmanager.sme.service.SmeLifecycleManager;
 import java.io.File;
 import java.io.FileInputStream;
+import java.util.List;
 import java.util.UUID;
 import org.apache.http.entity.ContentType;
 import org.junit.jupiter.api.Test;
 import java.util.UUID;
 import org.apache.http.entity.ContentType;
 import org.junit.jupiter.api.Test;
@@ -82,6 +84,11 @@ class RappControllerTest {
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+        AsdMetadata asdMetadata = new AsdMetadata();
+        asdMetadata.setDescriptorId(UUID.randomUUID().toString());
+        asdMetadata.setDescriptorInvariantId(UUID.randomUUID().toString());
+        asdMetadata.setDeploymentItems(List.of());
+        rapp.setAsdMetadata(asdMetadata);
         rappCacheService.putRapp(rapp);
         mockMvc.perform(MockMvcRequestBuilders.get("/rapps")).andExpect(status().isOk())
                 .andExpect(jsonPath("$", hasSize(1)));
         rappCacheService.putRapp(rapp);
         mockMvc.perform(MockMvcRequestBuilders.get("/rapps")).andExpect(status().isOk())
                 .andExpect(jsonPath("$", hasSize(1)));
@@ -92,6 +99,11 @@ class RappControllerTest {
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+        AsdMetadata asdMetadata = new AsdMetadata();
+        asdMetadata.setDescriptorId(UUID.randomUUID().toString());
+        asdMetadata.setDescriptorInvariantId(UUID.randomUUID().toString());
+        asdMetadata.setDeploymentItems(List.of());
+        rapp.setAsdMetadata(asdMetadata);
         rappCacheService.putRapp(rapp);
         mockMvc.perform(MockMvcRequestBuilders.get("/rapps/{rapp_id}", rappId)).andExpect(status().isOk())
                 .andExpect(jsonPath("$.rappId").value(rappId.toString()))
         rappCacheService.putRapp(rapp);
         mockMvc.perform(MockMvcRequestBuilders.get("/rapps/{rapp_id}", rappId)).andExpect(status().isOk())
                 .andExpect(jsonPath("$.rappId").value(rappId.toString()))
@@ -129,6 +141,11 @@ class RappControllerTest {
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+        AsdMetadata asdMetadata = new AsdMetadata();
+        asdMetadata.setDescriptorId(UUID.randomUUID().toString());
+        asdMetadata.setDescriptorInvariantId(UUID.randomUUID().toString());
+        asdMetadata.setDeploymentItems(List.of());
+        rapp.setAsdMetadata(asdMetadata);
         rappCacheService.putRapp(rapp);
         when(acmDeployer.primeRapp(any())).thenReturn(true);
         when(dmeDeployer.primeRapp(any())).thenReturn(true);
         rappCacheService.putRapp(rapp);
         when(acmDeployer.primeRapp(any())).thenReturn(true);
         when(dmeDeployer.primeRapp(any())).thenReturn(true);
@@ -154,6 +171,11 @@ class RappControllerTest {
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
+        AsdMetadata asdMetadata = new AsdMetadata();
+        asdMetadata.setDescriptorId(UUID.randomUUID().toString());
+        asdMetadata.setDescriptorInvariantId(UUID.randomUUID().toString());
+        asdMetadata.setDeploymentItems(List.of());
+        rapp.setAsdMetadata(asdMetadata);
         rappCacheService.putRapp(rapp);
         when(acmDeployer.deprimeRapp(any())).thenReturn(true);
         when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
         rappCacheService.putRapp(rapp);
         when(acmDeployer.deprimeRapp(any())).thenReturn(true);
         when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
@@ -168,6 +190,11 @@ class RappControllerTest {
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         UUID rappId = UUID.randomUUID();
         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+        AsdMetadata asdMetadata = new AsdMetadata();
+        asdMetadata.setDescriptorId(UUID.randomUUID().toString());
+        asdMetadata.setDescriptorInvariantId(UUID.randomUUID().toString());
+        asdMetadata.setDeploymentItems(List.of());
+        rapp.setAsdMetadata(asdMetadata);
         rappCacheService.putRapp(rapp);
         mockMvc.perform(MockMvcRequestBuilders.delete("/rapps/{rapp_id}", rappId)).andExpect(status().isOk());
     }
         rappCacheService.putRapp(rapp);
         mockMvc.perform(MockMvcRequestBuilders.delete("/rapps/{rapp_id}", rappId)).andExpect(status().isOk());
     }
index 4a3a08a..5de2050 100755 (executable)
@@ -80,8 +80,10 @@ class DeploymentArtifactsServiceTest {
     @EnumSource(value = HttpStatus.class, names = {"CREATED", "CONFLICT"})
     void testChartUpload(HttpStatus status) {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
     @EnumSource(value = HttpStatus.class, names = {"CREATED", "CONFLICT"})
     void testChartUpload(HttpStatus status) {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
-                            .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
-        List<DeploymentItem> deploymentItems = rappCsarConfigurationHandler.getDeploymentItems(rapp);
+                            .packageLocation(validCsarFileLocation)
+                            .state(RappState.COMMISSIONED).build();
+        rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
+        List<DeploymentItem> deploymentItems = rapp.getAsdMetadata().getDeploymentItems();
         deploymentItems.forEach(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                         requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST))
                                                           .andRespond(withStatus(status)));
         deploymentItems.forEach(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                         requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST))
                                                           .andRespond(withStatus(status)));
@@ -94,6 +96,7 @@ class DeploymentArtifactsServiceTest {
         String invalidRappFile = "invalid-rapp-package.csar";
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(invalidRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         String invalidRappFile = "invalid-rapp-package.csar";
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(invalidRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+        rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
         assertTrue(deploymentArtifactsService.configureDeploymentArtifacts(rapp));
     }
 
         assertTrue(deploymentArtifactsService.configureDeploymentArtifacts(rapp));
     }
 
@@ -101,7 +104,8 @@ class DeploymentArtifactsServiceTest {
     void testChartUploadFailure() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
     void testChartUploadFailure() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
-        List<DeploymentItem> deploymentItems = rappCsarConfigurationHandler.getDeploymentItems(rapp);
+        rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
+        List<DeploymentItem> deploymentItems = rapp.getAsdMetadata().getDeploymentItems();
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                         requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST))
                                                                                  .andRespond(withServerError()));
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                         requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST))
                                                                                  .andRespond(withServerError()));
@@ -115,7 +119,8 @@ class DeploymentArtifactsServiceTest {
     void testChartUploadFailureWithNotFound() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
     void testChartUploadFailureWithNotFound() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
-        List<DeploymentItem> deploymentItems = rappCsarConfigurationHandler.getDeploymentItems(rapp);
+        rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
+        List<DeploymentItem> deploymentItems = rapp.getAsdMetadata().getDeploymentItems();
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                 requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST)).andRespond(
                 withStatus(HttpStatus.NOT_FOUND)));
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                 requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST)).andRespond(
                 withStatus(HttpStatus.NOT_FOUND)));
@@ -127,7 +132,8 @@ class DeploymentArtifactsServiceTest {
     void testChartUploadFailureWithException() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
     void testChartUploadFailureWithException() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
-        List<DeploymentItem> deploymentItems = rappCsarConfigurationHandler.getDeploymentItems(rapp);
+        rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
+        List<DeploymentItem> deploymentItems = rapp.getAsdMetadata().getDeploymentItems();
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                 requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST)).andRespond(
                 withException(new IOException())));
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                 requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST)).andRespond(
                 withException(new IOException())));
@@ -141,7 +147,8 @@ class DeploymentArtifactsServiceTest {
     void testChartUploadFailureWithTooManyRequests() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
     void testChartUploadFailureWithTooManyRequests() {
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
-        List<DeploymentItem> deploymentItems = rappCsarConfigurationHandler.getDeploymentItems(rapp);
+        rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
+        List<DeploymentItem> deploymentItems = rapp.getAsdMetadata().getDeploymentItems();
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                         requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST))
                                                                                  .andRespond(withTooManyRequests()));
         deploymentItems.stream().findFirst().ifPresent(deploymentItem -> mockServer.expect(ExpectedCount.once(),
                         requestTo(deploymentItem.getTargetServerUri())).andExpect(method(HttpMethod.POST))
                                                                                  .andRespond(withTooManyRequests()));
index 97efcb5..81d084b 100755 (executable)
Binary files a/rapp-manager-application/src/test/resources/invalid-rapp-package.csar and b/rapp-manager-application/src/test/resources/invalid-rapp-package.csar differ
index 526d5d9..1dddd4a 100755 (executable)
Binary files a/rapp-manager-application/src/test/resources/valid-rapp-package.csar and b/rapp-manager-application/src/test/resources/valid-rapp-package.csar differ
index f51cfb2..36dd2e9 100755 (executable)
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar and b/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar differ
index 3454443..45a40e4 100755 (executable)
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package.csar and b/rapp-manager-dme/src/test/resources/valid-rapp-package.csar differ
diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/AsdMetadata.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/AsdMetadata.java
new file mode 100755 (executable)
index 0000000..bc97d1e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START======================================================================
+ * 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 com.oransc.rappmanager.models.csar;
+
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
+import com.fasterxml.jackson.databind.annotation.JsonNaming;
+import java.util.List;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
+public class AsdMetadata {
+
+    String description;
+    String descriptorId;
+    String descriptorInvariantId;
+    String descriptorVersion;
+    String schemaVersion;
+    String functionDescription;
+    String provider;
+    String applicationName;
+    String applicationVersion;
+    List<DeploymentItem> deploymentItems;
+}
index 1babdd2..f71315f 100755 (executable)
@@ -138,27 +138,7 @@ public class RappCsarConfigurationHandler {
         return asdLocation;
     }
 
         return asdLocation;
     }
 
-    public List<DeploymentItem> getDeploymentItems(Rapp rApp) {
-        List<DeploymentItem> deploymentItems = new ArrayList<>();
-        File csarFile = getCsarFile(rApp);
-        String asdDefinitionLocation = getAsdDefinitionLocation(csarFile);
-        if (asdDefinitionLocation != null && !asdDefinitionLocation.isEmpty()) {
-            try {
-                String asdContent = getFileFromCsar(csarFile, asdDefinitionLocation).toString();
-                JsonNode jsonNode = getAsdContentNode(asdContent);
-                JsonNode artifactsJsonNode = jsonNode.at(RappCsarPathProvider.ARTIFACTS_LOCATION_JSON_POINTER);
-                artifactsJsonNode.forEach(artifactJsonNode -> {
-                    DeploymentItem deploymentItem =
-                            objectMapper.convertValue(artifactJsonNode.at("/properties"), DeploymentItem.class);
-                    deploymentItem.setFile(artifactJsonNode.at("/file").asText());
-                    deploymentItems.add(deploymentItem);
-                });
-            } catch (Exception e) {
-                logger.warn("Unable to get the deployment items", e);
-            }
-        }
-        return deploymentItems;
-    }
+
 
 
     public String getSmeProviderDomainPayload(Rapp rapp, RappSMEInstance rappSMEInstance) {
 
 
     public String getSmeProviderDomainPayload(Rapp rapp, RappSMEInstance rappSMEInstance) {
@@ -232,6 +212,36 @@ public class RappCsarConfigurationHandler {
         return rappResources;
     }
 
         return rappResources;
     }
 
+    public AsdMetadata getAsdMetadata(Rapp rApp) {
+        AsdMetadata asdMetadata = new AsdMetadata();
+        File csarFile = getCsarFile(rApp);
+        String asdDefinitionLocation = getAsdDefinitionLocation(csarFile);
+        if (asdDefinitionLocation != null && !asdDefinitionLocation.isEmpty()) {
+            try {
+                String asdContent = getFileFromCsar(csarFile, asdDefinitionLocation).toString();
+                if (asdContent != null && !asdContent.isEmpty()) {
+                    JsonNode jsonNode = getAsdContentNode(asdContent);
+                    JsonNode asdJsonNode = jsonNode.at(RappCsarPathProvider.ASD_LOCATION_JSON_POINTER);
+                    asdMetadata = objectMapper.convertValue(asdJsonNode.at("/properties"), AsdMetadata.class);
+                    asdMetadata.setDescription(asdJsonNode.at("/description").asText());
+
+                    JsonNode artifactsJsonNode = jsonNode.at(RappCsarPathProvider.ASD_ARTIFACTS_LOCATION_JSON_POINTER);
+                    final List<DeploymentItem> deploymentItems = new ArrayList<>();
+                    artifactsJsonNode.forEach(artifactJsonNode -> {
+                        DeploymentItem deploymentItem =
+                                objectMapper.convertValue(artifactJsonNode.at("/properties"), DeploymentItem.class);
+                        deploymentItem.setFile(artifactJsonNode.at("/file").asText());
+                        deploymentItems.add(deploymentItem);
+                    });
+                    asdMetadata.setDeploymentItems(deploymentItems);
+                }
+            } catch (Exception e) {
+                logger.warn("Unable to get the asd metadata items", e);
+            }
+        }
+        return asdMetadata;
+    }
+
     Set<String> getFileListFromCsar(File csarFile, String dirLocation) {
         try (ZipFile zipFile = new ZipFile(csarFile)) {
             return zipFile.stream().filter(Predicate.not(ZipEntry::isDirectory)).map(ZipEntry::getName)
     Set<String> getFileListFromCsar(File csarFile, String dirLocation) {
         try (ZipFile zipFile = new ZipFile(csarFile)) {
             return zipFile.stream().filter(Predicate.not(ZipEntry::isDirectory)).map(ZipEntry::getName)
index 745ae14..57a650c 100755 (executable)
@@ -36,6 +36,11 @@ public class RappCsarPathProvider {
     public static final String DME_CONSUMER_INFO_TYPES_LOCATION = "Files/Dme/consumerinfotypes";
     public static final String DME_INFO_PRODUCERS_LOCATION = "Files/Dme/infoproducers";
     public static final String DME_INFO_CONSUMERS_LOCATION = "Files/Dme/infoconsumers";
     public static final String DME_CONSUMER_INFO_TYPES_LOCATION = "Files/Dme/consumerinfotypes";
     public static final String DME_INFO_PRODUCERS_LOCATION = "Files/Dme/infoproducers";
     public static final String DME_INFO_CONSUMERS_LOCATION = "Files/Dme/infoconsumers";
-    public static final String ARTIFACTS_LOCATION_JSON_POINTER =
-            "/topology_template/node_templates/applicationServiceDescriptor/artifacts";
-}
\ No newline at end of file
+    public static final String ASD_LOCATION_JSON_POINTER =
+            "/topology_template/node_templates/applicationServiceDescriptor";
+    public static final String ASD_PROPERTIES_JSON_POINTER = ASD_LOCATION_JSON_POINTER + "/properties";
+    public static final String ASD_ARTIFACTS_LOCATION_JSON_POINTER = ASD_LOCATION_JSON_POINTER + "/artifacts";
+    public static final String ASD_DESCRIPTOR_JSON_POINTER = ASD_PROPERTIES_JSON_POINTER + "/descriptor_id";
+    public static final String ASD_DESCRIPTOR_VARIANT_LOCATION_JSON_POINTER =
+            ASD_PROPERTIES_JSON_POINTER + "/descriptor_invariant_id";
+}
index ac00e95..082a156 100755 (executable)
@@ -36,7 +36,7 @@ public class ArtifactDefinitionValidator implements RappValidator {
     private final RappCsarConfigurationHandler rappCsarConfigurationHandler;
     private final RappValidationUtils rappValidationUtils;
     String invalidAsdErrorMsg = "ASD definition in rApp package is invalid.";
     private final RappCsarConfigurationHandler rappCsarConfigurationHandler;
     private final RappValidationUtils rappValidationUtils;
     String invalidAsdErrorMsg = "ASD definition in rApp package is invalid.";
-    private static final int VALIDATION_ORDER = 10;
+    private static final int VALIDATION_ORDER = 15;
 
     @Override
     public int getOrder() {
 
     @Override
     public int getOrder() {
@@ -47,25 +47,16 @@ public class ArtifactDefinitionValidator implements RappValidator {
     public void validate(Object target, Errors errors) {
         MultipartFile multipartFile = (MultipartFile) target;
         String asdLocation = rappValidationUtils.getAsdDefinitionLocation(multipartFile);
     public void validate(Object target, Errors errors) {
         MultipartFile multipartFile = (MultipartFile) target;
         String asdLocation = rappValidationUtils.getAsdDefinitionLocation(multipartFile);
-        if (asdLocation != null && !asdLocation.isEmpty() && rappValidationUtils.isFileExistsInCsar(multipartFile,
-                asdLocation)) {
-            try {
-                String asdContent = rappValidationUtils.getFileFromCsar(multipartFile, asdLocation).toString();
-                if(asdContent != null && !asdContent.isEmpty()) {
-                    JsonNode jsonNode = rappCsarConfigurationHandler.getAsdContentNode(asdContent);
-                    List<String> artifactFileList =
-                            jsonNode.at(RappCsarPathProvider.ARTIFACTS_LOCATION_JSON_POINTER).findValuesAsText("file");
-                    artifactFileList.forEach(
-                            artifactFile -> rappValidationUtils.isFileExistsInCsar(multipartFile, artifactFile));
-                } else {
-                    throw new RappValidationException(invalidAsdErrorMsg);
-                }
-            } catch (RappValidationException e) {
-                throw new RappValidationException(e.getMessage());
-            } catch (Exception e) {
-                throw new RappValidationException(invalidAsdErrorMsg);
-            }
-        } else {
+        try {
+            String asdContent = rappValidationUtils.getFileFromCsar(multipartFile, asdLocation).toString();
+            JsonNode jsonNode = rappCsarConfigurationHandler.getAsdContentNode(asdContent);
+            List<String> artifactFileList =
+                    jsonNode.at(RappCsarPathProvider.ASD_ARTIFACTS_LOCATION_JSON_POINTER).findValuesAsText("file");
+            artifactFileList.forEach(
+                    artifactFile -> rappValidationUtils.isFileExistsInCsar(multipartFile, artifactFile));
+        } catch (RappValidationException e) {
+            throw new RappValidationException(e.getMessage());
+        } catch (Exception e) {
             throw new RappValidationException(invalidAsdErrorMsg);
         }
     }
             throw new RappValidationException(invalidAsdErrorMsg);
         }
     }
diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/validator/AsdDescriptorValidator.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/validator/AsdDescriptorValidator.java
new file mode 100755 (executable)
index 0000000..643714e
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * ============LICENSE_START======================================================================
+ * 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 com.oransc.rappmanager.models.csar.validator;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
+import com.oransc.rappmanager.models.csar.RappCsarPathProvider;
+import com.oransc.rappmanager.models.exception.RappValidationException;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+import org.springframework.validation.Errors;
+import org.springframework.web.multipart.MultipartFile;
+
+@Component
+@RequiredArgsConstructor
+public class AsdDescriptorValidator implements RappValidator {
+
+    private final RappCacheService rappCacheService;
+    private final RappValidationUtils rappValidationUtils;
+    private final RappCsarConfigurationHandler rappCsarConfigurationHandler;
+    String invalidAsdErrorMsg = "ASD definition in rApp package is invalid.";
+
+    private static final int VALIDATION_ORDER = 10;
+
+    @Override
+    public int getOrder() {
+        return VALIDATION_ORDER;
+    }
+
+    @Override
+    public void validate(Object target, Errors errors) {
+        MultipartFile multipartFile = (MultipartFile) target;
+        String asdLocation = rappValidationUtils.getAsdDefinitionLocation(multipartFile);
+        if (asdLocation != null && !asdLocation.isEmpty() && rappValidationUtils.isFileExistsInCsar(multipartFile,
+                asdLocation)) {
+            try {
+                String asdContent = rappValidationUtils.getFileFromCsar(multipartFile, asdLocation).toString();
+                if (asdContent != null && !asdContent.isEmpty()) {
+                    JsonNode jsonNode = rappCsarConfigurationHandler.getAsdContentNode(asdContent);
+                    checkAsdDescriptorExists(jsonNode.at(RappCsarPathProvider.ASD_DESCRIPTOR_JSON_POINTER).asText());
+                    checkAsdDescriptorVariantExists(
+                            jsonNode.at(RappCsarPathProvider.ASD_DESCRIPTOR_VARIANT_LOCATION_JSON_POINTER).asText());
+                } else {
+                    throw new RappValidationException(invalidAsdErrorMsg);
+                }
+            } catch (RappValidationException e) {
+                throw new RappValidationException(e.getMessage());
+            } catch (Exception e) {
+                throw new RappValidationException(invalidAsdErrorMsg);
+            }
+        } else {
+            throw new RappValidationException(invalidAsdErrorMsg);
+        }
+    }
+
+    boolean checkAsdDescriptorExists(String descriptorId) {
+        if (rappCacheService.getAllRapp().stream()
+                    .anyMatch(rapp -> rapp.getAsdMetadata().getDescriptorId().equals(descriptorId))) {
+            throw new RappValidationException("ASD descriptor already exists.");
+        }
+        return true;
+    }
+
+    boolean checkAsdDescriptorVariantExists(String descriptorVariantId) {
+        if (rappCacheService.getAllRapp().stream()
+                    .anyMatch(rapp -> rapp.getAsdMetadata().getDescriptorInvariantId().equals(descriptorVariantId))) {
+            throw new RappValidationException("ASD descriptor invariant already exists.");
+        }
+        return true;
+    }
+}
index d061602..6619061 100755 (executable)
@@ -20,6 +20,7 @@
 package com.oransc.rappmanager.models.rapp;
 
 
 package com.oransc.rappmanager.models.rapp;
 
 
+import com.oransc.rappmanager.models.csar.AsdMetadata;
 import com.oransc.rappmanager.models.rappinstance.RappInstance;
 import java.beans.Transient;
 import java.util.HashMap;
 import com.oransc.rappmanager.models.rappinstance.RappInstance;
 import java.beans.Transient;
 import java.util.HashMap;
@@ -41,6 +42,7 @@ public class Rapp {
     String packageLocation;
     String packageName;
     RappResources rappResources;
     String packageLocation;
     String packageName;
     RappResources rappResources;
+    AsdMetadata asdMetadata;
     @Builder.Default
     Map<UUID, RappInstance> rappInstances = new HashMap<>();
 
     @Builder.Default
     Map<UUID, RappInstance> rappInstances = new HashMap<>();
 
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START======================================================================
 /*
  * ============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.
  * ===============================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
  * ============LICENSE_END========================================================================
  */
 
  * ============LICENSE_END========================================================================
  */
 
-package com.oransc.rappmanager.models.cache;
+package com.oransc.rappmanager.models;
 
 import org.springframework.boot.test.context.TestConfiguration;
 import org.springframework.cache.CacheManager;
 
 import org.springframework.boot.test.context.TestConfiguration;
 import org.springframework.cache.CacheManager;
@@ -24,7 +24,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
 import org.springframework.context.annotation.Bean;
 
 @TestConfiguration
 import org.springframework.context.annotation.Bean;
 
 @TestConfiguration
-class BeanTestConfiguration {
+public class BeanTestConfiguration {
 
     @Bean
     public CacheManager cacheManager() {
 
     @Bean
     public CacheManager cacheManager() {
index d2f5a8d..a89f344 100755 (executable)
@@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
+import com.oransc.rappmanager.models.BeanTestConfiguration;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
index 2325789..9f1893b 100755 (executable)
@@ -24,7 +24,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -36,9 +38,10 @@ import com.oransc.rappmanager.models.rappinstance.RappDMEInstance;
 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.util.List;
+import java.io.IOException;
 import java.util.Set;
 import java.util.UUID;
 import java.util.Set;
 import java.util.UUID;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.junit.jupiter.api.Test;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.junit.jupiter.api.Test;
@@ -95,6 +98,14 @@ class RappCsarConfigurationHandlerTest {
         assertThat(fileByteArray.size()).isZero();
     }
 
         assertThat(fileByteArray.size()).isZero();
     }
 
+    @Test
+    void testInvalidZipStreamGetFromCsar() throws IOException {
+        ZipArchiveInputStream zipArchiveInputStream = mock(ZipArchiveInputStream.class);
+        doThrow(new IOException()).when(zipArchiveInputStream).getNextEntry();
+        ByteArrayOutputStream fileByteArray = rappCsarConfigurationHandler.getFileFromCsar(zipArchiveInputStream, null);
+        assertThat(fileByteArray.size()).isZero();
+    }
+
     @Test
     void testListResources() {
         UUID rappId = UUID.randomUUID();
     @Test
     void testListResources() {
         UUID rappId = UUID.randomUUID();
@@ -241,24 +252,37 @@ class RappCsarConfigurationHandlerTest {
     }
 
     @Test
     }
 
     @Test
-    void testListDeploymentItems() {
+    void testGetAsdMetadata() {
         Rapp rapp = Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build();
         Rapp rapp = Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build();
-        List<DeploymentItem> deploymentItems = rappCsarConfigurationHandler.getDeploymentItems(rapp);
-        assertEquals(2, deploymentItems.size());
+        AsdMetadata asdMetadata = rappCsarConfigurationHandler.getAsdMetadata(rapp);
+        assertEquals("123e4567-e89b-12d3-a456-426614174000", asdMetadata.getDescriptorId());
+        assertEquals("040eff2a-eb1a-4aff-bd46-37ce38092985", asdMetadata.getDescriptorInvariantId());
+        assertEquals(2, asdMetadata.getDeploymentItems().size());
     }
 
     @ParameterizedTest
     @ValueSource(strings = {invalidRappNoAsdFile, invalidRappEmptyAsdFile})
     }
 
     @ParameterizedTest
     @ValueSource(strings = {invalidRappNoAsdFile, invalidRappEmptyAsdFile})
-    void testListDeploymentItemsNoAsd(String packageName) {
+    void testGetAsdMetadataNoAsd(String packageName) {
         Rapp rapp = Rapp.builder().name("").packageName(packageName).packageLocation(validCsarFileLocation).build();
         Rapp rapp = Rapp.builder().name("").packageName(packageName).packageLocation(validCsarFileLocation).build();
-        assertThat(rappCsarConfigurationHandler.getDeploymentItems(rapp)).isEmpty();
+        assertThat(rappCsarConfigurationHandler.getAsdMetadata(rapp)).isNotNull();
     }
 
     @Test
     }
 
     @Test
-    void testListDeploymentItemsWithException() throws JsonProcessingException {
+    void testGetAsdMetadataException() throws JsonProcessingException {
         Rapp rapp = Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build();
         doThrow(new JsonSyntaxException("")).when(rappCsarConfigurationHandler).getAsdContentNode(any());
         Rapp rapp = Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build();
         doThrow(new JsonSyntaxException("")).when(rappCsarConfigurationHandler).getAsdContentNode(any());
-        assertThat(rappCsarConfigurationHandler.getDeploymentItems(rapp)).isEmpty();
+        assertNull(rappCsarConfigurationHandler.getAsdMetadata(rapp).getDescriptorId());
+        assertNull(rappCsarConfigurationHandler.getAsdMetadata(rapp).getDescriptorInvariantId());
+        assertThat(rappCsarConfigurationHandler.getAsdMetadata(rapp).getDeploymentItems()).isNull();
+    }
+
+    @Test
+    void testGetAsdMetadataNullAsdContent() throws JsonProcessingException {
+        Rapp rapp = Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build();
+        doReturn(null).when(rappCsarConfigurationHandler).getAsdContentNode(any());
+        assertNull(rappCsarConfigurationHandler.getAsdMetadata(rapp).getDescriptorId());
+        assertNull(rappCsarConfigurationHandler.getAsdMetadata(rapp).getDescriptorInvariantId());
+        assertThat(rappCsarConfigurationHandler.getAsdMetadata(rapp).getDeploymentItems()).isNull();
     }
 
     @Test
     }
 
     @Test
index 7348116..b0c2f43 100755 (executable)
@@ -83,33 +83,11 @@ class ArtifactDefinitionValidatorTest {
         assertTrue(exception.getMessage().startsWith("rApp package missing a file"));
     }
 
         assertTrue(exception.getMessage().startsWith("rApp package missing a file"));
     }
 
-    @Test
-    void testCsarNoAsdFailure() {
-        MultipartFile multipartFile = mock(MultipartFile.class);
-        RappValidationException exception = assertThrows(RappValidationException.class,
-                () -> artifactDefinitionValidator.validate(multipartFile, null));
-        assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
-        assertEquals("ASD definition in rApp package is invalid.", exception.getMessage());
-    }
 
 
-    @ParameterizedTest
-    @NullSource
-    @ValueSource(strings = {""})
-    void testCsarAsdLocationNullFailure(String asdLocation) throws IOException {
-        String rappCsarPath = validCsarFileLocation + File.separator + invalidRappAsdEmptyFile;
-        MultipartFile multipartFile =
-                new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
-                        new FileInputStream(rappCsarPath));
-        doReturn(asdLocation).when(rappValidationUtils).getAsdDefinitionLocation(any());
-        RappValidationException exception = assertThrows(RappValidationException.class,
-                () -> artifactDefinitionValidator.validate(multipartFile, null));
-        assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
-        assertEquals("ASD definition in rApp package is invalid.", exception.getMessage());
-    }
 
     @ParameterizedTest
     @NullSource
 
     @ParameterizedTest
     @NullSource
-    @ValueSource(strings = {"", "{asasdasd"})
+    @ValueSource(strings = {"{asasdasd"})
     void testCsarAsdContentInvalidFailure(String asdContent) throws IOException {
         String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
         MultipartFile multipartFile =
     void testCsarAsdContentInvalidFailure(String asdContent) throws IOException {
         String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
         MultipartFile multipartFile =
diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/AsdDescriptorValidatorTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/AsdDescriptorValidatorTest.java
new file mode 100755 (executable)
index 0000000..1d9079b
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * ============LICENSE_START======================================================================
+ * 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 com.oransc.rappmanager.models.csar.validator;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.doReturn;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.oransc.rappmanager.models.BeanTestConfiguration;
+import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.csar.AsdMetadata;
+import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
+import com.oransc.rappmanager.models.exception.RappValidationException;
+import com.oransc.rappmanager.models.rapp.Rapp;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.UUID;
+import org.apache.http.entity.ContentType;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.NullSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.SpyBean;
+import org.springframework.cache.CacheManager;
+import org.springframework.http.HttpStatus;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.web.multipart.MultipartFile;
+
+@SpringBootTest
+@ContextConfiguration(classes = {BeanTestConfiguration.class, AsdDescriptorValidator.class, RappValidationUtils.class,
+        ObjectMapper.class, RappCsarConfigurationHandler.class, RappCacheService.class, CacheManager.class})
+class AsdDescriptorValidatorTest {
+
+    @Autowired
+    AsdDescriptorValidator asdDescriptorValidator;
+    @SpyBean
+    RappValidationUtils rappValidationUtils;
+    @Autowired
+    RappCacheService rappCacheService;
+
+    String validCsarFileLocation = "src/test/resources/";
+    String validRappFile = "valid-rapp-package.csar";
+    String invalidRappAsdEmptyFile = "invalid-rapp-package-empty-asd-yaml.csar";
+
+    @Test
+    void testCsarContainsValidAsdFile() throws IOException {
+        String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
+        MultipartFile multipartFile =
+                new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+                        new FileInputStream(rappCsarPath));
+        assertDoesNotThrow(() -> asdDescriptorValidator.validate(multipartFile, null));
+    }
+
+    @Test
+    void testCsarContainsDuplicateDescriptorId() throws IOException {
+        String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
+        AsdMetadata asdMetadata = new AsdMetadata();
+        asdMetadata.setDescriptorId("123e4567-e89b-12d3-a456-426614174000");
+        asdMetadata.setDescriptorInvariantId(UUID.randomUUID().toString());
+        Rapp rapp = Rapp.builder().name("").asdMetadata(asdMetadata).build();
+        rappCacheService.putRapp(rapp);
+        MultipartFile multipartFile =
+                new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+                        new FileInputStream(rappCsarPath));
+        RappValidationException exception =
+                assertThrows(RappValidationException.class, () -> asdDescriptorValidator.validate(multipartFile, null));
+        assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+        assertEquals("ASD descriptor already exists.", exception.getMessage());
+        rappCacheService.deleteRapp(rapp);
+    }
+
+    @Test
+    void testCsarContainsDuplicateDescriptorInvariantId() throws IOException {
+        String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
+        AsdMetadata asdMetadata = new AsdMetadata();
+        asdMetadata.setDescriptorId("");
+        asdMetadata.setDescriptorInvariantId("040eff2a-eb1a-4aff-bd46-37ce38092985");
+        Rapp rapp = Rapp.builder().name("").asdMetadata(asdMetadata).build();
+        rappCacheService.putRapp(rapp);
+        MultipartFile multipartFile =
+                new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+                        new FileInputStream(rappCsarPath));
+        RappValidationException exception =
+                assertThrows(RappValidationException.class, () -> asdDescriptorValidator.validate(multipartFile, null));
+        assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+        assertEquals("ASD descriptor invariant already exists.", exception.getMessage());
+        rappCacheService.deleteRapp(rapp);
+    }
+
+    @Test
+    void testCsarContainsValidAsdFileFailure() throws IOException {
+        String rappCsarPath = validCsarFileLocation + File.separator + invalidRappAsdEmptyFile;
+        MultipartFile multipartFile =
+                new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+                        new FileInputStream(rappCsarPath));
+        RappValidationException exception =
+                assertThrows(RappValidationException.class, () -> asdDescriptorValidator.validate(multipartFile, null));
+        assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+        assertEquals("ASD definition in rApp package is invalid.", exception.getMessage());
+    }
+
+    @ParameterizedTest
+    @NullSource
+    @ValueSource(strings = {""})
+    void testCsarAsdLocationNullFailure(String asdLocation) throws IOException {
+        String rappCsarPath = validCsarFileLocation + File.separator + invalidRappAsdEmptyFile;
+        MultipartFile multipartFile =
+                new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+                        new FileInputStream(rappCsarPath));
+        doReturn(asdLocation).when(rappValidationUtils).getAsdDefinitionLocation(any());
+        RappValidationException exception =
+                assertThrows(RappValidationException.class, () -> asdDescriptorValidator.validate(multipartFile, null));
+        assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+        assertEquals("ASD definition in rApp package is invalid.", exception.getMessage());
+    }
+
+    @ParameterizedTest
+    @NullSource
+    @ValueSource(strings = {"", "{asasdasd"})
+    void testCsarAsdContentInvalidFailure(String asdContent) throws IOException {
+        String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
+        MultipartFile multipartFile =
+                new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+                        new FileInputStream(rappCsarPath));
+        if (asdContent != null) {
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            byteArrayOutputStream.write(asdContent.getBytes(), 0, asdContent.getBytes().length);
+            doCallRealMethod().doReturn(byteArrayOutputStream).when(rappValidationUtils)
+                    .getFileFromCsar(any(MultipartFile.class), any());
+        } else {
+            doCallRealMethod().doReturn(asdContent).when(rappValidationUtils)
+                    .getFileFromCsar(any(MultipartFile.class), any());
+        }
+        RappValidationException exception =
+                assertThrows(RappValidationException.class, () -> asdDescriptorValidator.validate(multipartFile, null));
+        assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+        assertEquals("ASD definition in rApp package is invalid.", exception.getMessage());
+    }
+}
index 9edfe34..2166419 100755 (executable)
@@ -24,6 +24,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.mock;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import static org.mockito.Mockito.mock;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.oransc.rappmanager.models.BeanTestConfiguration;
+import com.oransc.rappmanager.models.cache.RappCacheService;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappValidationException;
 import java.io.File;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappValidationException;
 import java.io.File;
@@ -43,9 +45,9 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.web.multipart.MultipartFile;
 
 @SpringBootTest
 import org.springframework.web.multipart.MultipartFile;
 
 @SpringBootTest
-@ContextConfiguration(classes = {RappValidationHandler.class, NamingValidator.class, FileExistenceValidator.class,
-        ArtifactDefinitionValidator.class, RappValidationUtils.class, RappCsarConfigurationHandler.class,
-        ObjectMapper.class})
+@ContextConfiguration(classes = {BeanTestConfiguration.class, RappValidationHandler.class, NamingValidator.class,
+        FileExistenceValidator.class, ArtifactDefinitionValidator.class, AsdDescriptorValidator.class,
+        RappValidationUtils.class, RappCsarConfigurationHandler.class, ObjectMapper.class, RappCacheService.class})
 class RappValidationHandlerTest {
 
     @Autowired
 class RappValidationHandlerTest {
 
     @Autowired
index 7f1d8de..da575dd 100755 (executable)
@@ -87,7 +87,7 @@ class RappValidationUtilsTest {
         RappValidationException exception = assertThrows(RappValidationException.class,
                 () -> rappValidationUtils.getFileFromCsar(multipartFile, null));
         assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
         RappValidationException exception = assertThrows(RappValidationException.class,
                 () -> rappValidationUtils.getFileFromCsar(multipartFile, null));
         assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
-        assertEquals(String.format("Unable to get file %s from the multipart CSAR file", null), exception.getMessage());
+        assertEquals(String.format("Unable to get file %s from the multipart CSAR file", (Object) null), exception.getMessage());
     }
 
     @Test
     }
 
     @Test
index c82fce6..39dd363 100755 (executable)
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar and b/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar differ
index 30a7f04..03e466f 100755 (executable)
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar and b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar differ
index e03ad3a..406a56d 100755 (executable)
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar and b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar differ
index c48da0f..d2d9e5e 100755 (executable)
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package.csar and b/rapp-manager-models/src/test/resources/invalid-rapp-package.csar differ
index a045a6a..1dddd4a 100755 (executable)
Binary files a/rapp-manager-models/src/test/resources/valid-rapp-package.csar and b/rapp-manager-models/src/test/resources/valid-rapp-package.csar differ
index e1c17c6..a269a48 100755 (executable)
Binary files a/rapp-manager-sme/src/test/resources/valid-rapp-package.csar and b/rapp-manager-sme/src/test/resources/valid-rapp-package.csar differ
index af7e64f..b53c6c7 100755 (executable)
@@ -12,7 +12,7 @@ topology_template:
       description: "rapp-all"\r
       properties:\r
         descriptor_id: 123e4567-e89b-12d3-a456-426614174000\r
       description: "rapp-all"\r
       properties:\r
         descriptor_id: 123e4567-e89b-12d3-a456-426614174000\r
-        descriptor_invariant_id: 123e4yyy-e89b-12d3-a456-426614174abc\r
+        descriptor_invariant_id: 040eff2a-eb1a-4aff-bd46-37ce38092985\r
         descriptor_version: 1.0\r
         schema_version: 2.0\r
         function_description: rApp description\r
         descriptor_version: 1.0\r
         schema_version: 2.0\r
         function_description: rApp description\r