/** * Register a bean in the backing bean factory, typically to support a flow execution test. For test scenarios, if * the bean is a service invoked by a bean invoking action it is often a stub or dynamic mock implementation of the * service's business interface. * @param beanName the bean name * @param bean the singleton instance */ public void registerBean(String beanName, Object bean) { ((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory().registerSingleton(beanName, bean); }
/** * Returns a reference to the flow definition registry used by the flow being tested to load subflows. Allows late * registration of dependent subflows on a per test-case basis. This is an alternative to registering such subflows * upfront in {@link #configureFlowBuilderContext(MockFlowBuilderContext)}. * @return the flow definition registry */ protected FlowDefinitionRegistry getFlowDefinitionRegistry() { return (FlowDefinitionRegistry) flowBuilderContext.getFlowDefinitionLocator(); }
/** * Factory method to assemble a flow definition from a resource. Called by {@link #getFlowDefinition()} to create * the "main" flow to test. May also be called by subclasses to create subflow definitions whose executions should * also be exercised by this test. * @return the built flow definition, ready for execution */ protected final Flow buildFlow() { FlowDefinitionResource resource = getResource(getResourceFactory()); flowBuilderContext = new MockFlowBuilderContext(resource.getId(), resource.getAttributes()); configureFlowBuilderContext(flowBuilderContext); FlowBuilder builder = createFlowBuilder(resource); FlowAssembler assembler = new FlowAssembler(builder, flowBuilderContext); return assembler.assembleFlow(); }
protected void setUp() throws Exception { initDataSource(); populateDataBase(); persistenceListener = createFlowExecutionListener(); ClassPathResource resource = new ClassPathResource("managed-root-flow.xml", getClass()); DefaultFlowModelHolder holder = new DefaultFlowModelHolder(new XmlFlowModelBuilder(resource)); FlowModelFlowBuilder builder = new FlowModelFlowBuilder(holder); MockFlowBuilderContext context = new MockFlowBuilderContext("managed-root-flow"); FlowAssembler assembler = new FlowAssembler(builder, context); Flow rootFlow = assembler.assembleFlow(); ClassPathResource childFlowResource = new ClassPathResource("managed-child-flow.xml", getClass()); DefaultFlowModelHolder childFlowHolder = new DefaultFlowModelHolder(new XmlFlowModelBuilder(childFlowResource)); FlowModelFlowBuilder childFlowBuilder = new FlowModelFlowBuilder(childFlowHolder); MockFlowBuilderContext childFlowContext = new MockFlowBuilderContext("managed-child-flow"); FlowAssembler childFlowAssembler = new FlowAssembler(childFlowBuilder, childFlowContext); Flow childFlow = childFlowAssembler.assembleFlow(); Flow notManaged = new Flow("notmanaged-child-flow"); new EndState(notManaged, "finish"); context.registerSubflow(childFlow); context.registerSubflow(notManaged); Action incrementCountAction = incrementCountAction(); context.registerBean("incrementCountAction", incrementCountAction); childFlowContext.registerBean("incrementCountAction", incrementCountAction); Object assertCountAction = assertCountAction(); context.registerBean("assertCountAction", assertCountAction); childFlowContext.registerBean("assertCountAction", assertCountAction); FlowExecutionImplFactory factory = new FlowExecutionImplFactory(); factory.setExecutionListenerLoader(new StaticFlowExecutionListenerLoader(persistenceListener)); flowExecution = factory.createFlowExecution(rootFlow); }
protected void setUp() { MockFlowBuilderContext context = new MockFlowBuilderContext("flowId"); context.getFlowBuilderServices().setApplicationContext(new StaticApplicationContext()); FlowAssembler assembler = new FlowAssembler(new SimpleFlowBuilder(), context); holder = new DefaultFlowHolder(assembler); }
public void testExceptionHandlers() { FlowModel model = new FlowModel(); model.setStates(asList(new EndStateModel("state"))); model.setExceptionHandlers(asList(new ExceptionHandlerModel("exceptionHandler"))); FlowExecutionExceptionHandler handler = new FlowExecutionExceptionHandler() { public boolean canHandle(FlowExecutionException exception) { return true; } public void handle(FlowExecutionException exception, RequestControlContext context) { } }; FlowModelFlowBuilder builder = new FlowModelFlowBuilder(new StaticFlowModelHolder(model)); MockFlowBuilderContext context = new MockFlowBuilderContext("foo"); context.registerBean("exceptionHandler", handler); FlowAssembler assembler = new FlowAssembler(builder, context); Flow flow = assembler.assembleFlow(); assertEquals(1, flow.getExceptionHandlerSet().size()); }
protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) { Flow mockDetailFlow = new Flow("detail-flow"); mockDetailFlow.setInputMapper((source, target) -> { assertEquals("id of value 1 not provided as input by calling search flow", 1L, ((AttributeMap<?>) source).get("id")); return null; }); // test responding to finish result new EndState(mockDetailFlow, "finish"); builderContext.registerSubflow(mockDetailFlow); builderContext.registerBean("phonebook", new TestPhoneBook()); }
public void testNullExpressionEvaluation() throws Exception { serviceLocator.getFlowBuilderServices() .setExpressionParser((expressionString, context) -> new StaticExpression(null)); TransitionCriteria criterion = (TransitionCriteria) converter.convertSourceToTargetClass("doesnt matter", TransitionCriteria.class); RequestContext ctx = getRequestContext(); assertFalse("Criterion should evaluate to false", criterion.test(ctx)); }
protected void setUp() { builder = EasyMock.createMock(FlowBuilder.class); builderContext = new MockFlowBuilderContext("search"); assembler = new FlowAssembler(builder, builderContext); }
private Flow getFlow(FlowModel model) { FlowModelHolder holder = new StaticFlowModelHolder(model); FlowModelFlowBuilder builder = new FlowModelFlowBuilder(holder); FlowAssembler assembler = new FlowAssembler(builder, new MockFlowBuilderContext("flow")); return assembler.assembleFlow(); }
/** * Register a subflow definition in the backing flow registry, typically to support a flow execution test. For test * scenarios, the subflow is often a stub used to verify parent flow input and output mapping behavior. * @param subflow the subflow */ public void registerSubflow(Flow subflow) { ((FlowDefinitionRegistryImpl) getFlowDefinitionLocator()).registerFlowDefinition(subflow); }
/** * Register a bean in the backing bean factory, typically to support a flow execution test. For test scenarios, if * the bean is a service invoked by a bean invoking action it is often a stub or dynamic mock implementation of the * service's business interface. * @param beanName the bean name * @param bean the singleton instance */ public void registerBean(String beanName, Object bean) { ((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory().registerSingleton(beanName, bean); }
/** * Factory method to assemble a flow definition from a resource. Called by {@link #getFlowDefinition()} to create * the "main" flow to test. May also be called by subclasses to create subflow definitions whose executions should * also be exercised by this test. * @return the built flow definition, ready for execution */ protected final Flow buildFlow() { FlowDefinitionResource resource = getResource(getResourceFactory()); flowBuilderContext = new MockFlowBuilderContext(resource.getId(), resource.getAttributes()); configureFlowBuilderContext(flowBuilderContext); FlowBuilder builder = createFlowBuilder(resource); FlowAssembler assembler = new FlowAssembler(builder, flowBuilderContext); return assembler.assembleFlow(); }
/** * Returns a reference to the flow definition registry used by the flow being tested to load subflows. Allows late * registration of dependent subflows on a per test-case basis. This is an alternative to registering such subflows * upfront in {@link #configureFlowBuilderContext(MockFlowBuilderContext)}. * @return the flow definition registry */ protected FlowDefinitionRegistry getFlowDefinitionRegistry() { return (FlowDefinitionRegistry) flowBuilderContext.getFlowDefinitionLocator(); }
/** * Register a bean in the backing bean factory, typically to support a flow execution test. For test scenarios, if * the bean is a service invoked by a bean invoking action it is often a stub or dynamic mock implementation of the * service's business interface. * @param beanName the bean name * @param bean the singleton instance */ public void registerBean(String beanName, Object bean) { ((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory().registerSingleton(beanName, bean); }
/** * Factory method to assemble a flow definition from a resource. Called by {@link #getFlowDefinition()} to create * the "main" flow to test. May also be called by subclasses to create subflow definitions whose executions should * also be exercised by this test. * @return the built flow definition, ready for execution */ protected final Flow buildFlow() { FlowDefinitionResource resource = getResource(getResourceFactory()); flowBuilderContext = new MockFlowBuilderContext(resource.getId(), resource.getAttributes()); configureFlowBuilderContext(flowBuilderContext); FlowBuilder builder = createFlowBuilder(resource); FlowAssembler assembler = new FlowAssembler(builder, flowBuilderContext); return assembler.assembleFlow(); }
/** * Returns a reference to the flow definition registry used by the flow being tested to load subflows. Allows late * registration of dependent subflows on a per test-case basis. This is an alternative to registering such subflows * upfront in {@link #configureFlowBuilderContext(MockFlowBuilderContext)}. * @return the flow definition registry */ protected FlowDefinitionRegistry getFlowDefinitionRegistry() { return (FlowDefinitionRegistry) flowBuilderContext.getFlowDefinitionLocator(); }
private Flow getFlow(ClassPathResource resource) { FlowModelHolder holder = new DefaultFlowModelHolder(new XmlFlowModelBuilder(resource, new FlowModelRegistryImpl())); FlowModelFlowBuilder builder = new FlowModelFlowBuilder(holder); FlowAssembler assembler = new FlowAssembler(builder, new MockFlowBuilderContext("flow")); return assembler.assembleFlow(); }
/** * Register a subflow definition in the backing flow registry, typically to support a flow execution test. For test * scenarios, the subflow is often a stub used to verify parent flow input and output mapping behavior. * @param subflow the subflow */ public void registerSubflow(Flow subflow) { ((FlowDefinitionRegistryImpl) getFlowDefinitionLocator()).registerFlowDefinition(subflow); }
public void testGetFlowDefinitionWithChangesRefreshed() { assembler = new FlowAssembler(new ChangeDetectableFlowBuilder(), new MockFlowBuilderContext("flowId")); holder = new DefaultFlowHolder(assembler); FlowDefinition flow = holder.getFlowDefinition(); assertEquals("flowId", flow.getId()); assertEquals("end", flow.getStartState().getId()); }