org.springframework.statemachine.StateMachineContext Java Examples

The following examples show how to use org.springframework.statemachine.StateMachineContext. 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: EnityWithSateMachine.java    From spring-statemachine-learning with Apache License 2.0 4 votes vote down vote up
@Override
public StateMachineContext getStateMachineContext() {
    return context;
}
 
Example #6
Source File: EnityWithSateMachine.java    From spring-statemachine-learning with Apache License 2.0 4 votes vote down vote up
@Override
public void setStateMachineContext(StateMachineContext context) {
    this.context = context;
}
 
Example #7
Source File: InEntityStateMachinePersist.java    From spring-statemachine-learning with Apache License 2.0 4 votes vote down vote up
@Override
public void write(StateMachineContext<S, E> context, StateMachineContextEntity<S, E> contextObj) throws Exception {
    contextObj.setStateMachineContext(context);
}
 
Example #8
Source File: InEntityStateMachinePersist.java    From spring-statemachine-learning with Apache License 2.0 4 votes vote down vote up
@Override
public StateMachineContext<S, E> read(StateMachineContextEntity<S, E> contextObj) throws Exception {
    return contextObj.getStateMachineContext();
}
 
Example #9
Source File: BizStateMachinePersist.java    From tools-journey with Apache License 2.0 4 votes vote down vote up
@Override
public void write(StateMachineContext<TurnstileStates, TurnstileEvents> stateMachineContext, Integer integer) throws Exception {
    cache.put(integer, stateMachineContext.getState());
}
 
Example #10
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");
}
 
Example #11
Source File: StateMachineContextEntity.java    From spring-statemachine-learning with Apache License 2.0 votes vote down vote up
StateMachineContext<S, E> getStateMachineContext(); 
Example #12
Source File: StateMachineContextEntity.java    From spring-statemachine-learning with Apache License 2.0 votes vote down vote up
void setStateMachineContext(StateMachineContext<S, E> context);