/* 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.activiti.engine.test.mock; import org.activiti.engine.delegate.VariableScope; import org.activiti.engine.impl.scripting.Resolver; import org.activiti.engine.impl.scripting.ResolverFactory; /** * This is a bridge resolver, making available any objects registered through * {@link org.activiti.engine.test.mock.Mocks#register} inside scripts supported * by Activiti. <br> * <br> * In order to use it, you need to declare it as ResolverFactory, for example by using activiti.cfg.xml like this: <br><br> * * <?xml version="1.0" encoding="UTF-8"?><br> * <beans xmlns="http://www.springframework.org/schema/beans"<br> * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br> * xsi:schemaLocation="http://www.springframework.org/schema/beans * http://www.springframework.org/schema/beans/spring-beans.xsd"><br> * <br> * <bean id="processEngineConfiguration"<br> * class="org.activiti.engine.impl.cfg. * StandaloneInMemProcessEngineConfiguration"><br> * <property name="jobExecutorActivate" value="false" * /><br> * <property name="expressionManager"><br> * <bean * class="org.activiti.engine.test.mock.MockExpressionManager" /><br> * </property><br> * <property name="resolverFactories"><br> * <list><br> * <bean * class="org.activiti.engine.impl.scripting.VariableScopeResolverFactory * " /><br> * <bean * class="org.activiti.engine.impl.scripting.BeansResolverFactory" * /><br> * <bean class="com.deenero.activiti.MockResolverFactory" /><br> * </list><br> * </property><br> * </bean><br> * <br> * </beans> <br> * <br> * or by any other means of creating configuration. * * @author Emil Genov (http://www.emil-genov.info/) * */ public class MockResolverFactory implements ResolverFactory { @Override public Resolver createResolver(VariableScope variableScope) { return new Resolver() { @Override public Object get(Object key) { return Mocks.get(key); } @Override public boolean containsKey(Object key) { return Mocks.get(key) != null; } }; } }