State machine refactor (#1520)

* State machine refactor

* Add surefire plugin

* Refactor
This commit is contained in:
Grzegorz Piwowarek 2017-03-28 08:17:00 +02:00 committed by GitHub
parent 0c8aa7e46d
commit 85969c69d2
16 changed files with 65 additions and 49 deletions

View File

@ -9,7 +9,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>baeldung-spring-state-machine</artifactId> <artifactId>spring-state-machine</artifactId>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
@ -27,5 +27,32 @@
<version>4.11</version> <version>4.11</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<systemPropertyVariables>
<!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine.applicationReview; package com.baeldung.spring.statemachine.applicationreview;
public enum ApplicationReviewEvents { public enum ApplicationReviewEvents {
APPROVE, REJECT APPROVE, REJECT

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine.applicationReview; package com.baeldung.spring.statemachine.applicationreview;
public enum ApplicationReviewStates { public enum ApplicationReviewStates {
PEER_REVIEW, PRINCIPAL_REVIEW, APPROVED, REJECTED PEER_REVIEW, PRINCIPAL_REVIEW, APPROVED, REJECTED

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine.config; package com.baeldung.spring.statemachine.config;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine.config; package com.baeldung.spring.statemachine.config;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachine; import org.springframework.statemachine.config.EnableStateMachine;

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine.config; package com.baeldung.spring.statemachine.config;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -1,19 +1,13 @@
package com.baeldung.spring.stateMachine.config; package com.baeldung.spring.statemachine.config;
import com.baeldung.spring.stateMachine.applicationReview.ApplicationReviewEvents; import com.baeldung.spring.statemachine.applicationreview.ApplicationReviewEvents;
import com.baeldung.spring.stateMachine.applicationReview.ApplicationReviewStates; import com.baeldung.spring.statemachine.applicationreview.ApplicationReviewStates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.config.EnableStateMachine; import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter; import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer; import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import org.springframework.statemachine.guard.Guard;
import java.util.Arrays;
import java.util.HashSet;
@Configuration @Configuration
@EnableStateMachine @EnableStateMachine

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine.config; package com.baeldung.spring.statemachine.config;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine.config; package com.baeldung.spring.statemachine.config;
import org.springframework.statemachine.listener.StateMachineListenerAdapter; import org.springframework.statemachine.listener.StateMachineListenerAdapter;
import org.springframework.statemachine.state.State; import org.springframework.statemachine.state.State;

View File

@ -1,15 +1,14 @@
package com.baeldung.spring.stateMachine; package com.baeldung.spring.statemachine;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import com.baeldung.spring.statemachine.config.ForkJoinStateMachineConfiguration;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.StateMachine;
import com.baeldung.spring.stateMachine.config.ForkJoinStateMachineConfiguration; import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ForkJoinStateMachineTest { public class ForkJoinStateMachineTest {

View File

@ -1,14 +1,14 @@
package com.baeldung.spring.stateMachine; package com.baeldung.spring.statemachine;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import com.baeldung.spring.statemachine.config.HierarchicalStateMachineConfiguration;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.StateMachine;
import com.baeldung.spring.stateMachine.config.HierarchicalStateMachineConfiguration; import java.util.Arrays;
import static org.junit.Assert.assertEquals;
public class HierarchicalStateMachineTest { public class HierarchicalStateMachineTest {

View File

@ -1,17 +1,16 @@
package com.baeldung.spring.stateMachine; package com.baeldung.spring.statemachine;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.StateMachine;
import com.baeldung.spring.stateMachine.config.JunctionStateMachineConfiguration;
public class JunctionStateMachineTest { public class JunctionStateMachineTest {
@Test @Test
public void whenTransitioningToJunction_thenArriveAtSubJunctionNode() { public void whenTransitioningToJunction_thenArriveAtSubJunctionNode() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(JunctionStateMachineConfiguration.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(com.baeldung.spring.statemachine.config.JunctionStateMachineConfiguration.class);
StateMachine stateMachine = ctx.getBean(StateMachine.class); StateMachine stateMachine = ctx.getBean(StateMachine.class);
stateMachine.start(); stateMachine.start();

View File

@ -1,16 +1,15 @@
package com.baeldung.spring.stateMachine; package com.baeldung.spring.statemachine;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.baeldung.spring.statemachine.applicationreview.ApplicationReviewEvents;
import com.baeldung.spring.statemachine.applicationreview.ApplicationReviewStates;
import com.baeldung.spring.statemachine.config.SimpleEnumStateMachineConfiguration;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.StateMachine;
import com.baeldung.spring.stateMachine.applicationReview.ApplicationReviewEvents; import static org.junit.Assert.assertEquals;
import com.baeldung.spring.stateMachine.applicationReview.ApplicationReviewStates; import static org.junit.Assert.assertTrue;
import com.baeldung.spring.stateMachine.config.SimpleEnumStateMachineConfiguration;
public class StateEnumMachineTest { public class StateEnumMachineTest {

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.stateMachine; package com.baeldung.spring.statemachine;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -1,16 +1,15 @@
package com.baeldung.spring.stateMachine; package com.baeldung.spring.statemachine;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.baeldung.spring.statemachine.config.SimpleStateMachineConfiguration;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.StateMachine;
import com.baeldung.spring.stateMachine.config.SimpleStateMachineConfiguration; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class StateMachineTest { public class StateMachineIntegrationTest {
private AnnotationConfigApplicationContext ctx; private AnnotationConfigApplicationContext ctx;
private StateMachine stateMachine; private StateMachine stateMachine;
@ -34,7 +33,7 @@ public class StateMachineTest {
} }
@Test @Test
public void whenSimpleStringMachineActionState_thenActionExecuted() { public void whenSimpleStringMachineActionState_thenActionExecuted() throws InterruptedException {
stateMachine.sendEvent("E3"); stateMachine.sendEvent("E3");
assertEquals("S3", stateMachine.getState().getId()); assertEquals("S3", stateMachine.getState().getId());

View File

@ -45,7 +45,6 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration> <configuration>
<testFailureIgnore>true</testFailureIgnore> <testFailureIgnore>true</testFailureIgnore>
<excludes> <excludes>