diff --git a/pom.xml b/pom.xml index 29a81ca..a3d308a 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,13 @@ ${org.springframework.version} + + org.springframework + spring-test + ${org.springframework.version} + + + org.slf4j slf4j-api @@ -73,15 +80,9 @@ - javax.validation - validation-api - 1.0.0.GA - - - - org.hibernate - hibernate-validator - 4.1.0.Final + org.springframework + spring-orm + ${org.springframework.version} @@ -90,12 +91,32 @@ 3.6.7.Final + + org.hibernate + hibernate-commons-annotations + 3.2.0.Final + + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + 1.0.1.Final + + org.hsqldb hsqldb 1.8.0.10 + + com.h2database + h2 + 1.3.160 + + + + joda-time @@ -147,11 +168,7 @@ jetty-server ${jettyVersion} - - org.springframework - spring-orm - 3.0.6.RELEASE - + diff --git a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java index c702647..10c0232 100644 --- a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java +++ b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java @@ -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) { diff --git a/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java b/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java index a63e753..2beaae6 100644 --- a/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java +++ b/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java @@ -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() { diff --git a/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java b/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java index 874e8d3..a5c3dd8 100644 --- a/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java +++ b/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java @@ -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 packetClass; + private static final Logger LOGGER = LoggerFactory.getLogger(PacketType.class); + private PacketType(int code, Class 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; diff --git a/src/main/java/de/ctdo/bunti/control/BuntiController.java b/src/main/java/de/ctdo/bunti/control/BuntiController.java index ae9f0f1..0374d7c 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiController.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiController.java @@ -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 options); + Collection getAllRooms(); + Room getRoomById(int roomId); + } diff --git a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java index bca6fbb..95cb875 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java @@ -16,7 +16,7 @@ import de.ctdo.bunti.dao.BuntiDevicesDAO; import de.ctdo.bunti.model.*; @Component -public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware { +public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware { private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class); private ApplicationEventPublisher applicationEventPublisher = null; private BuntiDevicesDAO devicesDAO; @@ -54,6 +54,16 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub return false; } + @Override + public Collection getAllRooms() { + return roomsDAO.getRooms(); + } + + @Override + public Room getRoomById(int roomId) { + return roomsDAO.getRoom(roomId); + } + @Override public Collection getAllDevices() { return devicesDAO.getAllDevices(); diff --git a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java index 13bd25c..5c27899 100644 --- a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java +++ b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java @@ -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 getAllDevices(); - Collection getAllDMXDevices(); + List getAllDevices(); + List getAllDMXDevices(); BuntiDevice getDeviceById(int deviceId); + void addDevice(BuntiDevice device); + void removeDevice(int deviceId); } diff --git a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java index a142599..0510847 100644 --- a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java +++ b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java @@ -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 devices = new ArrayList(); - - 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 getAllDMXDevices() { - List list = new ArrayList(); - for (BuntiDevice device : devices) { - if( device instanceof BuntiDMXDevice ) { - list.add((BuntiDMXDevice) device); - } - } - return list; + public List getAllDMXDevices() { + return getHibernateTemplate().loadAll(BuntiDMXDevice.class); } @Override - public Collection getAllDevices() { - return Collections.unmodifiableCollection(devices); + public List getAllDevices() { + return getHibernateTemplate().loadAll(BuntiDevice.class); } @Override public BuntiDevice getDeviceById(int deviceId) { - for (BuntiDevice dev : devices) { - if(dev.getDeviceId() == deviceId) { - return dev; - } - } - return null; + return getHibernateTemplate().get(BuntiDevice.class,deviceId); } + @Override + public void addDevice(BuntiDevice device) { + getHibernateTemplate().save(device); + } + + @Override + public void removeDevice(int deviceId) { + getHibernateTemplate().delete(getDeviceById(deviceId)); + } + } diff --git a/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java b/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java index f25fbb2..ecb686d 100644 --- a/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java +++ b/src/main/java/de/ctdo/bunti/dao/RoomsDAO.java @@ -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 getRooms(); Room getRoom(int id); Room addRoom(Room room); void removeRoom(int id); - - } diff --git a/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java b/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java index b3359a2..d82e74b 100644 --- a/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java +++ b/src/main/java/de/ctdo/bunti/dao/RoomsDAOImpl.java @@ -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 getRooms() { return getHibernateTemplate().loadAll(Room.class); diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java b/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java index 43374f8..521e4e7 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java +++ b/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java @@ -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; diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXChannel.java b/src/main/java/de/ctdo/bunti/dmx/model/DMXChannel.java similarity index 95% rename from src/main/java/de/ctdo/bunti/dmx/DMXChannel.java rename to src/main/java/de/ctdo/bunti/dmx/model/DMXChannel.java index 528cc76..9e386af 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMXChannel.java +++ b/src/main/java/de/ctdo/bunti/dmx/model/DMXChannel.java @@ -1,4 +1,4 @@ -package de.ctdo.bunti.dmx; +package de.ctdo.bunti.dmx.model; public class DMXChannel { private int offset; diff --git a/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java index 13f1d4c..0a281fb 100644 --- a/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java +++ b/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java @@ -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 getChannelData() { Map map = new HashMap(); @@ -106,6 +111,18 @@ public abstract class BuntiDMXDevice extends BuntiDevice { return true; } + @Transient + @Override + public final Map getOptions() { + Map options = new HashMap(); + + 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 diff --git a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java index d0bbba3..4bcb9d3 100644 --- a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java +++ b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java @@ -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 options); + @Transient + public abstract Map getOptions(); + } + diff --git a/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java index 949c0f2..293269d 100644 --- a/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java +++ b/src/main/java/de/ctdo/bunti/model/BuntiSwitchingDevice.java @@ -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 options) { @@ -30,6 +30,7 @@ public abstract class BuntiSwitchingDevice extends BuntiDevice { return false; } + @Transient public boolean isState() { return state; } diff --git a/src/main/java/de/ctdo/bunti/model/Par56Spot.java b/src/main/java/de/ctdo/bunti/model/Par56Spot.java index c59c0e2..b5b7f69 100644 --- a/src/main/java/de/ctdo/bunti/model/Par56Spot.java +++ b/src/main/java/de/ctdo/bunti/model/Par56Spot.java @@ -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(" ["); diff --git a/src/main/java/de/ctdo/bunti/model/Room.java b/src/main/java/de/ctdo/bunti/model/Room.java index 8eed3d3..ebb2b06 100644 --- a/src/main/java/de/ctdo/bunti/model/Room.java +++ b/src/main/java/de/ctdo/bunti/model/Room.java @@ -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 devices = new ArrayList(); + @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; } @@ -26,27 +34,63 @@ public final class Room { public void setName(String name) { this.name = name; } - - public boolean addDevice(BuntiDevice device) { - return devices.add(device); - } - - public boolean removeDevice(BuntiDevice device) { - return devices.remove(device); + + 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 getDevices() { + return Collections.unmodifiableList(this.devices); + } + + public void setDevices(List devices) { + this.devices = devices; + } + + + @Transient + public boolean addDevice(BuntiDevice device) { + return getDevices().add(device); + } + + @Transient + public boolean removeDevice(BuntiDevice 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 getDeviceList() { - return Collections.unmodifiableList(devices); - } - - } diff --git a/src/main/java/de/ctdo/bunti/model/Strobe1500.java b/src/main/java/de/ctdo/bunti/model/Strobe1500.java index f0bd9f7..4cbb134 100644 --- a/src/main/java/de/ctdo/bunti/model/Strobe1500.java +++ b/src/main/java/de/ctdo/bunti/model/Strobe1500.java @@ -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(" ["); diff --git a/src/main/java/de/ctdo/bunti/web/DeviceControlController.java b/src/main/java/de/ctdo/bunti/web/DeviceControlController.java new file mode 100644 index 0000000..6428089 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/web/DeviceControlController.java @@ -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()); + } + } + +} diff --git a/src/main/java/de/ctdo/bunti/web/DevicesController.java b/src/main/java/de/ctdo/bunti/web/DevicesController.java new file mode 100644 index 0000000..5e7dfa2 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/web/DevicesController.java @@ -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 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; + } + + +} diff --git a/src/main/java/de/ctdo/bunti/web/RestController.java b/src/main/java/de/ctdo/bunti/web/RestController.java deleted file mode 100644 index a6ebce6..0000000 --- a/src/main/java/de/ctdo/bunti/web/RestController.java +++ /dev/null @@ -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 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"; - } - -} diff --git a/src/main/java/de/ctdo/bunti/web/RoomsController.java b/src/main/java/de/ctdo/bunti/web/RoomsController.java new file mode 100644 index 0000000..dcd4c00 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/web/RoomsController.java @@ -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 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 getDevicesFromRoom(@PathVariable("id") int id) { + Room room = roomsDAO.getRoom(id); + + if(room != null) { + return room.getDevices(); + } + + return null; + } + +} diff --git a/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java b/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java index 55a4b84..11635a6 100644 --- a/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java +++ b/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java @@ -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 als Parameter im Controller zu verarbeiten. + */ public class DeviceUpdates { - private long timeStamp = 0; - private List updates = new ArrayList(); - public List getUpdates() { return updates; } diff --git a/src/main/resources/META-INF/spring/hibernate-beans.xml b/src/main/resources/META-INF/spring/hibernate-beans.xml index 84e0dac..ccc9010 100755 --- a/src/main/resources/META-INF/spring/hibernate-beans.xml +++ b/src/main/resources/META-INF/spring/hibernate-beans.xml @@ -1,44 +1,43 @@ - + 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/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd" + xmlns:jdbc="http://www.springframework.org/schema/jdbc"> - - + + + - - - - /bunti.hbm.xml - - + + - - org.hibernate.dialect.HSQLDialect - + org.hibernate.dialect.HSQLDialect true - + - + - - - + + + + + + + + + - + + diff --git a/src/main/resources/bunti.hbm.xml b/src/main/resources/bunti.hbm.xml deleted file mode 100755 index 5fedde1..0000000 --- a/src/main/resources/bunti.hbm.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index e52abc7..7a44d51 100755 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -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 diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql deleted file mode 100755 index 00e6dc0..0000000 --- a/src/main/resources/init.sql +++ /dev/null @@ -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) - - - diff --git a/src/main/resources/init_data.sql b/src/main/resources/init_data.sql new file mode 100755 index 0000000..0b1197e --- /dev/null +++ b/src/main/resources/init_data.sql @@ -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); + + + diff --git a/src/main/resources/init_schema.sql b/src/main/resources/init_schema.sql new file mode 100755 index 0000000..72ae1bc --- /dev/null +++ b/src/main/resources/init_schema.sql @@ -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; + + + + + + diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties deleted file mode 100644 index 256221f..0000000 --- a/src/main/resources/log4j.properties +++ /dev/null @@ -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 diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml index 2494fe4..85d124a 100644 --- a/src/main/resources/log4j.xml +++ b/src/main/resources/log4j.xml @@ -15,18 +15,18 @@ - - - - + + + + - + diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index 3e109d2..18a6402 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -12,6 +12,7 @@ " rel="stylesheet" /> + @@ -26,45 +27,8 @@

