From 5b04d39e4142a0c8118e9d9ee3f03e8c4a01a907 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Fri, 10 May 2019 17:38:02 +0100 Subject: [PATCH] Reactive test changes for data - Relates #744 --- build.gradle | 1 + spring-statemachine-data/build.gradle | 3 +++ .../data/jpa/JpaRepositoryTests.java | 25 ++++++++++--------- .../data/mongodb/MongoDbRepositoryTests.java | 23 +++++++++-------- .../data/redis/RedisRepositoryTests.java | 23 +++++++++-------- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index 32ca1836..122054d9 100644 --- a/build.gradle +++ b/build.gradle @@ -301,6 +301,7 @@ project('spring-statemachine-data-common') { compile "com.fasterxml.jackson.core:jackson-core" compile "com.fasterxml.jackson.core:jackson-databind" testCompile project(":spring-statemachine-test") + testCompile project(path:":spring-statemachine-core", configuration:"testArtifacts") testCompile "org.springframework.boot:spring-boot-starter-test" testRuntime "org.springframework.boot:spring-boot-starter-web" } diff --git a/spring-statemachine-data/build.gradle b/spring-statemachine-data/build.gradle index e1ce251f..54564e6c 100644 --- a/spring-statemachine-data/build.gradle +++ b/spring-statemachine-data/build.gradle @@ -7,6 +7,7 @@ project('spring-statemachine-data-jpa') { compile "org.springframework:spring-orm" testCompile project(":spring-statemachine-test") testCompile project(path:":spring-statemachine-data-common", configuration:"testArtifacts") + testCompile project(path:":spring-statemachine-core", configuration:"testArtifacts") optional "org.eclipse.persistence:javax.persistence" testCompile "org.hsqldb:hsqldb" testCompile "org.springframework.boot:spring-boot-starter-test" @@ -23,6 +24,7 @@ project('spring-statemachine-data-redis') { testCompile project(":spring-statemachine-test") optional "org.eclipse.persistence:javax.persistence" testCompile project(path:":spring-statemachine-data-common", configuration:"testArtifacts") + testCompile project(path:":spring-statemachine-core", configuration:"testArtifacts") testCompile "org.springframework.boot:spring-boot-starter-test" testRuntime "org.apache.commons:commons-pool2" testRuntime "redis.clients:jedis" @@ -39,6 +41,7 @@ project('spring-statemachine-data-mongodb') { testCompile project(":spring-statemachine-test") optional "org.eclipse.persistence:javax.persistence" testCompile project(path:":spring-statemachine-data-common", configuration:"testArtifacts") + testCompile project(path:":spring-statemachine-core", configuration:"testArtifacts") testCompile "org.springframework.boot:spring-boot-starter-test" testRuntime "org.springframework.boot:spring-boot-starter-data-mongodb" testRuntime "org.springframework.boot:spring-boot-starter-web" diff --git a/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java b/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java index ed7ac39b..48fda7ce 100644 --- a/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java +++ b/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java @@ -18,6 +18,9 @@ package org.springframework.statemachine.data.jpa; import static org.hamcrest.CoreMatchers.is; 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 java.util.Arrays; import java.util.HashSet; @@ -288,32 +291,30 @@ public class JpaRepositoryTests extends AbstractRepositoryTests { } @Test - @SuppressWarnings("unchecked") public void testStateMachinePersistWithStrings() { context.register(TestConfig.class, ConfigWithStrings.class); context.refresh(); - StateMachine stateMachine = context.getBean(StateMachine.class); - stateMachine.start(); + StateMachine stateMachine = resolveMachine(context); + doStartAndAssert(stateMachine); assertThat(stateMachine.getState().getId(), is("S1")); - stateMachine.sendEvent("E1"); + doSendEventAndConsumeAll(stateMachine, "E1"); assertThat(stateMachine.getState().getId(), is("S2")); - stateMachine.sendEvent("E2"); + doSendEventAndConsumeAll(stateMachine, "E2"); assertThat(stateMachine.getState().getId(), is("S1")); } @Test - @SuppressWarnings("unchecked") public void testStateMachinePersistWithEnums() { context.register(TestConfig.class, ConfigWithEnums.class); context.refresh(); - StateMachine stateMachine = context.getBean(StateMachine.class); - stateMachine.start(); + StateMachine stateMachine = resolveMachine(context); + doStartAndAssert(stateMachine); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S1)); - stateMachine.sendEvent(PersistTestEvents.E1); + doSendEventAndConsumeAll(stateMachine, PersistTestEvents.E1); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S2)); - stateMachine.sendEvent(PersistTestEvents.E2); + doSendEventAndConsumeAll(stateMachine, PersistTestEvents.E2); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S1)); } @@ -325,9 +326,9 @@ public class JpaRepositoryTests extends AbstractRepositoryTests { JpaStateMachineRepository stateMachineRepository = context.getBean(JpaStateMachineRepository.class); StateMachine stateMachine = context.getBean(StateMachine.class); - stateMachine.start(); + doStartAndAssert(stateMachine); assertThat(stateMachine.getState().getIds(), containsInAnyOrder("S10", "S20")); - stateMachine.sendEvent("E1"); + doSendEventAndConsumeAll(stateMachine, "E1"); assertThat(stateMachine.getState().getIds(), containsInAnyOrder("S11", "S21")); assertThat(stateMachineRepository.count(), is(3l)); diff --git a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java index 88384e57..d488f6a9 100644 --- a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java +++ b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-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. @@ -18,6 +18,9 @@ package org.springframework.statemachine.data.mongodb; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.notNullValue; 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 java.util.ArrayList; import java.util.List; @@ -121,32 +124,30 @@ public class MongoDbRepositoryTests extends AbstractRepositoryTests { } @Test - @SuppressWarnings("unchecked") public void testStateMachinePersistWithStrings() { context.register(TestConfig.class, ConfigWithStrings.class); context.refresh(); - StateMachine stateMachine = context.getBean(StateMachine.class); - stateMachine.start(); + StateMachine stateMachine = resolveMachine(context); + doStartAndAssert(stateMachine); assertThat(stateMachine.getState().getId(), is("S1")); - stateMachine.sendEvent("E1"); + doSendEventAndConsumeAll(stateMachine, "E1"); assertThat(stateMachine.getState().getId(), is("S2")); - stateMachine.sendEvent("E2"); + doSendEventAndConsumeAll(stateMachine, "E2"); assertThat(stateMachine.getState().getId(), is("S1")); } @Test - @SuppressWarnings("unchecked") public void testStateMachinePersistWithEnums() { context.register(TestConfig.class, ConfigWithEnums.class); context.refresh(); - StateMachine stateMachine = context.getBean(StateMachine.class); - stateMachine.start(); + StateMachine stateMachine = resolveMachine(context); + doStartAndAssert(stateMachine); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S1)); - stateMachine.sendEvent(PersistTestEvents.E1); + doSendEventAndConsumeAll(stateMachine, PersistTestEvents.E1); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S2)); - stateMachine.sendEvent(PersistTestEvents.E2); + doSendEventAndConsumeAll(stateMachine, PersistTestEvents.E2); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S1)); } diff --git a/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java b/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java index ec3c4fb2..5a655369 100644 --- a/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java +++ b/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-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. @@ -18,6 +18,9 @@ package org.springframework.statemachine.data.redis; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.notNullValue; 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 java.util.ArrayList; import java.util.List; @@ -119,32 +122,30 @@ public class RedisRepositoryTests extends AbstractRepositoryTests { } @Test - @SuppressWarnings("unchecked") public void testStateMachinePersistWithStrings() { context.register(TestConfig.class, ConfigWithStrings.class); context.refresh(); - StateMachine stateMachine = context.getBean(StateMachine.class); - stateMachine.start(); + StateMachine stateMachine = resolveMachine(context); + doStartAndAssert(stateMachine); assertThat(stateMachine.getState().getId(), is("S1")); - stateMachine.sendEvent("E1"); + doSendEventAndConsumeAll(stateMachine, "E1"); assertThat(stateMachine.getState().getId(), is("S2")); - stateMachine.sendEvent("E2"); + doSendEventAndConsumeAll(stateMachine, "E2"); assertThat(stateMachine.getState().getId(), is("S1")); } @Test - @SuppressWarnings("unchecked") public void testStateMachinePersistWithEnums() { context.register(TestConfig.class, ConfigWithEnums.class); context.refresh(); - StateMachine stateMachine = context.getBean(StateMachine.class); - stateMachine.start(); + StateMachine stateMachine = resolveMachine(context); + doStartAndAssert(stateMachine); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S1)); - stateMachine.sendEvent(PersistTestEvents.E1); + doSendEventAndConsumeAll(stateMachine, PersistTestEvents.E1); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S2)); - stateMachine.sendEvent(PersistTestEvents.E2); + doSendEventAndConsumeAll(stateMachine, PersistTestEvents.E2); assertThat(stateMachine.getState().getId(), is(PersistTestStates.S1)); }