Testing polish and generic reactive changes
- Remove use of statemachine assertj assertions to prepare move - Move statemachine assertj assertion to spring-statemachine-test - Polish some tests and user TestUtils from core tests - Remove most of a deprecation warning from core tests - Relates #744
This commit is contained in:
@@ -17,6 +17,9 @@ package org.springframework.statemachine.buildtests;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll;
|
||||
import static org.springframework.statemachine.TestUtils.doStartAndAssert;
|
||||
import static org.springframework.statemachine.TestUtils.resolveMachine;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -31,15 +34,14 @@ import org.springframework.statemachine.guard.Guard;
|
||||
public class Gh737Tests extends AbstractBuildTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void test() throws Exception {
|
||||
context.register(Config1.class);
|
||||
context.refresh();
|
||||
StateMachine<Status, Event> machine = context.getBean(StateMachine.class);
|
||||
machine.start();
|
||||
StateMachine<Status, Event> machine = resolveMachine(context);
|
||||
doStartAndAssert(machine);
|
||||
|
||||
assertThat(machine.getState().getIds(), containsInAnyOrder(Status.ROOT, Status.S0));
|
||||
machine.sendEvent(Event.NEW);
|
||||
doSendEventAndConsumeAll(machine, Event.NEW);
|
||||
|
||||
assertThat(machine.getState().getIds(), containsInAnyOrder(Status.ROOT, Status.S2, Status.S21I, Status.S22I,
|
||||
Status.S23_IN_PROGRESS, Status.S24E));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,10 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll;
|
||||
import static org.springframework.statemachine.TestUtils.doStartAndAssert;
|
||||
import static org.springframework.statemachine.TestUtils.resolveFactory;
|
||||
import static org.springframework.statemachine.TestUtils.resolvePersister;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -52,28 +56,27 @@ public class RedisPersistTests extends AbstractBuildTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testPersistRegions() throws Exception {
|
||||
context.register(RedisConfig.class, Config1.class);
|
||||
context.refresh();
|
||||
|
||||
StateMachineFactory<TestStates, TestEvents> stateMachineFactory = context.getBean(StateMachineFactory.class);
|
||||
StateMachinePersister<TestStates, TestEvents, String> persister = context.getBean(StateMachinePersister.class);
|
||||
|
||||
StateMachineFactory<TestStates, TestEvents> stateMachineFactory = resolveFactory(context);
|
||||
StateMachinePersister<TestStates, TestEvents, String> persister = resolvePersister(context);
|
||||
StateMachine<TestStates, TestEvents> stateMachine = stateMachineFactory.getStateMachine("testid");
|
||||
stateMachine.start();
|
||||
|
||||
doStartAndAssert(stateMachine);
|
||||
assertThat(stateMachine, notNullValue());
|
||||
assertThat(stateMachine.getId(), is("testid"));
|
||||
|
||||
stateMachine.sendEvent(TestEvents.E1);
|
||||
doSendEventAndConsumeAll(stateMachine, TestEvents.E1);
|
||||
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S20, TestStates.S30));
|
||||
persister.persist(stateMachine, "xxx1");
|
||||
|
||||
stateMachine.sendEvent(TestEvents.E2);
|
||||
doSendEventAndConsumeAll(stateMachine, TestEvents.E2);
|
||||
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S21, TestStates.S30));
|
||||
persister.persist(stateMachine, "xxx2");
|
||||
|
||||
stateMachine.sendEvent(TestEvents.E3);
|
||||
doSendEventAndConsumeAll(stateMachine, TestEvents.E3);
|
||||
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S4));
|
||||
persister.persist(stateMachine, "xxx3");
|
||||
|
||||
@@ -83,7 +86,7 @@ public class RedisPersistTests extends AbstractBuildTests {
|
||||
stateMachine = persister.restore(stateMachine, "xxx1");
|
||||
assertThat(stateMachine.getId(), is("testid"));
|
||||
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S20, TestStates.S30));
|
||||
stateMachine.sendEvent(TestEvents.E2);
|
||||
doSendEventAndConsumeAll(stateMachine, TestEvents.E2);
|
||||
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S21, TestStates.S30));
|
||||
|
||||
stateMachine = stateMachineFactory.getStateMachine();
|
||||
@@ -92,7 +95,7 @@ public class RedisPersistTests extends AbstractBuildTests {
|
||||
stateMachine = persister.restore(stateMachine, "xxx2");
|
||||
assertThat(stateMachine.getId(), is("testid"));
|
||||
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S21, TestStates.S30));
|
||||
stateMachine.sendEvent(TestEvents.E3);
|
||||
doSendEventAndConsumeAll(stateMachine, TestEvents.E4);
|
||||
assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S4));
|
||||
|
||||
stateMachine = stateMachineFactory.getStateMachine();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package org.springframework.statemachine.buildtests;
|
||||
|
||||
import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll;
|
||||
import static org.springframework.statemachine.TestUtils.doStartAndAssert;
|
||||
import static org.springframework.statemachine.TestUtils.doStopAndAssert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.statemachine.StateMachine;
|
||||
@@ -30,7 +34,6 @@ public class TimerSmokeTests {
|
||||
}
|
||||
|
||||
private StateMachine<String, String> buildMachine() throws Exception {
|
||||
|
||||
StateMachineBuilder.Builder<String, String> builder = StateMachineBuilder.builder();
|
||||
|
||||
builder.configureConfiguration()
|
||||
@@ -56,7 +59,6 @@ public class TimerSmokeTests {
|
||||
}
|
||||
|
||||
private StateMachine<String, String> buildMachine2() throws Exception {
|
||||
|
||||
StateMachineBuilder.Builder<String, String> builder = StateMachineBuilder.builder();
|
||||
|
||||
builder.configureConfiguration()
|
||||
@@ -91,25 +93,23 @@ public class TimerSmokeTests {
|
||||
StateMachine<String, String> stateMachine;
|
||||
for (int i = 0; i < 20; i++) {
|
||||
stateMachine = buildMachine();
|
||||
stateMachine.start();
|
||||
doStartAndAssert(stateMachine);
|
||||
while (!stateMachine.isComplete()) {
|
||||
stateMachine.sendEvent("repeate");
|
||||
doSendEventAndConsumeAll(stateMachine, "repeate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNPE2() throws Exception {
|
||||
|
||||
StateMachine<String, String> stateMachine;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
stateMachine = buildMachine2();
|
||||
stateMachine.start();
|
||||
doStartAndAssert(stateMachine);
|
||||
while(!stateMachine.isComplete()) {
|
||||
stateMachine.sendEvent("repeate");
|
||||
doSendEventAndConsumeAll(stateMachine, "repeate");
|
||||
}
|
||||
stateMachine.stop();
|
||||
doStopAndAssert(stateMachine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user