View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krms.framework;
17  
18  import java.util.Arrays;
19  import java.util.Collections;
20  import java.util.HashSet;
21  import java.util.Map;
22  import java.util.Set;
23  
24  import org.apache.commons.lang.ArrayUtils;
25  import org.kuali.rice.krms.api.engine.TermResolver;
26  
27  /**
28   * Cheesy {@link TermResolver} implementation for testing purposes.
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   *
32   */
33  public class TermResolverMock<T> implements TermResolver<T> {
34  	
35  	private T result;
36  	private String outputName;
37  	private Set<String> params;
38  	
39  	public TermResolverMock(String outputName, T result) {
40  		this(outputName, null, result);
41  	}
42  	
43  	public TermResolverMock(String outputName, String [] params, T result) {
44  		this.outputName = outputName;
45  		this.result = result;
46  		if (ArrayUtils.isEmpty(params)) {
47  			this.params = Collections.emptySet(); 
48  		} else {
49  			this.params = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(params)));
50  		}
51  	}
52  	
53  	@Override
54  	public int getCost() { return 1; }
55  	
56  	@Override
57  	public String getOutput() { return outputName; }
58  	
59  	@Override
60  	public Set<String> getPrerequisites() { return Collections.emptySet(); }
61  	
62  	@Override
63  	public Set<String> getParameterNames() {
64  		return params;
65  	}
66  	
67  	@Override
68  	public T resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) {
69  		return result;
70  	}
71  };