org.springframework.statemachine.support.DefaultStateMachineContext Java Examples

The following examples show how to use org.springframework.statemachine.support.DefaultStateMachineContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateMachineTests.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoreFromInstallUsingInstallRequest() throws Exception {
	Mockito.when(releaseService.install(any(InstallRequest.class))).thenReturn(new Release());

	DefaultExtendedState extendedState = new DefaultExtendedState();
	extendedState.getVariables().put(SkipperEventHeaders.INSTALL_REQUEST, new InstallRequest());

	StateMachineContext<SkipperStates, SkipperEvents> stateMachineContext = new DefaultStateMachineContext<>(
			SkipperStates.INSTALL, SkipperEvents.INSTALL, null, extendedState);
	Mockito.when(stateMachineRuntimePersister.read(any())).thenReturn(stateMachineContext);

	StateMachineService<SkipperStates, SkipperEvents> stateMachineService = context.getBean(StateMachineService.class);
	StateMachine<SkipperStates, SkipperEvents> stateMachine = stateMachineService
			.acquireStateMachine("testRestoreFromInstallUsingInstallRequest", false);

	StateMachineTestPlan<SkipperStates, SkipperEvents> plan =
			StateMachineTestPlanBuilder.<SkipperStates, SkipperEvents>builder()
				.defaultAwaitTime(10)
				.stateMachine(stateMachine)
				.step()
					.expectStates(SkipperStates.INITIAL)
					.expectStateChanged(2)
					.and()
				.build();
	plan.test();

	Mockito.verify(upgradeCancelAction, never()).execute(any());
	Mockito.verify(errorAction, never()).execute(any());
}
 
Example #2
Source File: StateMachineTests.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoreFromUpgradeUsingUpgradeRequest() throws Exception {
	Manifest manifest = new Manifest();
	Release release = new Release();
	release.setManifest(manifest);
	Mockito.when(releaseReportService.createReport(any(), any(), any(boolean.class))).thenReturn(new ReleaseAnalysisReport(
			new ArrayList<>(), new ReleaseDifference(), release, release));
	Mockito.when(upgradeStrategy.checkStatus(any()))
			.thenReturn(true);
	Mockito.when(upgradeStrategyFactory.getUpgradeStrategy(any())).thenReturn(upgradeStrategy);

	DefaultExtendedState extendedState = new DefaultExtendedState();
	extendedState.getVariables().put(SkipperEventHeaders.UPGRADE_REQUEST, new UpgradeRequest());

	StateMachineContext<SkipperStates, SkipperEvents> stateMachineContext = new DefaultStateMachineContext<>(
			SkipperStates.UPGRADE, SkipperEvents.UPGRADE, null, extendedState);
	Mockito.when(stateMachineRuntimePersister.read(any())).thenReturn(stateMachineContext);

	StateMachineService<SkipperStates, SkipperEvents> stateMachineService = context.getBean(StateMachineService.class);
	StateMachine<SkipperStates, SkipperEvents> stateMachine = stateMachineService
			.acquireStateMachine("testRestoreFromUpgradeUsingUpgradeRequest", false);

	StateMachineTestPlan<SkipperStates, SkipperEvents> plan =
			StateMachineTestPlanBuilder.<SkipperStates, SkipperEvents>builder()
				.defaultAwaitTime(10)
				.stateMachine(stateMachine)
				.step()
					.expectStates(SkipperStates.INITIAL)
					.expectStateChanged(8)
					.and()
				.build();
	plan.test();
	Mockito.verify(upgradeCancelAction, never()).execute(any());
	Mockito.verify(errorAction, never()).execute(any());
}
 
