2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2023 Nordix Foundation. 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.sme.service;
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23 import static org.mockito.Mockito.doNothing;
24 import static org.mockito.Mockito.times;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
28 import com.oransc.rappmanager.sme.provider.data.APIProviderEnrolmentDetails;
29 import org.junit.jupiter.api.Test;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.boot.test.context.SpringBootTest;
32 import org.springframework.boot.test.mock.mockito.MockBean;
33 import org.springframework.boot.test.mock.mockito.SpyBean;
35 @SpringBootTest(classes = SmeLifecycleManager.class)
36 class SmeLifecycleManagerTest {
40 SmeDeployer smeDeployer;
44 SmeLifecycleManager smeLifecycleManager;
47 void testStartWithSuccess() {
48 when(smeDeployer.createAMF()).thenReturn(new APIProviderEnrolmentDetails());
49 smeLifecycleManager.start();
50 assertTrue(smeLifecycleManager.isRunning());
54 void testStartWithFailure() {
55 when(smeDeployer.createAMF()).thenReturn(null);
56 smeLifecycleManager.start();
57 assertFalse(smeLifecycleManager.isRunning());
61 void testStopWithSuccess() {
62 doNothing().when(smeDeployer).deleteAMF();
63 when(smeDeployer.createAMF()).thenReturn(new APIProviderEnrolmentDetails());
64 smeLifecycleManager.start();
65 assertTrue(smeLifecycleManager.isRunning());
66 smeLifecycleManager.stop();
67 verify(smeDeployer, times(1)).deleteAMF();
68 assertFalse(smeLifecycleManager.isRunning());
72 void testStopWithoutStart() {
73 smeLifecycleManager.stop();
74 verify(smeDeployer, times(0)).deleteAMF();
75 assertFalse(smeLifecycleManager.isRunning());