@Test
public void testHandleMessage() throws UnknownHostException {

    ExtensionServiceMessage msg = new ExtensionServiceMessage("");
    msg.resourceId = sourceName;
    Map<String,Object> object = new LinkedHashMap<>();
    msg.object = object;
    Map<String,Object> config = new LinkedHashMap<>();
    object.put("config", config);
    Map<String,Object> udpSourceConfig = new LinkedHashMap<>();
    config.put("udpSourceConfig", udpSourceConfig);
    Map<String,Object> general = new LinkedHashMap<>();
    Map<String,Object> incoming = new LinkedHashMap<>();
    Map<String,Object> outgoing = new LinkedHashMap<>();
    udpSourceConfig.put("type", "udp");
    udpSourceConfig.put("general", general);
    udpSourceConfig.put("incoming", incoming);
    udpSourceConfig.put("outgoing", outgoing);
    
    udpConfig.handleMessage(msg);
    
    assert !ConfigurableUDPSource.notificationHandlers.containsKey(sourceName);
    assert ConfigurableUDPSource.udpSocketToSources.isEmpty();
    
    int port = 10213;
    String addressName = "invalidAddress";
    incoming.put("passPureMapIn", true);
    outgoing.put("targetPort", port);
    outgoing.put("targetAddress", addressName);
    
    // initialize default address
    InetAddress address = InetAddress.getLocalHost();
    ConfigurableUDPSource.LISTENING_ADDRESS = address;
    
    assumeTrue("Cannot perform test. Address at port:" + port + " and IP:" + address + "already bound"
            , socketCanBind(port, address));
    udpConfig.handleMessage(msg);
    
    assert ConfigurableUDPSource.notificationHandlers.containsKey(sourceName);
    DatagramSocket socket = (DatagramSocket) ConfigurableUDPSource.udpSocketToSources.keySet().toArray()[0];
    assert socket.getLocalPort() == 3141;
    assert socket.getLocalAddress().equals(ConfigurableUDPSource.LISTENING_ADDRESS);
    
    addressName = "localhost";
    address = InetAddress.getByName(addressName);
    general.put("listenPort", port);
    general.put("listenAddress", addressName);
    
    assumeTrue("Cannot perform test. Address at port:" + port + " and IP:" + address + "already bound"
            , socketCanBind(port, address));
    udpConfig.handleMessage(msg);
    
    assert ConfigurableUDPSource.udpSocketToSources.keySet().size() == 2;
}