1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Map.Entry;
22
23 import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
24 import org.kuali.rice.krad.service.impl.RemoteModuleServiceBase;
25
26
27
28
29
30
31 public class MockModuleService extends RemoteModuleServiceBase {
32
33 private final List<? extends ExternalizableBusinessObject> instances;
34 private final List<Class<?>> lookupable;
35 private final List<Class<?>> inquirable;
36
37
38
39
40
41
42
43
44 public MockModuleService(List<? extends ExternalizableBusinessObject> instances, List<Class<?>> lookupable,
45 List<Class<?>> inquirable) {
46 this.instances = instances;
47 this.lookupable = lookupable;
48 this.inquirable = inquirable;
49 }
50
51
52
53
54
55 @Override
56 public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(Class<T> businessObjectClass,
57 Map<String, Object> fieldValues) {
58 for (ExternalizableBusinessObject instance : instances) {
59 boolean match = true;
60
61 fieldLoop: for (Entry<String, Object> fieldValue : fieldValues.entrySet()) {
62 Object matchValue = ObjectPropertyUtils.getPropertyValue(instance, fieldValue.getKey());
63 if (matchValue == null ? fieldValue.getValue() != null : !matchValue.equals(fieldValue.getValue())) {
64 match = false;
65 break fieldLoop;
66 }
67 }
68
69 if (match) {
70 return businessObjectClass.cast(instance);
71 }
72 }
73 return null;
74 }
75
76
77
78
79
80 @Override
81 public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsList(
82 Class<T> businessObjectClass, Map<String, Object> fieldValues) {
83 List<T> rv = new ArrayList<T>();
84 for (ExternalizableBusinessObject instance : instances) {
85 boolean match = true;
86
87 fieldLoop: for (Entry<String, Object> fieldValue : fieldValues.entrySet()) {
88 Object matchValue = ObjectPropertyUtils.getPropertyValue(instance, fieldValue.getKey());
89 if (matchValue == null ? fieldValue.getValue() != null : !matchValue.equals(fieldValue.getValue())) {
90 match = false;
91 break fieldLoop;
92 }
93 }
94
95 if (match) {
96 rv.add(businessObjectClass.cast(instance));
97 }
98 }
99 return rv;
100 }
101
102
103
104
105 @Override
106 public boolean isExternalizableBusinessObjectLookupable(@SuppressWarnings("rawtypes") Class boClass) {
107 return lookupable.contains(boClass);
108 }
109
110
111
112
113 @Override
114 public boolean isExternalizableBusinessObjectInquirable(@SuppressWarnings("rawtypes") Class boClass) {
115 return inquirable.contains(boClass);
116 }
117
118 boolean isResponsible(Class<?> boClass) {
119 if (isExternalizableBusinessObjectInquirable(boClass) || isExternalizableBusinessObjectLookupable(boClass)) {
120 return true;
121 }
122
123 for (ExternalizableBusinessObject instance : instances) {
124 if (boClass.isInstance(instance)) {
125 return true;
126 }
127 }
128
129 return false;
130 }
131
132 }