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.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;
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;
39 @ContextConfiguration(classes = {ObjectMapper.class, RappCsarConfigurationHandler.class})
40 class RappServiceEnablerTest {
43 RappCsarConfigurationHandler rappCsarConfigurationHandler;
44 String validCsarFileLocation = "src/test/resources/";
45 private final String validRappFile = "valid-rapp-package.csar";
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());