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
9 * http://www.apache.org/licenses/LICENSE-2.0
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========================================================================
19 package com.oransc.rappmanager.models;
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
24 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
25 import com.oransc.rappmanager.models.rapp.Rapp;
26 import com.oransc.rappmanager.models.rapp.RappResources;
27 import com.oransc.rappmanager.models.rappinstance.RappACMInstance;
28 import com.oransc.rappmanager.models.rappinstance.RappDMEInstance;
29 import com.oransc.rappmanager.models.rappinstance.RappInstance;
30 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
32 import org.junit.jupiter.api.Test;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.boot.test.context.SpringBootTest;
35 import org.springframework.test.context.ContextConfiguration;
38 @ContextConfiguration(classes = RappCsarConfigurationHandler.class)
39 class RappServiceEnablerTest {
42 RappCsarConfigurationHandler rappCsarConfigurationHandler;
43 String validCsarFileLocation = "src/test/resources/";
44 private final String validRappFile = "valid-rapp-package.csar";
47 void testRappIsDmeAndSmeEnabled() {
48 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
49 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
50 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
51 .packageLocation(validCsarFileLocation).build();
52 assertTrue(rapp.isDMEEnabled());
53 assertTrue(rapp.isSMEEnabled());
57 void testRappIsNotDmeEnabled() {
58 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
59 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
60 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
61 .packageLocation(validCsarFileLocation).build();
62 rapp.getRappResources().setDme(null);
63 assertFalse(rapp.isDMEEnabled());
67 void testRappIsNotSmeEnabled() {
68 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
69 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
70 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
71 .packageLocation(validCsarFileLocation).build();
72 rapp.getRappResources().setSme(null);
73 assertFalse(rapp.isSMEEnabled());
77 void testRappIsNotDmeEnabledWithFolder() {
78 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
79 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
80 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
81 .packageLocation(validCsarFileLocation).build();
82 rapp.getRappResources().getDme().setConsumerInfoTypes(Set.of());
83 rapp.getRappResources().getDme().setProducerInfoTypes(Set.of());
84 rapp.getRappResources().getDme().setInfoConsumers(Set.of());
85 rapp.getRappResources().getDme().setInfoProducers(Set.of());
86 assertFalse(rapp.isDMEEnabled());
90 void testRappIsNotSmeEnabledWithFolder() {
91 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
92 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
93 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
94 .packageLocation(validCsarFileLocation).build();
95 rapp.getRappResources().getSme().setProviderFunctions(Set.of());
96 rapp.getRappResources().getSme().setServiceApis(Set.of());
97 rapp.getRappResources().getSme().setInvokers(Set.of());
98 assertFalse(rapp.isSMEEnabled());
102 void testRappInstanceIsDmeAndSmeEnabled() {
103 RappInstance rappInstance = new RappInstance();
104 rappInstance.setAcm(new RappACMInstance());
105 RappDMEInstance rappDMEInstance = new RappDMEInstance();
106 rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
107 rappDMEInstance.setInfoTypeConsumer("cons");
108 rappInstance.setDme(rappDMEInstance);
109 RappSMEInstance rappSMEInstance = new RappSMEInstance();
110 rappSMEInstance.setProviderFunction("func1");
111 rappInstance.setSme(rappSMEInstance);
112 assertTrue(rappInstance.isDMEEnabled());
113 assertTrue(rappInstance.isSMEEnabled());
117 void testRappInstanceIsNotDmeEnabled() {
118 RappInstance rappInstance = new RappInstance();
119 rappInstance.setAcm(new RappACMInstance());
120 RappSMEInstance rappSMEInstance = new RappSMEInstance();
121 rappSMEInstance.setProviderFunction("func1");
122 rappInstance.setSme(rappSMEInstance);
123 assertFalse(rappInstance.isDMEEnabled());
127 void testRappInstanceIsNotSmeEnabled() {
128 RappInstance rappInstance = new RappInstance();
129 rappInstance.setAcm(new RappACMInstance());
130 RappDMEInstance rappDMEInstance = new RappDMEInstance();
131 rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
132 rappDMEInstance.setInfoTypeConsumer("cons");
133 rappInstance.setDme(rappDMEInstance);
134 assertFalse(rappInstance.isSMEEnabled());
138 void testRappInstanceIsNotDmeEnabledWithoutContent() {
139 RappInstance rappInstance = new RappInstance();
140 rappInstance.setAcm(new RappACMInstance());
141 RappSMEInstance rappSMEInstance = new RappSMEInstance();
142 rappSMEInstance.setProviderFunction("func1");
143 rappInstance.setSme(rappSMEInstance);
144 RappDMEInstance rappDMEInstance = new RappDMEInstance();
145 rappInstance.setDme(rappDMEInstance);
146 assertFalse(rappInstance.isDMEEnabled());
150 void testRappInstanceIsNotSmeEnabledWithoutContent() {
151 RappInstance rappInstance = new RappInstance();
152 rappInstance.setAcm(new RappACMInstance());
153 RappDMEInstance rappDMEInstance = new RappDMEInstance();
154 rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
155 rappDMEInstance.setInfoTypeConsumer("cons");
156 rappInstance.setDme(rappDMEInstance);
157 RappSMEInstance rappSMEInstance = new RappSMEInstance();
158 rappInstance.setSme(rappSMEInstance);
159 assertFalse(rappInstance.isSMEEnabled());