CTDO Raumsteuerung

- -
- -
-
-
-
- -
-
- -
-
-
-
-
-
- - - - -
- -
-
- -
- Raumlicht:
- An Aus -
+
+
@@ -80,6 +44,20 @@
{{/each}} + + diff --git a/src/main/webapp/WEB-INF/jsp/index2.jsp b/src/main/webapp/WEB-INF/jsp/index2.jsp new file mode 100644 index 0000000..9740e38 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/index2.jsp @@ -0,0 +1,77 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + +<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + WebSockets + + " rel="stylesheet"/> + " rel="stylesheet"/> + + + + + + +

CTDO Raumsteuerung

+ +

Par56:
+ + + +

+

Lampel:
+ + + + + + +

+ + + diff --git a/src/main/webapp/resources/js/events.class.js b/src/main/webapp/resources/js/events.class.js new file mode 100644 index 0000000..6801ccf --- /dev/null +++ b/src/main/webapp/resources/js/events.class.js @@ -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; + } + } + } + } +}; \ No newline at end of file diff --git a/src/main/webapp/resources/js/main.js b/src/main/webapp/resources/js/main.js index 497b13f..31c9ec8 100644 --- a/src/main/webapp/resources/js/main.js +++ b/src/main/webapp/resources/js/main.js @@ -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() { diff --git a/src/main/webapp/resources/js/models.js b/src/main/webapp/resources/js/models.js index 8ac1861..0ac0d47 100644 --- a/src/main/webapp/resources/js/models.js +++ b/src/main/webapp/resources/js/models.js @@ -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); \ No newline at end of file diff --git a/src/main/webapp/resources/js/views.js b/src/main/webapp/resources/js/views.js index d0fac59..0b4d9b7 100644 --- a/src/main/webapp/resources/js/views.js +++ b/src/main/webapp/resources/js/views.js @@ -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; } }); diff --git a/src/main/webapp/resources/json/room0.json b/src/main/webapp/resources/json/room0.json new file mode 100644 index 0000000..b9911b0 --- /dev/null +++ b/src/main/webapp/resources/json/room0.json @@ -0,0 +1,11 @@ +[ + { + "type":"Buzzer", + "deviceId":0, + "deviceName":"Buzzer", + "picture":null, + "options": { + "state":0 + } + } +] \ No newline at end of file diff --git a/src/main/webapp/resources/json/room1.json b/src/main/webapp/resources/json/room1.json new file mode 100644 index 0000000..7f52483 --- /dev/null +++ b/src/main/webapp/resources/json/room1.json @@ -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 + } + }, +] \ No newline at end of file diff --git a/src/test/java/de/ctdo/bunti/control/BuntiControllerImplTest.java b/src/test/java/de/ctdo/bunti/control/BuntiControllerImplTest.java new file mode 100644 index 0000000..a474047 --- /dev/null +++ b/src/test/java/de/ctdo/bunti/control/BuntiControllerImplTest.java @@ -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 { +// +// } +//} diff --git a/src/test/java/de/ctdo/bunti/control/BuntiControllerTest.java b/src/test/java/de/ctdo/bunti/control/BuntiControllerTest.java deleted file mode 100644 index 46d34ce..0000000 --- a/src/test/java/de/ctdo/bunti/control/BuntiControllerTest.java +++ /dev/null @@ -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 options = new HashMap(); -// options.put("optionA", "valueA"); -// options.put("optionB", 42); -// assertTrue(dut.updateDeviceData(12, options)); -// } - -} diff --git a/src/test/java/de/ctdo/bunti/dao/BuntiDevicesDAOImplTest.java b/src/test/java/de/ctdo/bunti/dao/BuntiDevicesDAOImplTest.java new file mode 100644 index 0000000..f926a49 --- /dev/null +++ b/src/test/java/de/ctdo/bunti/dao/BuntiDevicesDAOImplTest.java @@ -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 deviceList = dut.getAllDMXDevices(); + assertEquals(4, deviceList.size()); + } + + @Test + public void testGetAllDevices() throws Exception { + List deviceList = dut.getAllDevices(); + assertEquals(4, deviceList.size()); + } + + @Test + public void testGetDeviceById() throws Exception { + BuntiDevice device = dut.getDeviceById(2); + + assertEquals("Lampe2", device.getDeviceName()); + + } +} diff --git a/src/test/java/de/ctdo/bunti/dao/RoomsDAOImplTest.java b/src/test/java/de/ctdo/bunti/dao/RoomsDAOImplTest.java new file mode 100644 index 0000000..881057c --- /dev/null +++ b/src/test/java/de/ctdo/bunti/dao/RoomsDAOImplTest.java @@ -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)); + } +} diff --git a/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java b/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java index df71b7f..6bb8375 100644 --- a/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java +++ b/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java @@ -1,5 +1,6 @@ package de.ctdo.bunti.dmx; +import de.ctdo.bunti.dmx.model.DMXChannel; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java b/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java index cbc6922..d24c8b8 100644 --- a/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java +++ b/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java @@ -1,5 +1,6 @@ package de.ctdo.bunti.dmx; +import de.ctdo.bunti.dmx.model.DMXChannel; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java b/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java index 50bc1ef..6d9b321 100644 --- a/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java +++ b/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java @@ -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 options = new HashMap(); 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 options = new HashMap(); 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 options = new HashMap(); options.put("rednonexistent", 44); assertFalse(dut.updateDevice(device, options)); diff --git a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java index c3583f9..8e69918 100644 --- a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java +++ b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java @@ -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 diff --git a/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java index fb1b664..5c304c3 100644 --- a/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java +++ b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java @@ -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 diff --git a/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java b/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java index 91f2264..433556b 100644 --- a/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java +++ b/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java @@ -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 diff --git a/src/test/resources/de/ctdo/bunti/hibernate-test-context.xml b/src/test/resources/de/ctdo/bunti/hibernate-test-context.xml new file mode 100644 index 0000000..3def185 --- /dev/null +++ b/src/test/resources/de/ctdo/bunti/hibernate-test-context.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + org.hibernate.dialect.HSQLDialect + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file