package de.ctdo.bunti.dmx;

import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.Par56Spot;
import org.junit.Before;
import org.junit.Test;

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

import static org.junit.Assert.*;

public class DMXMixerImplTest {
    DMXMixerImpl dut;

    @Before
    public void setUp() throws Exception {
        dut = new DMXMixerImpl();
    }

    @Test
    public void testSetArtNetSender() throws Exception {

    }

    @Test
    public void testSetArtNetDeviceAddress() throws Exception {
        dut.setArtNetDeviceAddress("172.0.0.1");
    }


    @Test(expected = NullPointerException.class)
    public void testSendOutDMXBuffer() throws Exception {
        dut.sendOutDMXBuffer();
    }

    @Test
    public void testUpdateDevice() throws Exception {
        BuntiDevice device = new Par56Spot(23,42,"deviceName");
        Map<String,Object> options = new HashMap<String, Object>();
        options.put("red", 44);
        assertTrue(dut.updateDevice(device, options));
    }

    @Test
    public void testUpdateDeviceWrong1() throws Exception {
        BuntiDevice device = new Par56Spot(23,42,"deviceName");
        assertFalse(dut.updateDevice(device, null));
    }

    @Test
    public void testUpdateDeviceWrong2() throws Exception {
        Map<String,Object> options = new HashMap<String, Object>();
        options.put("red", 44);
        assertFalse(dut.updateDevice(null, options));
    }

    @Test
    public void testUpdateDeviceWrong3() throws Exception {
        BuntiDevice device = new Par56Spot(23,42,"deviceName");
        Map<String,Object> options = new HashMap<String, Object>();
        assertFalse(dut.updateDevice(device, options));
    }

    @Test
    public void testUpdateDeviceWrong4() throws Exception {
        BuntiDevice device = new Par56Spot(23,42,"deviceName");
        Map<String,Object> options = new HashMap<String, Object>();
        options.put("rednonexistent", 44);
        assertFalse(dut.updateDevice(device, options));
    }

    @Test
    public void testSetDMX512ChannelGood1() throws Exception {
        assertTrue(dut.setDMX512Channel(512, 255));
    }

    @Test
    public void testSetDMX512ChannelGood2() throws Exception {
        assertTrue(dut.setDMX512Channel(512, 0));
    }

    @Test
    public void testSetDMX512ChannelGood3() throws Exception {
        assertTrue(dut.setDMX512Channel(1, -10));
    }

    @Test
    public void testSetDMX512ChannelGood4() throws Exception {
        assertTrue(dut.setDMX512Channel(140, 300));
    }

    @Test
    public void testSetDMX512ChannelBad1() throws Exception {
        assertFalse(dut.setDMX512Channel(0, 10));
    }

    @Test
    public void testSetDMX512ChannelBad2() throws Exception {
        assertFalse(dut.setDMX512Channel(513, 10));
    }

    @Test
    public void testSetDMX512ChannelBad3() throws Exception {
        assertFalse(dut.setDMX512Channel(-1, -10));
    }

    @Test
    public void testOnApplicationEvent() throws Exception {

    }
}
