X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=rapp-manager-models%2Fsrc%2Ftest%2Fjava%2Fcom%2Foransc%2Frappmanager%2Fmodels%2Fstatemachine%2FRappInstanceStateMachineConfigTest.java;h=1c7b97e50ea562c0a3ba6cce865e00dec1cf21f4;hb=HEAD;hp=4657c763b078aba54f0609328eccc9667a757691;hpb=40a82302ff06348e446a2de3c4a552b1ee9bc61b;p=nonrtric%2Fplt%2Frappmanager.git diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfigTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfigTest.java deleted file mode 100755 index 4657c76..0000000 --- a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfigTest.java +++ /dev/null @@ -1,237 +0,0 @@ -/*- - * ============LICENSE_START====================================================================== - * Copyright (C) 2023 Nordix Foundation. All rights reserved. - * =============================================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END======================================================================== - */ - -package com.oransc.rappmanager.models.statemachine; - -import com.oransc.rappmanager.models.rapp.RappEvent; -import com.oransc.rappmanager.models.rappinstance.RappInstanceState; -import java.util.UUID; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.statemachine.StateMachine; -import org.springframework.statemachine.config.StateMachineFactory; -import org.springframework.statemachine.test.StateMachineTestPlan; -import org.springframework.statemachine.test.StateMachineTestPlanBuilder; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = {RappInstanceStateMachineConfig.class}) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class RappInstanceStateMachineConfigTest { - - @Autowired - StateMachineFactory stateMachineFactory; - - StateMachine stateMachine; - - @BeforeEach - void getStateMachine() { - stateMachine = stateMachineFactory.getStateMachine(UUID.randomUUID()); - stateMachine.startReactively().subscribe(); - } - - @AfterEach - void stopStateMachine() { - stateMachine.stopReactively().subscribe(); - } - - @Test - void testOnboardedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().build(); - plan.test(); - } - - @Test - void testDeployingState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().build(); - plan.test(); - } - - @ParameterizedTest - @EnumSource(value = RappEvent.class, names = {"ACMDEPLOYED", "SMEDEPLOYED", "DMEDEPLOYED" }) - void testIndividualDeployedState(RappEvent rappEvent) throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(rappEvent).expectState(RappInstanceState.DEPLOYING).and().build(); - plan.test(); - } - - @Test - void testDeployedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) - .and().build(); - plan.test(); - } - - @Test - void testAcmDeployFailedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.ACMDEPLOYFAILED).expectState(RappInstanceState.UNDEPLOYED) - .expectStateChanged(1).and().build(); - plan.test(); - } - - @Test - void testSmeDeployFailedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYFAILED).expectState(RappInstanceState.UNDEPLOYED) - .expectStateChanged(1).and().build(); - plan.test(); - } - - @Test - void testDmeDeployFailedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYFAILED).expectState(RappInstanceState.UNDEPLOYED) - .expectStateChanged(1).and().build(); - plan.test(); - } - - @Test - void testUndeployingState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) - .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) - .expectStateChanged(1).and().build(); - plan.test(); - } - - @ParameterizedTest - @EnumSource(value = RappEvent.class, names = {"ACMUNDEPLOYED", "SMEUNDEPLOYED", "DMEUNDEPLOYED" }) - void testIndividualUndeployedState(RappEvent rappEvent) throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) - .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) - .expectStateChanged(1).and().step().sendEvent(rappEvent) - .expectState(RappInstanceState.UNDEPLOYING).and().build(); - plan.test(); - } - - @Test - void testUndeployedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) - .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) - .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.SMEUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.DMEUNDEPLOYED) - .expectStateChanged(1).and().build(); - plan.test(); - } - - @Test - void testUndeployAcmFailedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) - .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) - .expectStateChanged(1).and().step().sendEvent(RappEvent.SMEUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.DMEUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.ACMUNDEPLOYFAILED) - .expectState(RappInstanceState.DEPLOYED).expectStateChanged(1).and().build(); - plan.test(); - } - - @Test - void testUndeploySmeFailedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) - .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) - .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.DMEUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.SMEUNDEPLOYFAILED) - .expectState(RappInstanceState.DEPLOYED).expectStateChanged(1).and().build(); - plan.test(); - } - - @Test - void testUndeployDmeFailedState() throws Exception { - StateMachineTestPlan plan = - StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() - .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) - .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() - .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() - .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) - .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) - .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.SMEUNDEPLOYED) - .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.DMEUNDEPLOYFAILED) - .expectState(RappInstanceState.DEPLOYED).expectStateChanged(1).and().build(); - plan.test(); - } -}