Merge "Add support to upload deployment helm artifacts to chartmuseum"
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / test / java / com / oransc / rappmanager / models / RappServiceEnablerTest.java
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END========================================================================
17  */
18
19 package com.oransc.rappmanager.models;
20
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
26 import com.oransc.rappmanager.models.rapp.Rapp;
27 import com.oransc.rappmanager.models.rapp.RappResources;
28 import com.oransc.rappmanager.models.rappinstance.RappACMInstance;
29 import com.oransc.rappmanager.models.rappinstance.RappDMEInstance;
30 import com.oransc.rappmanager.models.rappinstance.RappInstance;
31 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
32 import java.util.Set;
33 import org.junit.jupiter.api.Test;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.test.context.ContextConfiguration;
37
38 @SpringBootTest
39 @ContextConfiguration(classes = {ObjectMapper.class, RappCsarConfigurationHandler.class})
40 class RappServiceEnablerTest {
41
42     @Autowired
43     RappCsarConfigurationHandler rappCsarConfigurationHandler;
44     String validCsarFileLocation = "src/test/resources/";
45     private final String validRappFile = "valid-rapp-package.csar";
46
47     @Test
48     void testRappIsDmeAndSmeEnabled() {
49         RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
50                 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
51         Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
52                             .packageLocation(validCsarFileLocation).build();
53         assertTrue(rapp.isDMEEnabled());
54         assertTrue(rapp.isSMEEnabled());
55     }
56
57     @Test
58     void testRappIsNotDmeEnabled() {
59         RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
60                 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
61         Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
62                             .packageLocation(validCsarFileLocation).build();
63         rapp.getRappResources().setDme(null);
64         assertFalse(rapp.isDMEEnabled());
65     }
66
67     @Test
68     void testRappIsNotSmeEnabled() {
69         RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
70                 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
71         Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
72                             .packageLocation(validCsarFileLocation).build();
73         rapp.getRappResources().setSme(null);
74         assertFalse(rapp.isSMEEnabled());
75     }
76
77     @Test
78     void testRappIsNotDmeEnabledWithFolder() {
79         RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
80                 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
81         Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
82                             .packageLocation(validCsarFileLocation).build();
83         rapp.getRappResources().getDme().setConsumerInfoTypes(Set.of());
84         rapp.getRappResources().getDme().setProducerInfoTypes(Set.of());
85         rapp.getRappResources().getDme().setInfoConsumers(Set.of());
86         rapp.getRappResources().getDme().setInfoProducers(Set.of());
87         assertFalse(rapp.isDMEEnabled());
88     }
89
90     @Test
91     void testRappIsNotSmeEnabledWithFolder() {
92         RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
93                 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
94         Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
95                             .packageLocation(validCsarFileLocation).build();
96         rapp.getRappResources().getSme().setProviderFunctions(Set.of());
97         rapp.getRappResources().getSme().setServiceApis(Set.of());
98         rapp.getRappResources().getSme().setInvokers(Set.of());
99         assertFalse(rapp.isSMEEnabled());
100     }
101
102     @Test
103     void testRappInstanceIsDmeAndSmeEnabled() {
104         RappInstance rappInstance = new RappInstance();
105         rappInstance.setAcm(new RappACMInstance());
106         RappDMEInstance rappDMEInstance = new RappDMEInstance();
107         rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
108         rappDMEInstance.setInfoTypeConsumer("cons");
109         rappInstance.setDme(rappDMEInstance);
110         RappSMEInstance rappSMEInstance = new RappSMEInstance();
111         rappSMEInstance.setProviderFunction("func1");
112         rappInstance.setSme(rappSMEInstance);
113         assertTrue(rappInstance.isDMEEnabled());
114         assertTrue(rappInstance.isSMEEnabled());
115     }
116
117     @Test
118     void testRappInstanceIsNotDmeEnabled() {
119         RappInstance rappInstance = new RappInstance();
120         rappInstance.setAcm(new RappACMInstance());
121         RappSMEInstance rappSMEInstance = new RappSMEInstance();
122         rappSMEInstance.setProviderFunction("func1");
123         rappInstance.setSme(rappSMEInstance);
124         assertFalse(rappInstance.isDMEEnabled());
125     }
126
127     @Test
128     void testRappInstanceIsNotSmeEnabled() {
129         RappInstance rappInstance = new RappInstance();
130         rappInstance.setAcm(new RappACMInstance());
131         RappDMEInstance rappDMEInstance = new RappDMEInstance();
132         rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
133         rappDMEInstance.setInfoTypeConsumer("cons");
134         rappInstance.setDme(rappDMEInstance);
135         assertFalse(rappInstance.isSMEEnabled());
136     }
137
138     @Test
139     void testRappInstanceIsNotDmeEnabledWithoutContent() {
140         RappInstance rappInstance = new RappInstance();
141         rappInstance.setAcm(new RappACMInstance());
142         RappSMEInstance rappSMEInstance = new RappSMEInstance();
143         rappSMEInstance.setProviderFunction("func1");
144         rappInstance.setSme(rappSMEInstance);
145         RappDMEInstance rappDMEInstance = new RappDMEInstance();
146         rappInstance.setDme(rappDMEInstance);
147         assertFalse(rappInstance.isDMEEnabled());
148     }
149
150     @Test
151     void testRappInstanceIsNotSmeEnabledWithoutContent() {
152         RappInstance rappInstance = new RappInstance();
153         rappInstance.setAcm(new RappACMInstance());
154         RappDMEInstance rappDMEInstance = new RappDMEInstance();
155         rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
156         rappDMEInstance.setInfoTypeConsumer("cons");
157         rappInstance.setDme(rappDMEInstance);
158         RappSMEInstance rappSMEInstance = new RappSMEInstance();
159         rappInstance.setSme(rappSMEInstance);
160         assertFalse(rappInstance.isSMEEnabled());
161     }
162 }