Fix sonar code smells
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / test / java / com / oransc / rappmanager / models / statemachine / RappInstanceStateMachineTest.java
1 package com.oransc.rappmanager.models.statemachine;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertNotNull;
5 import static org.junit.jupiter.api.Assertions.assertNull;
6
7 import com.oransc.rappmanager.models.rapp.RappEvent;
8 import com.oransc.rappmanager.models.rappinstance.RappInstance;
9 import com.oransc.rappmanager.models.rappinstance.RappInstanceState;
10 import java.util.UUID;
11 import org.junit.jupiter.api.Test;
12 import org.junit.jupiter.api.extension.ExtendWith;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.boot.test.context.SpringBootTest;
15 import org.springframework.test.annotation.DirtiesContext;
16 import org.springframework.test.context.junit.jupiter.SpringExtension;
17
18 @ExtendWith(SpringExtension.class)
19 @SpringBootTest(classes = {RappInstanceStateMachine.class, RappInstanceStateMachineConfig.class})
20 @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
21 class RappInstanceStateMachineTest {
22
23     @Autowired
24     RappInstanceStateMachine rappInstanceStateMachine;
25
26     @Test
27     void testOnboardRappInstance() {
28         UUID rappInstanceId = UUID.randomUUID();
29         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
30         assertNotNull(rappInstanceStateMachine.stateMachineMap.get(rappInstanceId));
31     }
32
33     @Test
34     void testSendRappInstanceEvent() {
35         UUID rappInstanceId = UUID.randomUUID();
36         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
37         assertEquals(RappInstanceState.UNDEPLOYED, rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
38         RappInstance rappInstance = new RappInstance();
39         rappInstance.setRappInstanceId(rappInstanceId);
40         rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DEPLOYING);
41         assertEquals(RappInstanceState.DEPLOYING, rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
42     }
43
44     @Test
45     void testGetRappInstanceState() {
46         UUID rappInstanceId = UUID.randomUUID();
47         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
48         assertEquals(RappInstanceState.UNDEPLOYED, rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
49     }
50
51     @Test
52     void testDeleteRappInstance() {
53         UUID rappInstanceId = UUID.randomUUID();
54         rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
55         assertNotNull(rappInstanceStateMachine.stateMachineMap.get(rappInstanceId));
56         RappInstance rappInstance = new RappInstance();
57         rappInstance.setRappInstanceId(rappInstanceId);
58         rappInstanceStateMachine.deleteRappInstance(rappInstance);
59         assertNull(rappInstanceStateMachine.stateMachineMap.get(rappInstanceId));
60     }
61 }