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.configuration.RappsEnvironmentConfiguration;
26 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
27 import com.oransc.rappmanager.models.rapp.Rapp;
28 import com.oransc.rappmanager.models.rapp.RappResources;
29 import com.oransc.rappmanager.models.rappinstance.RappACMInstance;
30 import com.oransc.rappmanager.models.rappinstance.RappDMEInstance;
31 import com.oransc.rappmanager.models.rappinstance.RappInstance;
32 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
34 import org.junit.jupiter.api.Test;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.test.context.ContextConfiguration;
40 @ContextConfiguration(
41 classes = {ObjectMapper.class, RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
42 class RappServiceEnablerTest {
45 RappCsarConfigurationHandler rappCsarConfigurationHandler;
46 String validCsarFileLocation = "src/test/resources/";
47 private final String validRappFile = "valid-rapp-package.csar";
50 void testRappIsDmeAndSmeEnabled() {
51 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
52 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
53 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
54 .packageLocation(validCsarFileLocation).build();
55 assertTrue(rapp.isDMEEnabled());
56 assertTrue(rapp.isSMEEnabled());
60 void testRappIsNotDmeEnabled() {
61 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
62 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
63 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
64 .packageLocation(validCsarFileLocation).build();
65 rapp.getRappResources().setDme(null);
66 assertFalse(rapp.isDMEEnabled());
70 void testRappIsNotSmeEnabled() {
71 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
72 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
73 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
74 .packageLocation(validCsarFileLocation).build();
75 rapp.getRappResources().setSme(null);
76 assertFalse(rapp.isSMEEnabled());
80 void testRappIsNotDmeEnabledWithFolder() {
81 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
82 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
83 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
84 .packageLocation(validCsarFileLocation).build();
85 rapp.getRappResources().getDme().setConsumerInfoTypes(Set.of());
86 rapp.getRappResources().getDme().setProducerInfoTypes(Set.of());
87 rapp.getRappResources().getDme().setInfoConsumers(Set.of());
88 rapp.getRappResources().getDme().setInfoProducers(Set.of());
89 assertFalse(rapp.isDMEEnabled());
93 void testRappIsNotSmeEnabledWithFolder() {
94 RappResources rappResources = rappCsarConfigurationHandler.getRappResource(
95 Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build());
96 Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile)
97 .packageLocation(validCsarFileLocation).build();
98 rapp.getRappResources().getSme().setProviderFunctions(Set.of());
99 rapp.getRappResources().getSme().setServiceApis(Set.of());
100 rapp.getRappResources().getSme().setInvokers(Set.of());
101 assertFalse(rapp.isSMEEnabled());
105 void testRappInstanceIsDmeAndSmeEnabled() {
106 RappInstance rappInstance = new RappInstance();
107 rappInstance.setAcm(new RappACMInstance());
108 RappDMEInstance rappDMEInstance = new RappDMEInstance();
109 rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
110 rappDMEInstance.setInfoTypeConsumer("cons");
111 rappInstance.setDme(rappDMEInstance);
112 RappSMEInstance rappSMEInstance = new RappSMEInstance();
113 rappSMEInstance.setProviderFunction("func1");
114 rappInstance.setSme(rappSMEInstance);
115 assertTrue(rappInstance.isDMEEnabled());
116 assertTrue(rappInstance.isSMEEnabled());
120 void testRappInstanceIsNotDmeEnabled() {
121 RappInstance rappInstance = new RappInstance();
122 rappInstance.setAcm(new RappACMInstance());
123 RappSMEInstance rappSMEInstance = new RappSMEInstance();
124 rappSMEInstance.setProviderFunction("func1");
125 rappInstance.setSme(rappSMEInstance);
126 assertFalse(rappInstance.isDMEEnabled());
130 void testRappInstanceIsNotSmeEnabled() {
131 RappInstance rappInstance = new RappInstance();
132 rappInstance.setAcm(new RappACMInstance());
133 RappDMEInstance rappDMEInstance = new RappDMEInstance();
134 rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
135 rappDMEInstance.setInfoTypeConsumer("cons");
136 rappInstance.setDme(rappDMEInstance);
137 assertFalse(rappInstance.isSMEEnabled());
141 void testRappInstanceIsNotDmeEnabledWithoutContent() {
142 RappInstance rappInstance = new RappInstance();
143 rappInstance.setAcm(new RappACMInstance());
144 RappSMEInstance rappSMEInstance = new RappSMEInstance();
145 rappSMEInstance.setProviderFunction("func1");
146 rappInstance.setSme(rappSMEInstance);
147 RappDMEInstance rappDMEInstance = new RappDMEInstance();
148 rappInstance.setDme(rappDMEInstance);
149 assertFalse(rappInstance.isDMEEnabled());
153 void testRappInstanceIsNotSmeEnabledWithoutContent() {
154 RappInstance rappInstance = new RappInstance();
155 rappInstance.setAcm(new RappACMInstance());
156 RappDMEInstance rappDMEInstance = new RappDMEInstance();
157 rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2"));
158 rappDMEInstance.setInfoTypeConsumer("cons");
159 rappInstance.setDme(rappDMEInstance);
160 RappSMEInstance rappSMEInstance = new RappSMEInstance();
161 rappInstance.setSme(rappSMEInstance);
162 assertFalse(rappInstance.isSMEEnabled());