merge complete

This commit is contained in:
Hendrik Fellerhoff 2012-05-10 17:05:04 +02:00
commit f1bae83556
50 changed files with 937 additions and 354 deletions

45
pom.xml
View File

@ -47,6 +47,13 @@
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -73,15 +80,9 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
@ -90,12 +91,32 @@
<version>3.6.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.160</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
@ -147,11 +168,7 @@
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
</dependencies>

View File

@ -28,7 +28,7 @@ public class ByteUtils {
private final byte[] data;
public ByteUtils(byte[] data) {
this.data = data;
this.data = data.clone();
}
public static int byteToUint(byte b) {
@ -40,7 +40,7 @@ public class ByteUtils {
}
public final byte[] getBytes() {
return data;
return data.clone();
}
public final int getInt16(int offset) {

View File

@ -37,7 +37,7 @@ public abstract class ArtNetPacket {
}
public final void setData(byte[] data) {
this.data = new ByteUtils(data);
this.data = new ByteUtils(data.clone());
}
public final PacketType getType() {

View File

@ -19,6 +19,9 @@
package de.ctdo.bunti.artnet.packets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public enum PacketType {
ART_POLL(0x2000, null),
@ -47,6 +50,8 @@ public enum PacketType {
private final int opCode;
private final Class<? extends ArtNetPacket> packetClass;
private static final Logger LOGGER = LoggerFactory.getLogger(PacketType.class);
private PacketType(int code, Class<? extends ArtNetPacket> clazz) {
opCode = code;
@ -59,9 +64,9 @@ public enum PacketType {
try {
p = packetClass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
LOGGER.error("Could not instanciate ArtNetPacket: ",e);
} catch (IllegalAccessException e) {
e.printStackTrace();
LOGGER.error("Could not instanciate ArtNetPacket: ",e);
}
}
return p;

View File

@ -1,6 +1,7 @@
package de.ctdo.bunti.control;
import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.Room;
import java.util.Collection;
import java.util.Map;
@ -12,4 +13,7 @@ public interface BuntiController {
boolean updateDeviceData(int deviceId, Map<String, Object> options);
Collection<Room> getAllRooms();
Room getRoomById(int roomId);
}

View File

@ -54,6 +54,16 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
return false;
}
@Override
public Collection<Room> getAllRooms() {
return roomsDAO.getRooms();
}
@Override
public Room getRoomById(int roomId) {
return roomsDAO.getRoom(roomId);
}
@Override
public Collection<BuntiDevice> getAllDevices() {
return devicesDAO.getAllDevices();

View File

@ -1,14 +1,17 @@
package de.ctdo.bunti.dao;
import java.util.Collection;
import java.util.List;
import de.ctdo.bunti.model.*;
public interface BuntiDevicesDAO {
Collection<BuntiDevice> getAllDevices();
Collection<BuntiDMXDevice> getAllDMXDevices();
List<BuntiDevice> getAllDevices();
List<BuntiDMXDevice> getAllDMXDevices();
BuntiDevice getDeviceById(int deviceId);
void addDevice(BuntiDevice device);
void removeDevice(int deviceId);
}

View File

@ -1,63 +1,36 @@
package de.ctdo.bunti.dao;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.ctdo.bunti.model.*;
import org.springframework.stereotype.Repository;
@Repository
public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiDevicesDAOImpl.class);
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
public BuntiDevicesDAOImpl() {
addDummyDevices();
}
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
private void addDummyDevices() {
int deviceID = 0;
devices.add(new Par56Spot(deviceID++, 1, "Par56 Lampe 1"));
devices.add(new Par56Spot(deviceID++, 6, "Par56 Lampe 2"));
devices.add(new Par56Spot(deviceID++, 11, "Par56 Lampe 3"));
devices.add(new Par56Spot(deviceID++, 16, "Par56 Lampe 4"));
devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
devices.add(new Par56Spot(deviceID, 508, "Par56 Lampe 5"));
LOGGER.debug("added dummy devices in DAO");
}
public final class BuntiDevicesDAOImpl extends HibernateDaoSupport implements BuntiDevicesDAO {
@Override
public Collection<BuntiDMXDevice> getAllDMXDevices() {
List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
for (BuntiDevice device : devices) {
if( device instanceof BuntiDMXDevice ) {
list.add((BuntiDMXDevice) device);
}
}
return list;
public List<BuntiDMXDevice> getAllDMXDevices() {
return getHibernateTemplate().loadAll(BuntiDMXDevice.class);
}
@Override
public Collection<BuntiDevice> getAllDevices() {
return Collections.unmodifiableCollection(devices);
public List<BuntiDevice> getAllDevices() {
return getHibernateTemplate().loadAll(BuntiDevice.class);
}
@Override
public BuntiDevice getDeviceById(int deviceId) {
for (BuntiDevice dev : devices) {
if(dev.getDeviceId() == deviceId) {
return dev;
return getHibernateTemplate().get(BuntiDevice.class,deviceId);
}
@Override
public void addDevice(BuntiDevice device) {
getHibernateTemplate().save(device);
}
return null;
@Override
public void removeDevice(int deviceId) {
getHibernateTemplate().delete(getDeviceById(deviceId));
}
}

View File

@ -4,16 +4,9 @@ import de.ctdo.bunti.model.Room;
import java.util.List;
/**
* @author: lucas
* @date: 15.03.12 21:55
*/
public interface RoomsDAO {
List<Room> getRooms();
Room getRoom(int id);
Room addRoom(Room room);
void removeRoom(int id);
}

View File

@ -2,17 +2,10 @@ package de.ctdo.bunti.dao;
import de.ctdo.bunti.model.Room;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import java.util.List;
public final class RoomsDAOImpl extends HibernateDaoSupport implements RoomsDAO {
public RoomsDAOImpl() {
}
@Override
public List<Room> getRooms() {
return getHibernateTemplate().loadAll(Room.class);

View File

@ -1,5 +1,7 @@
package de.ctdo.bunti.dmx;
import de.ctdo.bunti.dmx.model.DMXChannel;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;

View File

@ -1,4 +1,4 @@
package de.ctdo.bunti.dmx;
package de.ctdo.bunti.dmx.model;
public class DMXChannel {
private int offset;

View File

@ -1,28 +1,30 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.DMXChannel;
import de.ctdo.bunti.dmx.model.DMXChannel;
import de.ctdo.bunti.dmx.DMXChannels;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Entity;
import javax.persistence.Transient;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@Entity
public abstract class BuntiDMXDevice extends BuntiDevice {
private int startAddress;
private final DMXChannels dmxChannels = new DMXChannels();
public BuntiDMXDevice(int deviceId, int startAddress, String name) {
super(deviceId, name);
setStartAddress(startAddress);
public BuntiDMXDevice() {
}
/**
* Gets the DMX start address for this device
* @return The address value from 1 to max 512
*/
public final int getStartAddress() {
public int getStartAddress() {
return startAddress;
}
@ -31,7 +33,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
* @param startAddress The address value from 1 to max 512
* @return True on success, false if start address is wrong
*/
public final boolean setStartAddress(int startAddress) {
public boolean setStartAddress(int startAddress) {
if(startAddress < DMX.DMX_CHANNEL_INDEX_MIN ||
startAddress - 1 + dmxChannels.getCount() > DMX.DMX_CHANNEL_INDEX_MAX) {
return false;
@ -62,6 +64,8 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
* @param name The channel name to get the value from.
* @return The desired channel value.
*/
@JsonIgnore
@Transient
protected final int getChannelValueByName(String name) {
DMXChannel dx = dmxChannels.getChannelByName(name);
if (dx != null) {
@ -75,6 +79,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
* @return The channel data with startaddress+offset of every channel
*/
@JsonIgnore
@Transient
public Map<Integer, Integer> getChannelData() {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
@ -106,6 +111,18 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
return true;
}
@Transient
@Override
public final Map<String, Object> getOptions() {
Map<String, Object> options = new HashMap<String, Object>();
for(DMXChannel channel: dmxChannels.getAllChannels()) {
options.put(channel.getName(), channel.getValue());
}
return options;
}
/**
* Add a channel to this DMX Device
* used internally by subclasses to define their structure

View File

@ -1,5 +1,6 @@
package de.ctdo.bunti.model;
import javax.persistence.*;
import java.util.Map;
/**
@ -7,43 +8,53 @@ import java.util.Map;
* Maybe this is a lamp, or a switchable power source, or a strobe, ...
* @author lucas
*/
@Entity
@Table(name = "devices")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class BuntiDevice {
private int deviceId;
private int id;
private String deviceName;
private String picture;
public BuntiDevice(int deviceId, String deviceName) {
this.deviceId = deviceId;
this.deviceName = deviceName;
public BuntiDevice() {
}
/**
* Get the type of this device
* @return a string with the class name (=the Type)
*/
@SuppressWarnings("UnusedDeclaration")
@Transient
public final String getType() {
String FQClassName = this.getClass().getName();
int firstChar = FQClassName.lastIndexOf ('.') + 1;
String fqClassName = this.getClass().getName();
int firstChar = fqClassName.lastIndexOf ('.') + 1;
if ( firstChar > 0 ) {
FQClassName = FQClassName.substring ( firstChar );
fqClassName = fqClassName.substring ( firstChar );
}
return FQClassName;
return fqClassName;
}
/**
* Gets the device Id
* @return the device Id
*/
public final int getDeviceId() {
return deviceId;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "BUNTIDEVICE_ID", updatable=false, nullable=false)
public final int getId() {
return id;
}
public final void setId(int id) {
this.id = id;
}
/**
* Gets the device name
* @return The name of the device
*/
public final String getDeviceName() {
public String getDeviceName() {
return deviceName;
}
@ -51,7 +62,7 @@ public abstract class BuntiDevice {
* Sets the device Name
* @param deviceName a String with the device name
*/
public final void setDeviceName(String deviceName) {
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
@ -59,7 +70,7 @@ public abstract class BuntiDevice {
* Get the relative URL to the picture of this device
* @return the relative URL to the picture
*/
public final String getPicture() {
public String getPicture() {
return picture;
}
@ -67,7 +78,7 @@ public abstract class BuntiDevice {
* Get the relative URL to the picture of this device
* @param picture The relative URL to the picture
*/
public final void setPicture(String picture) {
public void setPicture(String picture) {
this.picture = picture;
}
@ -90,4 +101,8 @@ public abstract class BuntiDevice {
public abstract boolean setValuesFromOptions(Map<String, Object> options);
@Transient
public abstract Map<String, Object> getOptions();
}

View File

@ -1,18 +1,18 @@
package de.ctdo.bunti.model;
import javax.persistence.Entity;
import javax.persistence.Transient;
import java.util.Map;
@Entity
public abstract class BuntiSwitchingDevice extends BuntiDevice {
private static final String OPTION_STATE = "state";
private boolean state = false;
public BuntiSwitchingDevice(int deviceId, String deviceName) {
super(deviceId, deviceName);
public BuntiSwitchingDevice() {
}
@Override
public final boolean setValuesFromOptions(Map<String, Object> options) {
@ -30,6 +30,7 @@ public abstract class BuntiSwitchingDevice extends BuntiDevice {
return false;
}
@Transient
public boolean isState() {
return state;
}

View File

@ -1,8 +1,13 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.DMXChannel;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.codehaus.jackson.annotate.JsonIgnore;
import javax.persistence.Entity;
import javax.persistence.Transient;
@Entity
public class Par56Spot extends BuntiDMXDevice {
private static final String CHANNEL_MODE = "mode";
@ -11,8 +16,12 @@ public class Par56Spot extends BuntiDMXDevice {
private static final String CHANNEL_BLUE = "blue";
private static final String CHANNEL_SPEED = "speed";
public Par56Spot(int deviceId, int startAddress, String deviceName) {
super(deviceId, startAddress, deviceName);
public Par56Spot() {
super();
addChannels();
}
private void addChannels() {
int offset = 0;
addChannel(new DMXChannel(offset++, CHANNEL_MODE));
addChannel(new DMXChannel(offset++, CHANNEL_RED));
@ -33,14 +42,20 @@ public class Par56Spot extends BuntiDMXDevice {
setChannelValueByName(CHANNEL_BLUE, value);
}
@JsonIgnore
@Transient
public final int getRed() {
return getChannelValueByName(CHANNEL_RED);
}
@JsonIgnore
@Transient
public final int getGreen() {
return getChannelValueByName(CHANNEL_GREEN);
}
@JsonIgnore
@Transient
public final int getBlue() {
return getChannelValueByName(CHANNEL_BLUE);
}
@ -67,7 +82,7 @@ public class Par56Spot extends BuntiDMXDevice {
public final String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Par56Spot ");
sb.append(getDeviceId());
sb.append(getId());
sb.append(", ");
sb.append(getDeviceName());
sb.append(" [");

View File

@ -1,16 +1,23 @@
package de.ctdo.bunti.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.persistence.*;
import java.util.*;
@Entity
@Table( name = "rooms" )
public final class Room {
private int id;
private String name;
private String floor;
private int xCord;
private int yCord;
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ROOM_ID", updatable=false, nullable=false)
public int getId() {
return id;
}
@ -19,6 +26,7 @@ public final class Room {
this.id = id;
}
@Column( name = "roomName")
public String getName() {
return name;
}
@ -27,26 +35,62 @@ public final class Room {
this.name = name;
}
public int getxCord() {
return xCord;
}
public void setxCord(int xCord) {
this.xCord = xCord;
}
public int getyCord() {
return yCord;
}
public void setyCord(int yCord) {
this.yCord = yCord;
}
public String getFloor() {
return floor;
}
public void setFloor(String floor) {
this.floor = floor;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = BuntiDevice.class)
@JoinTable(name = "ROOM_BUNTIDEVICE",
joinColumns = { @JoinColumn(name = "ROOM_ID") },
inverseJoinColumns = { @JoinColumn(name = "BUNTIDEVICE_ID") })
public List<BuntiDevice> getDevices() {
return Collections.unmodifiableList(this.devices);
}
public void setDevices(List<BuntiDevice> devices) {
this.devices = devices;
}
@Transient
public boolean addDevice(BuntiDevice device) {
return devices.add(device);
return getDevices().add(device);
}
@Transient
public boolean removeDevice(BuntiDevice device) {
return devices.remove(device);
return getDevices().remove(device);
}
@Transient
public BuntiDevice getDevice(int id) {
for (BuntiDevice device: devices) {
if( device.getDeviceId() == id) {
for (BuntiDevice device: getDevices()) {
if( device.getId() == id) {
return device;
}
}
return null;
}
public Collection<BuntiDevice> getDeviceList() {
return Collections.unmodifiableList(devices);
}
}

View File

@ -1,17 +1,25 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.DMXChannel;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.codehaus.jackson.annotate.JsonIgnore;
import javax.persistence.Entity;
import javax.persistence.Transient;
@Entity
public class Strobe1500 extends BuntiDMXDevice {
private static final String CHANNEL_SPEED = "speed";
private static final String CHANNEL_INTENSITY = "intensity";
private static final String CHANNEL_MODE = "mode";
public Strobe1500(int deviceId, int startAddress, String deviceName) {
super(deviceId, startAddress, deviceName);
public Strobe1500() {
super();
addChannels();
}
private void addChannels() {
addChannel(new DMXChannel(0, CHANNEL_SPEED));
addChannel(new DMXChannel(1, CHANNEL_INTENSITY));
addChannel(new DMXChannel(2, CHANNEL_MODE));
@ -29,14 +37,20 @@ public class Strobe1500 extends BuntiDMXDevice {
return setChannelValueByName(CHANNEL_MODE, value);
}
@JsonIgnore
@Transient
public final int getSpeed() {
return getChannelValueByName(CHANNEL_SPEED);
}
@JsonIgnore
@Transient
public final int getIntensity() {
return getChannelValueByName(CHANNEL_INTENSITY);
}
@JsonIgnore
@Transient
public final int getMode() {
return getChannelValueByName(CHANNEL_MODE);
}
@ -59,7 +73,7 @@ public class Strobe1500 extends BuntiDMXDevice {
public final String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Strobe1500 ");
sb.append(getDeviceId());
sb.append(getId());
sb.append(", ");
sb.append(getDeviceName());
sb.append(" [");

View File

@ -0,0 +1,33 @@
package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.webmodel.DeviceUpdate;
import de.ctdo.bunti.webmodel.DeviceUpdates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping(value = "/control")
public class DeviceControlController {
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceControlController.class);
private BuntiController controller;
@Autowired
public final void setController(BuntiController controller) {
this.controller = controller;
}
@RequestMapping(value = "/devices", method = RequestMethod.POST)
public void setDevices(@RequestBody DeviceUpdates updates) {
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
}
}
}

View File

@ -0,0 +1,38 @@
package de.ctdo.bunti.web;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.BuntiDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
@Controller
@RequestMapping(value = "/devices")
public class DevicesController {
private BuntiDevicesDAO devicesDAO;
@Autowired
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
this.devicesDAO = devicesDAO;
}
@RequestMapping(value = "", method = RequestMethod.GET)
public @ResponseBody Collection<BuntiDevice> getAll() {
return devicesDAO.getAllDevices();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
return devicesDAO.getDeviceById(id);
}
@RequestMapping(value = "", method = RequestMethod.POST)
public @ResponseBody BuntiDevice setDevices(@RequestBody BuntiDevice device) {
devicesDAO.addDevice(device);
return device;
}
}

View File

@ -1,62 +0,0 @@
package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.webmodel.DeviceUpdate;
import de.ctdo.bunti.webmodel.DeviceUpdates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.validation.Validator;
import java.util.*;
@Controller
@RequestMapping(value = "/control")
public class RestController {
private static final Logger LOGGER = LoggerFactory.getLogger(RestController.class);
private BuntiController controller;
@Autowired
public final void setController(BuntiController controller) {
this.controller = controller;
}
@RequestMapping(value = "/devices", method = RequestMethod.GET)
public @ResponseBody Collection<BuntiDevice> getAll() {
LOGGER.info("handle GET /devices request");
return controller.getAllDevices();
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
LOGGER.info("handle GET /devices/" + id + " request");
return controller.getDeviceById(id);
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.POST)
public @ResponseBody BuntiDevice setDeviceById(@PathVariable("id") int id, @RequestBody DeviceUpdate update) {
LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() );
controller.updateDeviceData(id, update.getOptions());
return controller.getDeviceById(id);
}
@RequestMapping(value = "/devices", method = RequestMethod.POST)
public String setDevices(@RequestBody DeviceUpdates updates) {
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
}
return "bla";
}
}

View File

@ -0,0 +1,45 @@
package de.ctdo.bunti.web;
import de.ctdo.bunti.dao.RoomsDAO;
import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.Room;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
@Controller
@RequestMapping(value = "/rooms")
public class RoomsController {
private RoomsDAO roomsDAO;
@Autowired
public void setRoomsDAO(RoomsDAO roomsDAO) {
this.roomsDAO = roomsDAO;
}
@RequestMapping(value = "", method = RequestMethod.GET)
public @ResponseBody Collection<Room> getAll() {
return roomsDAO.getRooms();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public @ResponseBody Room getRoomById(@PathVariable("id") int id) {
return roomsDAO.getRoom(id);
}
@RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
public @ResponseBody
List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) {
Room room = roomsDAO.getRoom(id);
if(room != null) {
return room.getDevices();
}
return null;
}
}

View File

@ -1,16 +1,16 @@
package de.ctdo.bunti.webmodel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Diese Klasse gibts nur, weil ich es nicht hinbekomme mit Jackson
* ein ArrayList<DeviceUpdate> als Parameter im Controller zu verarbeiten.
*/
public class DeviceUpdates {
private long timeStamp = 0;
private List<DeviceUpdate> updates = new ArrayList<DeviceUpdate>();
public List<DeviceUpdate> getUpdates() {
return updates;
}

View File

@ -1,44 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:init.sql" />
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:init_schema.sql" />
<jdbc:script location="classpath:init_data.sql" />
</jdbc:embedded-database>
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>/bunti.hbm.xml</value>
</list>
</property>
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan" value="de.ctdo.bunti.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.HSQLDialect
</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">create</prop> -->
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="roomsDAO" class="de.ctdo.bunti.dao.RoomsDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="devicesDAO" class="de.ctdo.bunti.dao.BuntiDevicesDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<tx:annotation-driven />
</beans>

View File

@ -1,14 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true">
<class name="de.ctdo.bunti.model.Room" table="rooms" >
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>

View File

@ -1,2 +1,2 @@
db.driverClassName=org.hsqldb.jdbcDriver
db.url=jdbc:hsqldb:mem:buntiserver
#db.driverClassName=org.hsqldb.jdbcDriver
#db.url=jdbc:hsqldb:mem:buntiserver

View File

@ -1,12 +0,0 @@
DROP TABLE DUAL_HIBERNATE_SEQUENCE IF EXISTS
DROP TABLE ROOMS IF EXISTS
DROP TABLE SEQUENCE IF EXISTS
CREATE MEMORY TABLE SEQUENCE(SEQ_NAME VARCHAR(50) NOT NULL PRIMARY KEY,SEQ_COUNT NUMERIC(38))
CREATE MEMORY TABLE ROOMS(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,NAME VARCHAR(255))
CREATE MEMORY TABLE DUAL_HIBERNATE_SEQUENCE(ZERO INTEGER)
INSERT INTO SEQUENCE VALUES('SEQ_GEN',0)

View File

@ -0,0 +1,19 @@
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Kueche', '0', '0');
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Wohnzimmer', '0', '1');
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Werkstatt', '1', '0');
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Flur', '1', '1');
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe1',null, 1);
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe2',null, 6);
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe3',null, 11);
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
values ('Par56Spot',null,'Lampe4',null, 16);

View File

@ -0,0 +1,29 @@
drop table ROOM_BUNTIDEVICE if exists;
drop table devices if exists;
drop table rooms if exists;
create table ROOM_BUNTIDEVICE (ROOM_ID integer not null, BUNTIDEVICE_ID int not null,
primary key (ROOM_ID, BUNTIDEVICE_ID), unique (BUNTIDEVICE_ID));
create table devices (DTYPE varchar(31) not null,
BUNTIDEVICE_ID integer generated by default as identity (start with 1),
deviceName varchar(255),
picture varchar(255),
startAddress integer,
primary key (BUNTIDEVICE_ID));
create table rooms (ROOM_ID integer generated by default as identity (start with 1),
floor varchar(255),
roomName varchar(255),
xCord integer not null,
yCord integer not null,
primary key (ROOM_ID));
alter table ROOM_BUNTIDEVICE add constraint FK96EF8F028BB4B62 foreign key (ROOM_ID) references rooms;
alter table ROOM_BUNTIDEVICE add constraint FK96EF8F021E9F392 foreign key (BUNTIDEVICE_ID) references devices;

View File

@ -1,15 +0,0 @@
#log4j.rootLogger=debug, stdout
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
##log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c: %m%n
#log4j.appender.R=org.apache.log4j.RollingFileAppender
#log4j.appender.R.File=application.log
#log4j.appender.R.MaxFileSize=100KB
#log4j.appender.R.MaxBackupIndex=1
#log4j.appender.R.layout=org.apache.log4j.PatternLayout
#log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

View File

@ -15,18 +15,18 @@
<level value="info" />
</logger>
<logger name="org.springframework.orm">
<level value="debug" />
</logger>
<logger name="de.ctdo">
<level value="debug" />
</logger>
<logger name="org.hibernate">
<level value="info" />
</logger>
<root>
<priority value="debug" />
<priority value="info" />
<appender-ref ref="console" />
</root>

View File

@ -12,6 +12,7 @@
<link type="text/css" href="<c:url value="/resources/css/smoothness/jquery-ui-1.8.18.custom.css"/>" rel="stylesheet" />
<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.1.min.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/jquery-ui-1.8.18.custom.min.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/events.class.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/jquery.cookie.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/underscore.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/backbone-min.js" />"></script>
@ -26,45 +27,8 @@
</head>
<body>
<h1>CTDO Raumsteuerung</h1>
<div id="container">
<div id="room-tabs">
<ul>
<li><a href="#tabs-1">Global</a></li>
<li><a href="#tabs-2">Raum 1</a></li>
</ul>
<div id="tabs-1">
</div>
<div id="tabs-2">
<div id="v-tabs" class="inner-tabs-container">
<ul>
<li><a href="#v-tabs-1">Licht</a></li>
<li><a href="#v-tabs-2">Musik</a></li>
<li><a href="#v-tabs-3">Lampel</a></li>
</ul>
<div id="v-tabs-1">
<div id="colorpicker-raum1"></div>
<select multiple="multiple" id="par56select">
</select>
</div>
<div id="v-tabs-2">
<label for="slider1">Lautstärke Raum 1:</label><div id="slider1" class="slider"></div>
</div>
<div id="v-tabs-3">
<div class="lampel">
<span class="circle red" title="click to toggle"></span>
<span class="circle yellow" title="click to toggle"></span>
<span class="circle green" title="click to toggle"></span>
</div>
</div>
</div>
<div class="switch">
Raumlicht:<br />
<input type="radio" name="raum-1-licht">An <input type="radio" name="raum-1-licht" checked="checked">Aus
</div>
</div>
</div>
@ -80,6 +44,20 @@
</div>
{{/each}}
</script>
<script type="text/x-handlebars-template" id="room-vertical-tabs-template">
<div id="room{{roomId}}-vertical-tabs" class="ui-tabs-vertical">
<ul>
{{#each types}}
<li><a href="#room{{roomId}}-vertical-tabs-{{id}}">{{typeName}}</a></li>
{{/each}}
</ul>
{{#each types}}
<div id="room{{roomId}}-vertical-tabs-{{id}}">
</div>
{{/each}}
</div>
</script>
<script type="text/x-handlebars-template" id="par56-options-template">
{{#each devices}}
<option name="{{deviceId}}">{{deviceName}}</option>
@ -91,6 +69,15 @@
<button>Buzzern</button>
</div>
</script>
<script type="text/x-handlebars-template" id="lampel-template">
<div class="lampel">
<span class="circle red" title="click to toggle"></span>
<span class="circle yellow" title="click to toggle"></span>
<span class="circle green" title="click to toggle"></span>
</div>
</script>
<script type="text/x-handlebars-template">
</script>

View File

@ -0,0 +1,77 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WebSockets</title>
<link type="text/css" href="<c:url value="/resources/css/screen.css"/>" rel="stylesheet"/>
<link type="text/css" href="<c:url value="/resources/css/styles.css"/>" rel="stylesheet"/>
<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.1.min.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/js/main.js" />"></script>
<script type="text/javascript">
function sendData(data) {
var time = Math.round(new Date().getTime() / 1000);
data = {"timeStamp":time, "updates":data};
$.ajax({
type:'POST',
url:"/control/devices",
contentType:"application/json",
dataType:"json",
data:JSON.stringify(data)
});
console.log(data);
console.log(JSON.stringify(data));
}
$('#par56 .pink').click(function () {
data = [
{"deviceId":0, "options":{"red":255, "green":0, "blue":40}},
{"deviceId":1, "options":{"red":255, "green":0, "blue":40}},
{"deviceId":2, "options":{"red":255, "green":0, "blue":40}},
{"deviceId":3, "options":{"red":255, "green":0, "blue":40}}
];
sendData(data);
});
$('#par56 .gruen').click(function () {
data = [
{"deviceId":0, "options":{"red":0, "green":255, "blue":0}},
{"deviceId":1, "options":{"red":0, "green":255, "blue":0}},
{"deviceId":2, "options":{"red":0, "green":255, "blue":0}},
{"deviceId":3, "options":{"red":0, "green":255, "blue":0}}
];
sendData(data);
});
$('#par56 .rot').click(function () {
data = [
{"deviceId":0, "options":{"red":255, "green":0, "blue":0}},
{"deviceId":1, "options":{"red":255, "green":0, "blue":0}},
{"deviceId":2, "options":{"red":255, "green":0, "blue":0}},
{"deviceId":3, "options":{"red":255, "green":0, "blue":0}}
];
sendData(data);
});
</script>
</head>
<body>
<h1>CTDO Raumsteuerung</h1>
<p id="par56">Par56: <br>
<button class="pink">Pink</button>
<button class="gruen">Grün</button>
<button class="rot">Rot</button>
</p>
<p id="lampel">Lampel:<br>
<button class="rota">Rot (an)</button>
<button class="gelba">Gelb (an)</button>
<button class="gruena">Grün (an)</button>
<button class="roto">Rot (aus)</button>
<button class="gelbo">Gelb (aus)</button>
<button class="grueno">Grün (aus)</button>
</p>
</body>
</html>

View File

@ -0,0 +1,51 @@
//Copyright (c) 2010 Nicholas C. Zakas. All rights reserved.
//MIT License
function EventTarget(){
this._listeners = {};
}
EventTarget.prototype = {
constructor: EventTarget,
addListener: function(type, listener){
if (typeof this._listeners[type] == "undefined"){
this._listeners[type] = [];
}
this._listeners[type].push(listener);
},
fire: function(event){
if (typeof event == "string"){
event = { type: event };
}
if (!event.target){
event.target = this;
}
if (!event.type){ //falsy
throw new Error("Event object missing 'type' property.");
}
if (this._listeners[event.type] instanceof Array){
var listeners = this._listeners[event.type];
for (var i=0, len=listeners.length; i < len; i++){
listeners[i].call(this, event);
}
}
},
removeListener: function(type, listener){
if (this._listeners[type] instanceof Array){
var listeners = this._listeners[type];
for (var i=0, len=listeners.length; i < len; i++){
if (listeners[i] === listener){
listeners.splice(i, 1);
break;
}
}
}
}
};

View File

@ -5,7 +5,9 @@
* Time: 00:51
* Main Javascript file
*/
var events = new EventTarget();
var roomDevices = [];
var roomDeviceViews = [];
Workspace = Backbone.Router.extend({
routes:{
"":"home",
@ -13,11 +15,27 @@ Workspace = Backbone.Router.extend({
},
home: function() {
function roomsLoadedHandler() {
rooms.each(function(room) {
var id = room.get('roomId');
roomDevices[id] = new RoomDevices();
roomDevices[id].url = '/resources/json/room' + id + '.json';
roomDevices[id].fetch();
});
events.removeListener("roomsLoaded", roomsLoadedHandler);
}
events.addListener("roomsLoaded", roomsLoadedHandler);
rooms.fetch();
},
show_room: function(id) {
this.home();
window.roomTabsId = id;
function roomsLoadedHandlerTabSelect() {
$('#room-tabs').tabs('select', id);
events.removeListener("roomsLoaded", roomsLoadedHandlerTabSelect)
}
events.addListener("roomsLoaded", roomsLoadedHandlerTabSelect);
}
});
$(document).ready(function() {

View File

@ -5,8 +5,8 @@
url: '/resources/json/rooms.json'
});
window.Device = Backbone.Model.extend({});
window.Devices = Backbone.Collection.extend({
model: Device,
url: '/control/devices'
window.RoomDevices = Backbone.Collection.extend({
model: Device
});
})(jQuery);

View File

@ -3,12 +3,46 @@ window.RoomsView = Backbone.View.extend({
this.collection.bind('reset', this.render, this);
},
render: function() {
$('#room-tabs').tabs('destroy');
this.template = Handlebars.compile($("#room-tabs-template").html());
var rooms = {'rooms': this.collection.toJSON()};
$('#room-tabs').html(this.template(rooms)).tabs();
if(typeof(window.roomTabsId) != "undefined") {
$('#room-tabs').tabs('select', window.roomTabsId);
$('#room-tabs').html(this.template(rooms)).tabs({
select: function(event, ui) {
//set hashtag?
}
});
events.fire("roomsLoaded");
return this;
}
});
window.LampelView = Backbone.View.extend({
initialize: function() {
this.collection.bind('reset', this.render, this);
},
render: function() {
events.fire("lampelLoaded");
return this;
}
});
window.BuzzerView = Backbone.View.extend({
initialize: function() {
this.collection.bind('reset', this.render, this);
},
render: function() {
events.fire("buzzerLoaded");
return this;
}
});
window.Par56View = Backbone.View.extend({
initialize: function() {
this.collection.bind('reset', this.render, this);
},
render: function() {
events.fire("par56Loaded");
return this;
}
});

View File

@ -0,0 +1,11 @@
[
{
"type":"Buzzer",
"deviceId":0,
"deviceName":"Buzzer",
"picture":null,
"options": {
"state":0
}
}
]

View File

@ -0,0 +1,85 @@
[
{
"startAddress":1,
"type":"Par56Spot",
"deviceId":0,
"deviceName":"Par56 Lampe 1",
"picture":null,
"options": {
"red":0,
"green":0,
"blue":0
}
},
{
"startAddress":6,
"type":"Par56Spot",
"deviceId":1,
"deviceName":"Par56 Lampe 2",
"picture":null,
"options": {
"red":0,
"green":0,
"blue":0
}
},
{
"startAddress":11,
"type":"Par56Spot",
"deviceId":2,
"deviceName":"Par56 Lampe 3",
"picture":null,
"options": {
"red":0,
"green":0,
"blue":0
}
},
{
"startAddress":16,
"type":"Par56Spot",
"deviceId":3,
"deviceName":"Par56 Lampe 5",
"picture":null,
"options": {
"red":0,
"green":0,
"blue":0
}
},
{
"startAddress":21,
"type":"Strobe1500",
"deviceId":4,
"deviceName":"Stroboskop 1",
"picture":null,
"options": {
"mode":0,
"speed":0,
"intensity":0
}
},
{
"startAddress":508,
"type":"Par56Spot",
"deviceId":5,
"deviceName":"Par56 Lampe 5",
"picture":null,
"options": {
"red":0,
"green":0,
"blue":0
}
},
{
"type":"Lampel",
"deviceId":6,
"deviceName":"Lampel",
"picture":null,
"options": {
"red":0,
"green":0,
"blue":0
}
},
]

View File

@ -0,0 +1,40 @@
package de.ctdo.bunti.control;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//@ContextConfiguration(locations = { "classpath:/META-INF/spring/root-context.xml","classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
//@RunWith(SpringJUnit4ClassRunner.class)
//public class BuntiControllerImplTest {
// @Autowired
// BuntiController dut;
//
// @Test
// public void testUpdateDeviceData() throws Exception {
//
// }
//
// @Test
// public void testGetAllRooms() throws Exception {
//
// }
//
// @Test
// public void testGetRoomById() throws Exception {
//
// }
//
// @Test
// public void testGetAllDevices() throws Exception {
//
// }
//
// @Test
// public void testGetDeviceById() throws Exception {
//
// }
//}

View File

@ -1,23 +0,0 @@
package de.ctdo.bunti.control;
import org.junit.Before;
public class BuntiControllerTest {
BuntiControllerImpl dut;
@Before
public void setUp() throws Exception {
dut = new BuntiControllerImpl();
// dut.setDevicesDAO(daoMock);
}
// @Test
// public void testSetDevice() throws Exception {
// Map<String,Object> options = new HashMap<String, Object>();
// options.put("optionA", "valueA");
// options.put("optionB", 42);
// assertTrue(dut.updateDeviceData(12, options));
// }
}

View File

@ -0,0 +1,43 @@
package de.ctdo.bunti.dao;
import de.ctdo.bunti.model.BuntiDMXDevice;
import de.ctdo.bunti.model.BuntiDevice;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Collection;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
@ContextConfiguration(locations = { "classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class BuntiDevicesDAOImplTest {
@Autowired
BuntiDevicesDAO dut;
@Test
public void testGetAllDMXDevices() throws Exception {
List<BuntiDMXDevice> deviceList = dut.getAllDMXDevices();
assertEquals(4, deviceList.size());
}
@Test
public void testGetAllDevices() throws Exception {
List<BuntiDevice> deviceList = dut.getAllDevices();
assertEquals(4, deviceList.size());
}
@Test
public void testGetDeviceById() throws Exception {
BuntiDevice device = dut.getDeviceById(2);
assertEquals("Lampe2", device.getDeviceName());
}
}

View File

@ -0,0 +1,34 @@
package de.ctdo.bunti.dao;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
@ContextConfiguration(locations = { "classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class RoomsDAOImplTest {
@Autowired
RoomsDAO dut;
@Test
// @Transactional
public void testGetRooms() throws Exception {
assertEquals(4, dut.getRooms().size());
}
@Test
public void testGetRoomKueche() throws Exception {
assertEquals("Kueche", dut.getRoom(1).getName());
}
@Test
public void testGetRoomKuecheError() throws Exception {
assertNull(dut.getRoom(23));
}
}

View File

@ -1,5 +1,6 @@
package de.ctdo.bunti.dmx;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.junit.Before;
import org.junit.Test;

View File

@ -1,5 +1,6 @@
package de.ctdo.bunti.dmx;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.junit.Before;
import org.junit.Test;

View File

@ -36,7 +36,10 @@ public class DMXMixerImplTest {
@Test
public void testUpdateDevice() throws Exception {
BuntiDevice device = new Par56Spot(23,42,"deviceName");
Par56Spot device = new Par56Spot();
device.setId(23);
device.setStartAddress(42);
device.setDeviceName("deviceName");
Map<String,Object> options = new HashMap<String, Object>();
options.put("red", 44);
assertTrue(dut.updateDevice(device, options));
@ -44,7 +47,10 @@ public class DMXMixerImplTest {
@Test
public void testUpdateDeviceWrong1() throws Exception {
BuntiDevice device = new Par56Spot(23,42,"deviceName");
Par56Spot device = new Par56Spot();
device.setId(23);
device.setStartAddress(42);
device.setDeviceName("deviceName");
assertFalse(dut.updateDevice(device, null));
}
@ -57,14 +63,20 @@ public class DMXMixerImplTest {
@Test
public void testUpdateDeviceWrong3() throws Exception {
BuntiDevice device = new Par56Spot(23,42,"deviceName");
Par56Spot device = new Par56Spot();
device.setId(23);
device.setStartAddress(42);
device.setDeviceName("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");
Par56Spot device = new Par56Spot();
device.setId(23);
device.setStartAddress(42);
device.setDeviceName("deviceName");
Map<String,Object> options = new HashMap<String, Object>();
options.put("rednonexistent", 44);
assertFalse(dut.updateDevice(device, options));

View File

@ -1,6 +1,6 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMXChannel;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.junit.Before;
import org.junit.Test;
@ -16,7 +16,10 @@ public class BuntiDMXDeviceTest {
@Before
public void setUp() throws Exception {
dut = new Par56Spot(DEVICEID,STARTADDRESS,"device");
dut = new Par56Spot();
dut.setId(23);
dut.setStartAddress(42);
dut.setDeviceName("deviceName");
}
@Test
@ -139,7 +142,7 @@ public class BuntiDMXDeviceTest {
@Test
public void testGetDeviceId() throws Exception {
assertEquals(DEVICEID, dut.getDeviceId());
assertEquals(DEVICEID, dut.getId());
}
@Test

View File

@ -9,8 +9,10 @@ public class Par56SpotTest {
@Before
public void setUp() throws Exception {
dut = new Par56Spot(23,42,"device");
dut = new Par56Spot();
dut.setId(23);
dut.setStartAddress(42);
dut.setDeviceName("device");
}
@Test

View File

@ -10,8 +10,10 @@ public class Strobe1500Test {
@Before
public void setUp() throws Exception {
dut = new Strobe1500(23,42,"device");
dut = new Strobe1500();
dut.setId(23);
dut.setStartAddress(42);
dut.setDeviceName("device");
}
@Test

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:init_schema.sql" />
<jdbc:script location="classpath:init_data.sql" />
</jdbc:embedded-database>
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan" value="de.ctdo.bunti.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="roomsDAO" class="de.ctdo.bunti.dao.RoomsDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="devicesDAO" class="de.ctdo.bunti.dao.BuntiDevicesDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<tx:annotation-driven />
</beans>