2012-03-06 00:31:25 +00:00
|
|
|
package de.ctdo.bunti.model;
|
|
|
|
|
2012-03-25 15:58:07 +00:00
|
|
|
import de.ctdo.bunti.dmx.model.DMXChannel;
|
2012-03-06 00:31:25 +00:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2012-03-07 21:10:31 +00:00
|
|
|
import static junit.framework.Assert.*;
|
2012-03-06 00:31:25 +00:00
|
|
|
|
|
|
|
public class BuntiDMXDeviceTest {
|
|
|
|
private static final int STARTADDRESS = 42;
|
2012-03-06 17:10:46 +00:00
|
|
|
private static final int DEVICEID = 23;
|
2012-03-06 00:31:25 +00:00
|
|
|
BuntiDMXDevice dut;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
2012-03-25 14:23:45 +00:00
|
|
|
dut = new Par56Spot();
|
|
|
|
dut.setId(23);
|
|
|
|
dut.setStartAddress(42);
|
|
|
|
dut.setDeviceName("deviceName");
|
2012-03-06 00:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetStartAddress() throws Exception {
|
|
|
|
assertEquals(42, dut.getStartAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetStartAddress() throws Exception {
|
|
|
|
dut.setStartAddress(333);
|
|
|
|
assertEquals(333, dut.getStartAddress());
|
|
|
|
}
|
|
|
|
|
2012-03-07 18:17:43 +00:00
|
|
|
@Test
|
|
|
|
public void testSetStartAddressWrong1() throws Exception {
|
|
|
|
assertFalse(dut.setStartAddress(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetStartAddressWrong2() throws Exception {
|
|
|
|
assertFalse(dut.setStartAddress(513));
|
|
|
|
}
|
|
|
|
|
2012-03-06 00:31:25 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetValuesFromOptions() throws Exception {
|
|
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
|
|
options.put("red", 123);
|
|
|
|
assertTrue(dut.setValuesFromOptions(options));
|
|
|
|
}
|
2012-03-06 16:11:21 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetValuesFromOptionsWrong() throws Exception {
|
|
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
|
|
options.put("reddddwrong", 123);
|
2012-03-06 16:56:02 +00:00
|
|
|
assertFalse(dut.setValuesFromOptions(options));
|
2012-03-06 16:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetValuesFromOptionsWrong2() throws Exception {
|
|
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
|
|
options.put("red", null);
|
|
|
|
assertFalse(dut.setValuesFromOptions(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetChannelValueWrong() throws Exception {
|
|
|
|
assertFalse(dut.setChannelValueByName("nonexistend", 42));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetChannelValue() throws Exception {
|
|
|
|
assertTrue(dut.setChannelValueByName("red", 42));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetChannelValueOkay() throws Exception {
|
|
|
|
assertEquals(dut.getChannelValueByName("red"), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetChannelValueWrong() throws Exception {
|
2012-03-07 18:17:43 +00:00
|
|
|
assertEquals(dut.getChannelValueByName("nonexistent"), 0);
|
2012-03-06 16:11:21 +00:00
|
|
|
}
|
2012-03-06 00:31:25 +00:00
|
|
|
|
2012-03-06 17:10:46 +00:00
|
|
|
@Test
|
|
|
|
public void testGetChannelValueWrong2() throws Exception {
|
|
|
|
assertEquals(dut.getChannelValueByName(null), 0);
|
|
|
|
}
|
|
|
|
|
2012-03-06 16:29:57 +00:00
|
|
|
private Map<String, Object> createOptions() {
|
2012-03-06 00:31:25 +00:00
|
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
|
|
options.put("blue", 99);
|
|
|
|
options.put("red", 66);
|
|
|
|
options.put("green", 77);
|
|
|
|
options.put("speed", 111);
|
|
|
|
options.put("mode", 222);
|
2012-03-06 16:29:57 +00:00
|
|
|
return options;
|
|
|
|
}
|
2012-03-06 00:31:25 +00:00
|
|
|
|
2012-03-06 16:29:57 +00:00
|
|
|
@Test
|
|
|
|
public void testGetChannelDataCount() throws Exception {
|
|
|
|
dut.setValuesFromOptions(createOptions());
|
2012-03-06 00:31:25 +00:00
|
|
|
Map<Integer,Integer> channelData = dut.getChannelData();
|
|
|
|
assertEquals(channelData.size(), 5);
|
2012-03-06 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetChannelDataOrder() throws Exception {
|
|
|
|
dut.setValuesFromOptions(createOptions());
|
|
|
|
|
|
|
|
Map<Integer,Integer> channelData = dut.getChannelData();
|
2012-03-06 00:31:25 +00:00
|
|
|
|
2012-03-07 18:17:43 +00:00
|
|
|
assertEquals(new Integer(222), channelData.get(STARTADDRESS));
|
|
|
|
assertEquals(new Integer(66), channelData.get(STARTADDRESS + 1));
|
|
|
|
assertEquals(new Integer(77), channelData.get(STARTADDRESS + 2));
|
|
|
|
assertEquals(new Integer(99), channelData.get(STARTADDRESS + 3));
|
|
|
|
assertEquals(new Integer(111), channelData.get(STARTADDRESS + 4));
|
2012-03-06 00:31:25 +00:00
|
|
|
}
|
2012-03-07 18:17:43 +00:00
|
|
|
|
|
|
|
// @Test
|
|
|
|
// public void testGetChannelDataIndex() throws Exception {
|
|
|
|
// dut = new Par56Spot(42, -10, "faultdevice");
|
|
|
|
// dut.setChannelValueByName("red", 23);
|
|
|
|
// assertEquals(5, dut.getChannelData().size());
|
|
|
|
// }
|
2012-03-06 00:31:25 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAddChannel() throws Exception {
|
|
|
|
dut.addChannel(new DMXChannel(5, "channel"));
|
|
|
|
Map<Integer,Integer> channelData = dut.getChannelData();
|
|
|
|
assertEquals(6, channelData.size());
|
|
|
|
}
|
2012-03-06 16:11:21 +00:00
|
|
|
|
2012-03-06 16:29:57 +00:00
|
|
|
@Test
|
2012-03-06 17:10:46 +00:00
|
|
|
public void testSetDeviceName() throws Exception {
|
2012-03-06 16:29:57 +00:00
|
|
|
dut.setDeviceName("rapunzel");
|
|
|
|
assertEquals("rapunzel", dut.getDeviceName());
|
|
|
|
}
|
2012-03-06 17:10:46 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetDeviceId() throws Exception {
|
2012-03-21 20:22:53 +00:00
|
|
|
assertEquals(DEVICEID, dut.getId());
|
2012-03-06 17:10:46 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
@Test
|
|
|
|
public void testGetPicture() throws Exception {
|
|
|
|
dut.setPicture("urltopicture");
|
|
|
|
assertEquals("urltopicture", dut.getPicture());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetType() throws Exception {
|
|
|
|
assertEquals("Par56Spot", dut.getType());
|
|
|
|
}
|
|
|
|
|
2012-03-06 00:31:25 +00:00
|
|
|
}
|