From 55c6faf225205c9ae25667c26ebfe06816065144 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sat, 19 Nov 2016 17:51:15 +0000 Subject: [PATCH] Fix Redis/Mongo entity states - Fix RedisRepositoryState and MongoDbStateRepository not to use null for machineid in any case as contract is that empty machineid is always empty not null. - This issue was found when adding initial tck config tests, thus this commit also adds initial tck tests. - Fixes #279 - Relates to #278 --- build.gradle | 7 + .../buildtests/tck/AbstractTckTests.java | 89 ++++++++++++ .../tck/javaconfig/AnnotationTckTests.java | 72 ++++++++++ .../buildtests/tck/jpa/JpaJsonTckTests.java | 100 ++++++++++++++ .../buildtests/tck/jpa/JpaManualTckTests.java | 107 +++++++++++++++ .../tck/mongodb/MongoDbJsonTckTests.java | 121 +++++++++++++++++ .../tck/mongodb/MongoDbManualTckTests.java | 127 +++++++++++++++++ .../buildtests/tck/mongodb/MongoDbRule.java | 53 ++++++++ .../tck/redis/RedisJsonTckTests.java | 121 +++++++++++++++++ .../tck/redis/RedisManualTckTests.java | 128 ++++++++++++++++++ .../buildtests/tck/redis/RedisRule.java | 52 +++++++ .../buildtests/tck/uml/UmlTckTests.java | 65 +++++++++ .../buildtests/tck/jpa/SimpleMachine.json | 32 +++++ .../buildtests/tck/mongodb/SimpleMachine.json | 32 +++++ .../buildtests/tck/redis/SimpleMachine.json | 32 +++++ .../buildtests/tck/uml/SimpleMachine.di | 2 + .../buildtests/tck/uml/SimpleMachine.notation | 120 ++++++++++++++++ .../buildtests/tck/uml/SimpleMachine.uml | 22 +++ .../data/mongodb/MongoDbRepositoryState.java | 2 +- .../data/redis/RedisRepositoryState.java | 2 +- 20 files changed, 1284 insertions(+), 2 deletions(-) create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/AbstractTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/javaconfig/AnnotationTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaJsonTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaManualTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbJsonTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbManualTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisJsonTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisManualTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisRule.java create mode 100644 spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/uml/UmlTckTests.java create mode 100644 spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/jpa/SimpleMachine.json create mode 100644 spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/mongodb/SimpleMachine.json create mode 100644 spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/redis/SimpleMachine.json create mode 100644 spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.di create mode 100644 spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.notation create mode 100644 spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.uml diff --git a/build.gradle b/build.gradle index 0a32a50b..de1c38e8 100644 --- a/build.gradle +++ b/build.gradle @@ -305,6 +305,13 @@ project('spring-statemachine-build-tests') { dependencies { testCompile project(":spring-statemachine-uml") testCompile project(":spring-statemachine-test") + testCompile project(":spring-statemachine-data-common:spring-statemachine-data-jpa") + testCompile project(":spring-statemachine-data-common:spring-statemachine-data-redis") + testCompile project(":spring-statemachine-data-common:spring-statemachine-data-mongodb") + testRuntime "org.springframework.boot:spring-boot-starter-data-redis:$springBootVersion" + testCompile "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion" + testCompile "com.h2database:h2:$h2Version" + testCompile "org.springframework.boot:spring-boot-starter:$springBootVersion" testCompile "org.springframework:spring-test:$springVersion" testCompile "org.hamcrest:hamcrest-core:$hamcrestVersion" testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion" diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/AbstractTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/AbstractTckTests.java new file mode 100644 index 00000000..5f9a104c --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/AbstractTckTests.java @@ -0,0 +1,89 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.config.StateMachineFactory; +import org.springframework.statemachine.test.StateMachineTestPlan; +import org.springframework.statemachine.test.StateMachineTestPlanBuilder; + +/** + * Base tck test class for defining various machine tests + * which different config implementations can implement to + * test that same machine behaviour. + * + * @author Janne Valkealahti + * + */ +public abstract class AbstractTckTests { + + protected AnnotationConfigApplicationContext context; + + @Before + public void setup() { + cleanInternal(); + context = buildContext(); + } + + @After + public void clean() { + if (context != null) { + context.close(); + } + context = null; + } + + @SuppressWarnings("unchecked") + protected StateMachine getStateMachineFromContext() { + return context.getBean(StateMachine.class); + } + + @SuppressWarnings("unchecked") + protected StateMachineFactory getStateMachineFactoryFromContext() { + return context.getBean(StateMachineFactory.class); + } + + protected void cleanInternal() { + } + + protected AnnotationConfigApplicationContext buildContext() { + return null; + } + + @Test + public void testSimpleMachine() throws Exception { + StateMachine stateMachine = getSimpleMachine(); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .stateMachine(stateMachine) + .step().expectStates("S1").and() + .step().sendEvent("E1").expectStates("S2").and() + .step().sendEvent("E2").expectStates("S3").and() + .build(); + plan.test(); + } + + /** + * Return state machine for {@link #testSimpleMachine()}. + * + * @return StateMachine for SimpleMachine + */ + protected abstract StateMachine getSimpleMachine(); +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/javaconfig/AnnotationTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/javaconfig/AnnotationTckTests.java new file mode 100644 index 00000000..74bb4c4d --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/javaconfig/AnnotationTckTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.javaconfig; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachine; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; +import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; + +/** + * Tck tests for annotation based javaconfig. + * + * @author Janne Valkealahti + * + */ +public class AnnotationTckTests extends AbstractTckTests { + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(SimpleMachineConfig.class); + context.refresh(); + return getStateMachineFromContext(); + } + + @Configuration + @EnableStateMachine + static class SimpleMachineConfig extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineStateConfigurer states) throws Exception { + states + .withStates() + .initial("S1") + .state("S2") + .state("S3"); + } + + @Override + public void configure(StateMachineTransitionConfigurer transitions) throws Exception { + transitions + .withExternal() + .source("S1").target("S2") + .event("E1") + .and() + .withExternal() + .source("S2").target("S3") + .event("E2"); + } + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaJsonTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaJsonTckTests.java new file mode 100644 index 00000000..16995734 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaJsonTckTests.java @@ -0,0 +1,100 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.jpa; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachineFactory; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryState; +import org.springframework.statemachine.data.RepositoryStateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryTransition; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.support.StateMachineJackson2RepositoryPopulatorFactoryBean; + +/** + * Tck tests for machine configs imported from json entity definitions. + * + * @author Janne Valkealahti + * + */ +public class JpaJsonTckTests extends AbstractTckTests { + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(TestConfig.class, SimpleMachineConfig.class, StateMachineFactoryConfig.class); + context.refresh(); + return getStateMachineFactoryFromContext().getStateMachine(); + } + + @Configuration + public static class SimpleMachineConfig { + + @Bean + public StateMachineJackson2RepositoryPopulatorFactoryBean jackson2RepositoryPopulatorFactoryBean() { + StateMachineJackson2RepositoryPopulatorFactoryBean factoryBean = new StateMachineJackson2RepositoryPopulatorFactoryBean(); + factoryBean.setResources(new Resource[]{new ClassPathResource("org/springframework/statemachine/buildtests/tck/jpa/SimpleMachine.json")}); + return factoryBean; + } + } + + @Configuration + @EnableStateMachineFactory + public static class StateMachineFactoryConfig extends StateMachineConfigurerAdapter { + + @Autowired + private StateRepository stateRepository; + + @Autowired + private TransitionRepository transitionRepository; + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + return new RepositoryStateMachineModelFactory(stateRepository, transitionRepository); + } + } + + @EnableAutoConfiguration + @EntityScan(basePackages = {"org.springframework.statemachine.data.jpa"}) + @EnableJpaRepositories(basePackages = {"org.springframework.statemachine.data.jpa"}) + static class TestConfig { + } + +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaManualTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaManualTckTests.java new file mode 100644 index 00000000..785f4728 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/jpa/JpaManualTckTests.java @@ -0,0 +1,107 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.jpa; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachineFactory; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryState; +import org.springframework.statemachine.data.RepositoryStateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryTransition; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.jpa.JpaRepositoryState; +import org.springframework.statemachine.data.jpa.JpaRepositoryTransition; +import org.springframework.statemachine.data.jpa.JpaStateRepository; +import org.springframework.statemachine.data.jpa.JpaTransitionRepository; + +/** + * Tck tests for machine configs build manually agains repository interfaces. + * + * @author Janne Valkealahti + * + */ +public class JpaManualTckTests extends AbstractTckTests { + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(TestConfig.class, StateMachineFactoryConfig.class); + context.refresh(); + + JpaStateRepository stateRepository = context.getBean(JpaStateRepository.class); + JpaTransitionRepository transitionRepository = context.getBean(JpaTransitionRepository.class); + + JpaRepositoryState stateS1 = new JpaRepositoryState("S1", true); + JpaRepositoryState stateS2 = new JpaRepositoryState("S2"); + JpaRepositoryState stateS3 = new JpaRepositoryState("S3"); + + stateRepository.save(stateS1); + stateRepository.save(stateS2); + stateRepository.save(stateS3); + + JpaRepositoryTransition transitionS1ToS2 = new JpaRepositoryTransition(stateS1, stateS2, "E1"); + JpaRepositoryTransition transitionS2ToS3 = new JpaRepositoryTransition(stateS2, stateS3, "E2"); + + transitionRepository.save(transitionS1ToS2); + transitionRepository.save(transitionS2ToS3); + + return getStateMachineFactoryFromContext().getStateMachine(); + } + + @Configuration + @EnableStateMachineFactory + public static class StateMachineFactoryConfig extends StateMachineConfigurerAdapter { + + @Autowired + private StateRepository stateRepository; + + @Autowired + private TransitionRepository transitionRepository; + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + return new RepositoryStateMachineModelFactory(stateRepository, transitionRepository); + } + } + + @EnableAutoConfiguration + @EntityScan(basePackages = {"org.springframework.statemachine.data.jpa"}) + @EnableJpaRepositories(basePackages = {"org.springframework.statemachine.data.jpa"}) + static class TestConfig { + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbJsonTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbJsonTckTests.java new file mode 100644 index 00000000..0257d0ce --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbJsonTckTests.java @@ -0,0 +1,121 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.mongodb; + +import org.junit.Rule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachineFactory; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryState; +import org.springframework.statemachine.data.RepositoryStateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryTransition; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryAction; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryGuard; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryState; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryTransition; +import org.springframework.statemachine.data.support.StateMachineJackson2RepositoryPopulatorFactoryBean; + +/** + * Tck tests for machine configs imported from json entity definitions. + * + * @author Janne Valkealahti + * + */ +public class MongoDbJsonTckTests extends AbstractTckTests { + + @Rule + public MongoDbRule MongoDbAvailableRule = new MongoDbRule(); + + @Override + protected void cleanInternal() { + AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext(); + c.register(TestConfig.class); + c.refresh(); + MongoTemplate template = c.getBean(MongoTemplate.class); + template.dropCollection(MongoDbRepositoryAction.class); + template.dropCollection(MongoDbRepositoryGuard.class); + template.dropCollection(MongoDbRepositoryState.class); + template.dropCollection(MongoDbRepositoryTransition.class); + c.close(); + } + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(TestConfig.class, SimpleMachineConfig.class, StateMachineFactoryConfig.class); + context.refresh(); + return getStateMachineFactoryFromContext().getStateMachine(); + } + + @Configuration + public static class SimpleMachineConfig { + + @Bean + public StateMachineJackson2RepositoryPopulatorFactoryBean jackson2RepositoryPopulatorFactoryBean() { + StateMachineJackson2RepositoryPopulatorFactoryBean factoryBean = new StateMachineJackson2RepositoryPopulatorFactoryBean(); + factoryBean.setResources(new Resource[]{new ClassPathResource("org/springframework/statemachine/buildtests/tck/mongodb/SimpleMachine.json")}); + return factoryBean; + } + } + + @Configuration + @EnableStateMachineFactory + public static class StateMachineFactoryConfig extends StateMachineConfigurerAdapter { + + @Autowired + private StateRepository stateRepository; + + @Autowired + private TransitionRepository transitionRepository; + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + return new RepositoryStateMachineModelFactory(stateRepository, transitionRepository); + } + } + + @EnableAutoConfiguration + @EntityScan(basePackages = {"org.springframework.statemachine.data.mongodb"}) + @EnableMongoRepositories(basePackages = {"org.springframework.statemachine.data.mongodb"}) + static class TestConfig { + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbManualTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbManualTckTests.java new file mode 100644 index 00000000..780204a8 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbManualTckTests.java @@ -0,0 +1,127 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.mongodb; + +import org.junit.Rule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachineFactory; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryState; +import org.springframework.statemachine.data.RepositoryStateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryTransition; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryAction; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryGuard; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryState; +import org.springframework.statemachine.data.mongodb.MongoDbRepositoryTransition; +import org.springframework.statemachine.data.mongodb.MongoDbStateRepository; +import org.springframework.statemachine.data.mongodb.MongoDbTransitionRepository; + +/** + * Tck tests for machine configs build manually agains repository interfaces. + * + * @author Janne Valkealahti + * + */ +public class MongoDbManualTckTests extends AbstractTckTests { + + @Rule + public MongoDbRule MongoDbAvailableRule = new MongoDbRule(); + + @Override + protected void cleanInternal() { + AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext(); + c.register(TestConfig.class); + c.refresh(); + MongoTemplate template = c.getBean(MongoTemplate.class); + template.dropCollection(MongoDbRepositoryAction.class); + template.dropCollection(MongoDbRepositoryGuard.class); + template.dropCollection(MongoDbRepositoryState.class); + template.dropCollection(MongoDbRepositoryTransition.class); + c.close(); + } + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(TestConfig.class, StateMachineFactoryConfig.class); + context.refresh(); + + MongoDbStateRepository stateRepository = context.getBean(MongoDbStateRepository.class); + MongoDbTransitionRepository transitionRepository = context.getBean(MongoDbTransitionRepository.class); + + MongoDbRepositoryState stateS1 = new MongoDbRepositoryState("S1", true); + MongoDbRepositoryState stateS2 = new MongoDbRepositoryState("S2"); + MongoDbRepositoryState stateS3 = new MongoDbRepositoryState("S3"); + + stateRepository.save(stateS1); + stateRepository.save(stateS2); + stateRepository.save(stateS3); + + MongoDbRepositoryTransition transitionS1ToS2 = new MongoDbRepositoryTransition(stateS1, stateS2, "E1"); + MongoDbRepositoryTransition transitionS2ToS3 = new MongoDbRepositoryTransition(stateS2, stateS3, "E2"); + + transitionRepository.save(transitionS1ToS2); + transitionRepository.save(transitionS2ToS3); + + return getStateMachineFactoryFromContext().getStateMachine(); + } + + @Configuration + @EnableStateMachineFactory + public static class StateMachineFactoryConfig extends StateMachineConfigurerAdapter { + + @Autowired + private StateRepository stateRepository; + + @Autowired + private TransitionRepository transitionRepository; + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + return new RepositoryStateMachineModelFactory(stateRepository, transitionRepository); + } + } + + @EnableAutoConfiguration + @EntityScan(basePackages = {"org.springframework.statemachine.data.mongodb"}) + @EnableMongoRepositories(basePackages = {"org.springframework.statemachine.data.mongodb"}) + static class TestConfig { + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java new file mode 100644 index 00000000..b1cf8233 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.mongodb; + +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import com.mongodb.MongoClient; +import com.mongodb.MongoClientOptions; +import com.mongodb.ServerAddress; + +/** + * Rule skipping tests if MongoDb is not available from localhost with default settings. + * + * @author Janne Valkealahti + * + */ +public class MongoDbRule extends TestWatcher implements TestRule { + + @Override + public Statement apply(Statement base, Description description) { + MongoClient client = null; + try { + client = new MongoClient(new ServerAddress(), MongoClientOptions.builder().connectTimeout(50).build()); + client.getAddress(); + } catch (Exception e) { + return super.apply(new Statement() { + @Override + public void evaluate() throws Throwable { + } + }, Description.EMPTY); + } finally { + if (client != null) { + client.close(); + } + } + return super.apply(base, description); + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisJsonTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisJsonTckTests.java new file mode 100644 index 00000000..e104f54b --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisJsonTckTests.java @@ -0,0 +1,121 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.redis; + +import org.junit.Rule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.data.keyvalue.core.KeyValueTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachineFactory; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryState; +import org.springframework.statemachine.data.RepositoryStateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryTransition; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.redis.RedisRepositoryAction; +import org.springframework.statemachine.data.redis.RedisRepositoryGuard; +import org.springframework.statemachine.data.redis.RedisRepositoryState; +import org.springframework.statemachine.data.redis.RedisRepositoryTransition; +import org.springframework.statemachine.data.support.StateMachineJackson2RepositoryPopulatorFactoryBean; + +/** + * Tck tests for machine configs imported from json entity definitions. + * + * @author Janne Valkealahti + * + */ +public class RedisJsonTckTests extends AbstractTckTests { + + @Rule + public RedisRule redisAvailableRule = new RedisRule(); + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected void cleanInternal() { + AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext(); + c.register(TestConfig.class); + c.refresh(); + KeyValueTemplate kvTemplate = c.getBean(KeyValueTemplate.class); + kvTemplate.delete(RedisRepositoryAction.class); + kvTemplate.delete(RedisRepositoryGuard.class); + kvTemplate.delete(RedisRepositoryState.class); + kvTemplate.delete(RedisRepositoryTransition.class); + c.close(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(TestConfig.class, SimpleMachineConfig.class, StateMachineFactoryConfig.class); + context.refresh(); + return getStateMachineFactoryFromContext().getStateMachine(); + } + + @Configuration + public static class SimpleMachineConfig { + + @Bean + public StateMachineJackson2RepositoryPopulatorFactoryBean jackson2RepositoryPopulatorFactoryBean() { + StateMachineJackson2RepositoryPopulatorFactoryBean factoryBean = new StateMachineJackson2RepositoryPopulatorFactoryBean(); + factoryBean.setResources(new Resource[]{new ClassPathResource("org/springframework/statemachine/buildtests/tck/redis/SimpleMachine.json")}); + return factoryBean; + } + } + + @Configuration + @EnableStateMachineFactory + public static class StateMachineFactoryConfig extends StateMachineConfigurerAdapter { + + @Autowired + private StateRepository stateRepository; + + @Autowired + private TransitionRepository transitionRepository; + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + return new RepositoryStateMachineModelFactory(stateRepository, transitionRepository); + } + } + + @EnableAutoConfiguration + @EntityScan(basePackages = {"org.springframework.statemachine.data.redis"}) + @EnableRedisRepositories(basePackages = {"org.springframework.statemachine.data.redis"}) + static class TestConfig { + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisManualTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisManualTckTests.java new file mode 100644 index 00000000..b7ac6db4 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisManualTckTests.java @@ -0,0 +1,128 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.redis; + +import org.junit.Rule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.keyvalue.core.KeyValueTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachineFactory; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryState; +import org.springframework.statemachine.data.RepositoryStateMachineModelFactory; +import org.springframework.statemachine.data.RepositoryTransition; +import org.springframework.statemachine.data.StateRepository; +import org.springframework.statemachine.data.TransitionRepository; +import org.springframework.statemachine.data.redis.RedisRepositoryAction; +import org.springframework.statemachine.data.redis.RedisRepositoryGuard; +import org.springframework.statemachine.data.redis.RedisRepositoryState; +import org.springframework.statemachine.data.redis.RedisRepositoryTransition; +import org.springframework.statemachine.data.redis.RedisStateRepository; +import org.springframework.statemachine.data.redis.RedisTransitionRepository; + +/** + * Tck tests for machine configs build manually agains repository interfaces. + * + * @author Janne Valkealahti + * + */ +public class RedisManualTckTests extends AbstractTckTests { + + @Rule + public RedisRule redisAvailableRule = new RedisRule(); + + @Override + protected void cleanInternal() { + AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext(); + c.register(TestConfig.class); + c.refresh(); + KeyValueTemplate kvTemplate = c.getBean(KeyValueTemplate.class); + kvTemplate.delete(RedisRepositoryAction.class); + kvTemplate.delete(RedisRepositoryGuard.class); + kvTemplate.delete(RedisRepositoryState.class); + kvTemplate.delete(RedisRepositoryTransition.class); + c.close(); + } + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(TestConfig.class, StateMachineFactoryConfig.class); + context.refresh(); + + RedisStateRepository stateRepository = context.getBean(RedisStateRepository.class); + RedisTransitionRepository transitionRepository = context.getBean(RedisTransitionRepository.class); + + RedisRepositoryState stateS1 = new RedisRepositoryState("S1", true); + RedisRepositoryState stateS2 = new RedisRepositoryState("S2"); + RedisRepositoryState stateS3 = new RedisRepositoryState("S3"); + + stateRepository.save(stateS1); + stateRepository.save(stateS2); + stateRepository.save(stateS3); + + + RedisRepositoryTransition transitionS1ToS2 = new RedisRepositoryTransition(stateS1, stateS2, "E1"); + RedisRepositoryTransition transitionS2ToS3 = new RedisRepositoryTransition(stateS2, stateS3, "E2"); + + transitionRepository.save(transitionS1ToS2); + transitionRepository.save(transitionS2ToS3); + + return getStateMachineFactoryFromContext().getStateMachine(); + } + + @Configuration + @EnableStateMachineFactory + public static class StateMachineFactoryConfig extends StateMachineConfigurerAdapter { + + @Autowired + private StateRepository stateRepository; + + @Autowired + private TransitionRepository transitionRepository; + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + return new RepositoryStateMachineModelFactory(stateRepository, transitionRepository); + } + } + + @EnableAutoConfiguration + @EntityScan(basePackages = {"org.springframework.statemachine.data.redis"}) + @EnableRedisRepositories(basePackages = {"org.springframework.statemachine.data.redis"}) + static class TestConfig { + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisRule.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisRule.java new file mode 100644 index 00000000..9c4b15c7 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/redis/RedisRule.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.redis; + +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; + +/** + * Rule skipping tests if redis is not available from localhost with default settings. + * + * @author Janne Valkealahti + * + */ +public class RedisRule extends TestWatcher implements TestRule { + + @Override + public Statement apply(Statement base, Description description) { + JedisConnectionFactory connectionFactory = null; + try { + connectionFactory = new JedisConnectionFactory(); + connectionFactory.afterPropertiesSet(); + connectionFactory.getConnection().close(); + } catch (Exception e) { + return super.apply(new Statement() { + @Override + public void evaluate() throws Throwable { + } + }, Description.EMPTY); + } finally { + if (connectionFactory != null) { + connectionFactory.destroy(); + } + } + return super.apply(base, description); + } +} diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/uml/UmlTckTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/uml/UmlTckTests.java new file mode 100644 index 00000000..d41bc11c --- /dev/null +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/uml/UmlTckTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.buildtests.tck.uml; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.buildtests.tck.AbstractTckTests; +import org.springframework.statemachine.config.EnableStateMachine; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.uml.UmlStateMachineModelFactory; + +/** + * Tck tests for machine configs build from uml. + * + * @author Janne Valkealahti + * + */ +public class UmlTckTests extends AbstractTckTests { + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Override + protected StateMachine getSimpleMachine() { + context.register(SimpleMachineConfig.class); + context.refresh(); + return getStateMachineFromContext(); + } + + @Configuration + @EnableStateMachine + public static class SimpleMachineConfig extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + return new UmlStateMachineModelFactory("classpath:org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.uml"); + } + } +} diff --git a/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/jpa/SimpleMachine.json b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/jpa/SimpleMachine.json new file mode 100644 index 00000000..b0e38eef --- /dev/null +++ b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/jpa/SimpleMachine.json @@ -0,0 +1,32 @@ +[ + { + "@id": "1", + "_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState", + "initial": true, + "state": "S1" + }, + { + "@id": "2", + "_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState", + "initial": false, + "state": "S2" + }, + { + "@id": "3", + "_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState", + "initial": false, + "state": "S3" + }, + { + "_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition", + "source": "1", + "target": "2", + "event": "E1" + }, + { + "_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition", + "source": "2", + "target": "3", + "event": "E2" + } +] diff --git a/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/mongodb/SimpleMachine.json b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/mongodb/SimpleMachine.json new file mode 100644 index 00000000..5bb251b7 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/mongodb/SimpleMachine.json @@ -0,0 +1,32 @@ +[ + { + "@id": "1", + "_class": "org.springframework.statemachine.data.mongodb.MongoDbRepositoryState", + "initial": true, + "state": "S1" + }, + { + "@id": "2", + "_class": "org.springframework.statemachine.data.mongodb.MongoDbRepositoryState", + "initial": false, + "state": "S2" + }, + { + "@id": "3", + "_class": "org.springframework.statemachine.data.mongodb.MongoDbRepositoryState", + "initial": false, + "state": "S3" + }, + { + "_class": "org.springframework.statemachine.data.mongodb.MongoDbRepositoryTransition", + "source": "1", + "target": "2", + "event": "E1" + }, + { + "_class": "org.springframework.statemachine.data.mongodb.MongoDbRepositoryTransition", + "source": "2", + "target": "3", + "event": "E2" + } +] diff --git a/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/redis/SimpleMachine.json b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/redis/SimpleMachine.json new file mode 100644 index 00000000..ff3d993b --- /dev/null +++ b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/redis/SimpleMachine.json @@ -0,0 +1,32 @@ +[ + { + "@id": "1", + "_class": "org.springframework.statemachine.data.redis.RedisRepositoryState", + "initial": true, + "state": "S1" + }, + { + "@id": "2", + "_class": "org.springframework.statemachine.data.redis.RedisRepositoryState", + "initial": false, + "state": "S2" + }, + { + "@id": "3", + "_class": "org.springframework.statemachine.data.redis.RedisRepositoryState", + "initial": false, + "state": "S3" + }, + { + "_class": "org.springframework.statemachine.data.redis.RedisRepositoryTransition", + "source": "1", + "target": "2", + "event": "E1" + }, + { + "_class": "org.springframework.statemachine.data.redis.RedisRepositoryTransition", + "source": "2", + "target": "3", + "event": "E2" + } +] diff --git a/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.di b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.di new file mode 100644 index 00000000..bf9abab3 --- /dev/null +++ b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.di @@ -0,0 +1,2 @@ + + diff --git a/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.notation b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.notation new file mode 100644 index 00000000..3d46f9fa --- /dev/null +++ b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.notation @@ -0,0 +1,120 @@ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.uml b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.uml new file mode 100644 index 00000000..dd072daa --- /dev/null +++ b/spring-statemachine-build-tests/src/test/resources/org/springframework/statemachine/buildtests/tck/uml/SimpleMachine.uml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-statemachine-data/mongodb/src/main/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryState.java b/spring-statemachine-data/mongodb/src/main/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryState.java index 429d8fac..f1385134 100644 --- a/spring-statemachine-data/mongodb/src/main/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryState.java +++ b/spring-statemachine-data/mongodb/src/main/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryState.java @@ -121,7 +121,7 @@ public class MongoDbRepositoryState extends RepositoryState { */ public MongoDbRepositoryState(String machineId, MongoDbRepositoryState parentState, String state, boolean initial, Set stateActions, Set entryActions, Set exitActions) { - this.machineId = machineId; + this.machineId = machineId == null ? "" : machineId; this.parentState = parentState; this.state = state; this.initial = initial; diff --git a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java index 4b4cebfd..d7157006 100644 --- a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java +++ b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java @@ -131,7 +131,7 @@ public class RedisRepositoryState extends RepositoryState { */ public RedisRepositoryState(String machineId, RedisRepositoryState parentState, String state, boolean initial, Set stateActions, Set entryActions, Set exitActions) { - this.machineId = machineId; + this.machineId = machineId == null ? "" : machineId; this.parentState = parentState; this.state = state; this.initial = initial;