UDPConfigHandler extends Handler<ExtensionServiceMessage> { boolean isConfiguredToReceive(Map incoming) { return incoming != null && (ConfigurableUDPSource.valueIsTrue(incoming, "receiveAllPorts") || ConfigurableUDPSource.valueIsTrue(incoming, "receiveAllAddresses") || ConfigurableUDPSource.valueIsTrue(incoming, "passPureMapIn") || ConfigurableUDPSource.valueIsTrue(incoming, "passUnspecifiedIn") || ConfigurableUDPSource.valueIsTrue(incoming,"expectCsvIn") || ConfigurableUDPSource.valueIsTrue(incoming,"expectXmlIn") || incoming.get("passRecAddress") instanceof String || incoming.get("passRecPort") instanceof String || incoming.get("passBytesInAs") instanceof String || (incoming.get("receivePorts") instanceof List && hasValidPort((List) incoming.get("receivePorts"))) || (incoming.get("receiveAddresses") instanceof List && hasValidAddress((List) incoming.get("receiveAddresses"))) || (incoming.get("receiveServers") instanceof List && hasValidServer((List) incoming.get("receiveServers"))) || (incoming.get("transformations") instanceof List && hasValidTransform((List) incoming.get("transformations"))) || (incoming.get("regexParser") instanceof Map && isValidRegexParser((Map)incoming.get("regexParser"))) ); }  @Override void handleMessage(ExtensionServiceMessage message);  }
@Test public void testIsConfiguredToReceive() { Map<String,Object> incoming = new LinkedHashMap<>(); incoming.put("receiveAllPorts", false); incoming.put("receiveAllAddresses", false); incoming.put("passPureMapIn", "not a bool"); incoming.put("passUnspecifiedIn", new Object()); incoming.put("passRecAddress", 1357); incoming.put("passRecPort", new ArrayList().add("not actually a string")); List<Object> l = new ArrayList<>(); l.add(1234567); l.add(-1); l.add("2000"); l.add("not a num"); incoming.put("receivePorts", l); l = new ArrayList<>(); l.add(153); l.add(new Object()); l.add("not a valid address"); l.add("1.2.3.4.5"); incoming.put("receiveAddresses", l); l = new ArrayList<>(); List<Object> subl = new ArrayList<>(); subl.add("invalid address"); subl.add(2000); l.add(subl); subl = new ArrayList<>(); subl.add("localhost"); subl.add(-1); l.add(subl); subl = new ArrayList<>(); subl.add(2000); subl.add("localhost"); l.add(subl); incoming.put("receiveServers", l); l = new ArrayList<>(); subl = new ArrayList<>(); subl.add(123); subl.add("location"); l.add(subl); subl = new ArrayList<>(); subl.add("location"); l.add(subl); subl = new ArrayList<>(); subl.add(123); subl.add("location"); subl.add("location2"); l.add(subl); subl = new ArrayList<>(); subl.add("123"); subl.add(new Object()); l.add(subl); incoming.put("transformations", l); Map<String,Object> m = new LinkedHashMap<>(); m.put("pattern", "valid regex"); m.put("locations", "not a list"); incoming.put("regexParser", m); assert !udpConfig.isConfiguredToReceive(incoming); m = new LinkedHashMap<>(); m.put("pattern", "valid regex with (two) (capture groups)"); l = new ArrayList(); l.add("firstLoc"); l.add("secondLocs"); m.put("locations", l); incoming.put("regexParser", m); assert udpConfig.isConfiguredToReceive(incoming); }