org.activiti.engine.test.mock.MockResolverFactory Maven / Gradle / Ivy
/* 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.cfg.ProcessEngineConfigurationImpl;
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 Mocks#register} inside scripts supported by Activiti.
*
* In order to use it, you need to declare it as ResolverFactory, for example by using activiti.cfg.xml like this:
*
*
* <?xml version="1.0" encoding="UTF-8"?>
* <beans xmlns="http://www.springframework.org/schema/beans"
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
* xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
*
* <bean id="processEngineConfiguration"
* class="org.activiti.engine.impl.cfg. StandaloneInMemProcessEngineConfiguration">
* <property name="jobExecutorActivate" value="false" />
* <property name="expressionManager">
* <bean class="org.activiti.engine.test.mock.MockExpressionManager" />
* </property>
* <property name="resolverFactories">
* <list>
* <bean class="org.activiti.engine.impl.scripting.VariableScopeResolverFactory " />
* <bean class="org.activiti.engine.impl.scripting.BeansResolverFactory" />
* <bean class="com.deenero.activiti.MockResolverFactory" />
* </list>
* </property>
* </bean>
*
* </beans>
*
* or by any other means of creating configuration.
*
*
*/
public class MockResolverFactory implements ResolverFactory {
@Override
public Resolver createResolver(ProcessEngineConfigurationImpl processEngineConfiguration, 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;
}
};
}
}