package de.ctdo.bunti.artnet;

import de.ctdo.bunti.dmx.DMX;
import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static junit.framework.Assert.*;

/**
 * @author: lucas
 * @date: 07.03.12 23:33
 */
public class SimpleArtNetSenderImplTest {

    SimpleArtNetSenderImpl dut;
    
    @Before
    public void setUp() throws Exception {
        dut = new SimpleArtNetSenderImpl();
        dut.setSocket(new ArtNetSocketImpl());
    }

    @Test
    public void testSendDMXDataWrong1() throws Exception {
        Map<Integer,Integer> data = new HashMap<Integer, Integer>();
        assertFalse(dut.sendDMXData(data, null));
    }

    @Test
    public void testSendDMXDataWrong2() throws Exception {
        assertFalse(dut.sendDMXData(null, null));
    }

    @Test(expected = ArrayIndexOutOfBoundsException.class)
    public void testSendDMXDataWrong3() throws Exception {
        Map<Integer,Integer> data = new HashMap<Integer, Integer>();
        initDMXData(data);
        data.put(DMX.DMX_CHANNEL_INDEX_MAX+1, 0);
        dut.sendDMXData(data,"127.0.0.1");
    }

    @Test
    public void testSendDMXDataGood1() throws Exception {
        Map<Integer,Integer> data = new HashMap<Integer, Integer>();
        assertTrue(dut.sendDMXData(data,"127.0.0.1"));
    }

    @Test
    public void testSendDMXDataGood2() throws Exception {
        Map<Integer,Integer> data = new HashMap<Integer, Integer>();
        initDMXData(data);
        assertTrue(dut.sendDMXData(data,"127.0.0.1"));
    }

    private void initDMXData(Map<Integer,Integer> dmxData) {
        for (int i = DMX.DMX_CHANNEL_INDEX_MIN; i <= DMX.DMX_CHANNEL_INDEX_MAX; i++) {
            dmxData.put(i, 0);
        }
    }
}
