Copyright added in missed files
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / test / java / com / oransc / rappmanager / models / statemachine / RappInstanceStateMachineTest.java
1 /*
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2023 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.statemachine;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
23 import static org.junit.jupiter.api.Assertions.assertNull;
24
25 import com.oransc.rappmanager.models.rapp.RappEvent;
26 import com.oransc.rappmanager.models.rappinstance.RappInstance;
27 import com.oransc.rappmanager.models.rappinstance.RappInstanceState;
28 import java.util.UUID;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.boot.test.context.SpringBootTest;
33 import org.springframework.test.annotation.DirtiesContext;
34 import org.springframework.test.context.junit.jupiter.SpringExtension;
35
36 @ExtendWith(SpringExtension.class)
37 @SpringBootTest(classes = {RappInstanceStateMachine.class, RappInstanceStateMachineConfig.class})
38 @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
39 class RappInstanceStateMachineTest {
40
41     @Autowired
42     RappInstanceStateMachine rappInstanceStateMachine;
43
44     @Test
45     void testOnboardRappInstance() {
46         UUID rappInstanceId = UUID.randomUUID();
47         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
48         assertNotNull(rappInstanceStateMachine.stateMachineMap.get(rappInstanceId));
49     }
50
51     @Test
52     void testSendRappInstanceEvent() {
53         UUID rappInstanceId = UUID.randomUUID();
54         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
55         assertEquals(RappInstanceState.UNDEPLOYED, rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
56         RappInstance rappInstance = new RappInstance();
57         rappInstance.setRappInstanceId(rappInstanceId);
58         rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DEPLOYING);
59         assertEquals(RappInstanceState.DEPLOYING, rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
60     }
61
62     @Test
63     void testGetRappInstanceState() {
64         UUID rappInstanceId = UUID.randomUUID();
65         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
66         assertEquals(RappInstanceState.UNDEPLOYED, rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
67     }
68
69     @Test
70     void testDeleteRappInstance() {
71         UUID rappInstanceId = UUID.randomUUID();
72         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
73         assertNotNull(rappInstanceStateMachine.stateMachineMap.get(rappInstanceId));
74         RappInstance rappInstance = new RappInstance();
75         rappInstance.setRappInstanceId(rappInstanceId);
76         rappInstanceStateMachine.deleteRappInstance(rappInstance);
77         assertNull(rappInstanceStateMachine.stateMachineMap.get(rappInstanceId));
78     }
79 }