001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krms.framework;
017
018 import java.util.Arrays;
019 import java.util.Collections;
020 import java.util.HashSet;
021 import java.util.Map;
022 import java.util.Set;
023
024 import org.apache.commons.lang.ArrayUtils;
025 import org.kuali.rice.krms.api.engine.TermResolver;
026
027 /**
028 * Cheesy {@link TermResolver} implementation for testing purposes.
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 *
032 */
033 public class TermResolverMock<T> implements TermResolver<T> {
034
035 private T result;
036 private String outputName;
037 private Set<String> params;
038
039 public TermResolverMock(String outputName, T result) {
040 this(outputName, null, result);
041 }
042
043 public TermResolverMock(String outputName, String [] params, T result) {
044 this.outputName = outputName;
045 this.result = result;
046 if (ArrayUtils.isEmpty(params)) {
047 this.params = Collections.emptySet();
048 } else {
049 this.params = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(params)));
050 }
051 }
052
053 @Override
054 public int getCost() { return 1; }
055
056 @Override
057 public String getOutput() { return outputName; }
058
059 @Override
060 public Set<String> getPrerequisites() { return Collections.emptySet(); }
061
062 @Override
063 public Set<String> getParameterNames() {
064 return params;
065 }
066
067 @Override
068 public T resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) {
069 return result;
070 }
071 };