public class FilterTestUtil {
private static final Splitter PATH_SPLITTER = Splitter.on("/").omitEmptyStrings().trimResults();
// Returns a message container that has the given routing key , and payload that has the given path and given value
public static MessageContainer makeMessageContainer(String routingKey, String path, Object value) throws Exception {
MessageContainer container = mock(MessageContainer.class);
when(container.getRoutingKey()).thenReturn(routingKey);
if(path == null) {
return container;
}
List<String> steps = Lists.newArrayList(PATH_SPLITTER.split(path));
Map<String, Object> map = Maps.newHashMap();
Map<String, Object> current = map;
for(int i = 0; i < steps.size() - 1; i++) {
String step = steps.get(i);
Map<String, Object> obj = Maps.newHashMap();
current.put(step, obj);
current = obj;
}
current.put(steps.get(steps.size() - 1), value);
when(container.getEntity(Map.class)).thenReturn(map);
return container;
}