Example #3
Source File: StateMachineTests.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoreFromInstallUsingInstallProperties() throws Exception {
	Mockito.when(releaseService.install(any(), any(InstallProperties.class))).thenReturn(new Release());

	DefaultExtendedState extendedState = new DefaultExtendedState();
	extendedState.getVariables().put(SkipperEventHeaders.INSTALL_PROPERTIES, new InstallProperties());

	StateMachineContext<SkipperStates, SkipperEvents> stateMachineContext = new DefaultStateMachineContext<>(
			SkipperStates.INSTALL, SkipperEvents.INSTALL, null, extendedState);
	Mockito.when(stateMachineRuntimePersister.read(any())).thenReturn(stateMachineContext);

	StateMachineService<SkipperStates, SkipperEvents> stateMachineService = context.getBean(StateMachineService.class);
	StateMachine<SkipperStates, SkipperEvents> stateMachine = stateMachineService
			.acquireStateMachine("testRestoreFromInstallUsingInstallProperties", false);

	StateMachineTestPlan<SkipperStates, SkipperEvents> plan =
			StateMachineTestPlanBuilder.<SkipperStates, SkipperEvents>builder()
				.defaultAwaitTime(10)
				.stateMachine(stateMachine)
				.step()
					.expectStates(SkipperStates.INITIAL)
					.expectStateChanged(2)
					.and()
				.build();
	plan.test();

	Mockito.verify(upgradeCancelAction, never()).execute(any());
	Mockito.verify(errorAction, never()).execute(any());
}
 
Example #4
Source File: StateMachineTests.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoreFromDeleteUsingDeleteProperties() throws Exception {
	Mockito.when(releaseService.delete(nullable(String.class), any(boolean.class))).thenReturn(new Release());
	DeleteProperties deleteProperties = new DeleteProperties();

	DefaultExtendedState extendedState = new DefaultExtendedState();
	extendedState.getVariables().put(SkipperEventHeaders.RELEASE_DELETE_PROPERTIES, deleteProperties);

	StateMachineContext<SkipperStates, SkipperEvents> stateMachineContext = new DefaultStateMachineContext<>(
			SkipperStates.DELETE, SkipperEvents.DELETE, null, extendedState);
	Mockito.when(stateMachineRuntimePersister.read(any())).thenReturn(stateMachineContext);

	StateMachineService<SkipperStates, SkipperEvents> stateMachineService = context.getBean(StateMachineService.class);
	StateMachine<SkipperStates, SkipperEvents> stateMachine = stateMachineService
			.acquireStateMachine("testRestoreFromDeleteUsingDeleteProperties", false);

	StateMachineTestPlan<SkipperStates, SkipperEvents> plan =
			StateMachineTestPlanBuilder.<SkipperStates, SkipperEvents>builder()
				.defaultAwaitTime(10)
				.stateMachine(stateMachine)
				.step()
					.expectStates(SkipperStates.INITIAL)
					.expectStateChanged(2)
					.and()
				.build();
	plan.test();

	Mockito.verify(upgradeCancelAction, never()).execute(any());
	Mockito.verify(errorAction, never()).execute(any());
}
 
Example #5
Source File: FlowAdapter.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(String stateRepresentation, Map<Object, Object> variables) {
    S state  = stateConverter.convert(stateRepresentation);
    List<? extends StateMachineAccess<S, E>> withAllRegions = flowMachine.getStateMachineAccessor().withAllRegions();
    for (StateMachineAccess<S, E> access : withAllRegions) {
        access.resetStateMachine(new DefaultStateMachineContext<>(state, null, null, null));
    }
    if (variables != null) {
        flowMachine.getExtendedState().getVariables().putAll(variables);
    }
    flowMachine.start();
}
 
Example #6
Source File: BizStateMachinePersist.java    From tools-journey with Apache License 2.0 4 votes vote down vote up
@Override
public StateMachineContext<TurnstileStates, TurnstileEvents> read(Integer integer) throws Exception {
    return cache.containsKey(integer) ?
            new DefaultStateMachineContext<>(cache.get(integer), null, null, null, null, "turnstileStateMachine") :
            new DefaultStateMachineContext<>(TurnstileStates.Locked, null, null, null, null, "turnstileStateMachine");
}