1 package com.oransc.rappmanager.models.statemachine;
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;
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;
18 @ExtendWith(SpringExtension.class)
19 @SpringBootTest(classes = {RappInstanceStateMachine.class, RappInstanceStateMachineConfig.class})
20 @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
21 class RappInstanceStateMachineTest {
24 RappInstanceStateMachine rappInstanceStateMachine;
27 void testOnboardRappInstance() {
28 UUID rappInstanceId = UUID.randomUUID();
29 rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
30 assertNotNull(rappInstanceStateMachine.stateMachineMap.get(rappInstanceId));
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));
45 void testGetRappInstanceState() {
46 UUID rappInstanceId = UUID.randomUUID();
47 rappInstanceStateMachine.onboardRappInstance(rappInstanceId);
48 assertEquals(RappInstanceState.UNDEPLOYED, rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
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));