|
From: <gca...@us...> - 2011-12-02 15:39:08
|
Revision: 3729
http://openutils.svn.sourceforge.net/openutils/?rev=3729&view=rev
Author: gcatania
Date: 2011-12-02 15:39:01 +0000 (Fri, 02 Dec 2011)
Log Message:
-----------
BSHD-2 more unit tests
Modified Paths:
--------------
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java
trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml
Added Paths:
-----------
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java
Modified: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java 2011-12-02 15:18:01 UTC (rev 3728)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java 2011-12-02 15:39:01 UTC (rev 3729)
@@ -28,6 +28,7 @@
import it.openutils.hibernate.test.dao.CarDAO;
import it.openutils.hibernate.test.dao.CarMakerDAO;
import it.openutils.hibernate.test.dao.PersonDAO;
+import it.openutils.hibernate.test.dao.StickerDAO;
import it.openutils.hibernate.test.model.Address;
import it.openutils.hibernate.test.model.Car;
import it.openutils.hibernate.test.model.CarMaker;
@@ -37,8 +38,10 @@
import it.openutils.hibernate.test.model.FullName;
import it.openutils.hibernate.test.model.Owner;
import it.openutils.hibernate.test.model.Person;
+import it.openutils.hibernate.test.model.Sticker;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
@@ -73,6 +76,9 @@
@Autowired
private CarDAO carDAO;
+ @Autowired
+ private StickerDAO stickerDAO;
+
private static Person alice()
{
FullName fullName = new FullName("Alice", "McBeal");
@@ -165,7 +171,7 @@
return p;
}
- private Car bobsPrius(Owner bob, CarModel prius)
+ private static Car bobsPrius(Owner bob, CarModel prius)
{
Car bobsPrius = new Car();
bobsPrius.setModel(prius);
@@ -176,7 +182,7 @@
return bobsPrius;
}
- private Car chucksPrius(Owner chuck, CarModel prius)
+ private static Car chucksPrius(Owner chuck, CarModel prius)
{
Car chucksPrius = new Car();
chucksPrius.setModel(prius);
@@ -387,6 +393,32 @@
Assert.assertEquals(shouldBeBob.getName(), bob.getName());
}
+ @Test
+ public void testFindFilteredChildEntity()
+ {
+ Sticker st1 = new Sticker();
+ st1.setName("Warning! Baby on board!");
+ st1.setHeight(20d);
+ st1.setWidth(10d);
+ Sticker st2 = new Sticker();
+ st2.setName("Object in the mirror are losing");
+ st2.setHeight(5d);
+ st2.setWidth(10d);
+ Sticker st3 = new Sticker();
+ st3.setName("(tribal tattoo sticker)");
+ st3.setHeight(35d);
+ st3.setWidth(18d);
+
+ Car chucksPrius = chucksPrius(chuck(), prius(toyota()));
+ chucksPrius.setStickers(Arrays.asList(st1, st2, st3));
+ carDAO.save(chucksPrius);
+ carDAO.evict(chucksPrius);
+ Sticker filter = new Sticker();
+ filter.setWidth(10d);
+ List<Sticker> found = stickerDAO.findFiltered(filter);
+ Assert.assertEquals(found.size(), 2);
+ }
+
// @Test
// public void testExampleAssociations()
// {
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java 2011-12-02 15:39:01 UTC (rev 3729)
@@ -0,0 +1,55 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.dao;
+
+import it.openutils.dao.hibernate.HibernateDAO;
+import it.openutils.dao.hibernate.HibernateDAOImpl;
+import it.openutils.hibernate.test.model.Sticker;
+
+import org.hibernate.SessionFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Repository;
+
+
+/**
+ * @author gcatania
+ */
+public interface StickerDAO extends HibernateDAO<Sticker, Long>
+{
+
+ @Repository("stickerDAO")
+ class StickerDAOImpl extends HibernateDAOImpl<Sticker, Long> implements StickerDAO
+ {
+
+ @Autowired
+ public StickerDAOImpl(SessionFactory factory)
+ {
+ super(Sticker.class);
+ setSessionFactory(factory);
+ }
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java 2011-12-02 15:18:01 UTC (rev 3728)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java 2011-12-02 15:39:01 UTC (rev 3729)
@@ -26,6 +26,7 @@
package it.openutils.hibernate.test.model;
import java.util.Calendar;
+import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@@ -34,6 +35,7 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
/**
@@ -59,6 +61,9 @@
@Column
private CurrencyAmount marketValue;
+ @OneToMany(cascade = CascadeType.ALL)
+ private List<Sticker> stickers;
+
/**
* @return the id
*/
@@ -140,6 +145,22 @@
}
/**
+ * @return the stickers
+ */
+ public List<Sticker> getStickers()
+ {
+ return stickers;
+ }
+
+ /**
+ * @param stickers the stickers to set
+ */
+ public void setStickers(List<Sticker> stickers)
+ {
+ this.stickers = stickers;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -149,9 +170,8 @@
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((marketValue == null) ? 0 : marketValue.hashCode());
- result = prime * result + ((model == null) ? 0 : model.hashCode());
- result = prime * result + ((owner == null) ? 0 : owner.hashCode());
result = prime * result + ((registrationDate == null) ? 0 : registrationDate.hashCode());
+ result = prime * result + ((stickers == null) ? 0 : stickers.hashCode());
return result;
}
@@ -196,39 +216,28 @@
{
return false;
}
- if (model == null)
+ if (registrationDate == null)
{
- if (other.model != null)
+ if (other.registrationDate != null)
{
return false;
}
}
- else if (!model.equals(other.model))
+ else if (!registrationDate.equals(other.registrationDate))
{
return false;
}
- if (owner == null)
+ if (stickers == null)
{
- if (other.owner != null)
+ if (other.stickers != null)
{
return false;
}
}
- else if (!owner.equals(other.owner))
+ else if (!stickers.equals(other.stickers))
{
return false;
}
- if (registrationDate == null)
- {
- if (other.registrationDate != null)
- {
- return false;
- }
- }
- else if (!registrationDate.equals(other.registrationDate))
- {
- return false;
- }
return true;
}
@@ -242,14 +251,12 @@
builder
.append("Car [id=")
.append(id)
- .append(", model=")
- .append(model)
- .append(", owner=")
- .append(owner)
.append(", registrationDate=")
.append(registrationDate)
.append(", marketValue=")
.append(marketValue)
+ .append(", stickers=")
+ .append(stickers)
.append("]");
return builder.toString();
}
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java 2011-12-02 15:39:01 UTC (rev 3729)
@@ -0,0 +1,219 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+
+/**
+ * @author gcatania
+ */
+@Entity
+public class Sticker
+{
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column
+ private String name;
+
+ @Column
+ private Double height;
+
+ @Column
+ private Double width;
+
+ /**
+ * @return the id
+ */
+ public Long getId()
+ {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * @return the height
+ */
+ public Double getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * @param height the height to set
+ */
+ public void setHeight(Double height)
+ {
+ this.height = height;
+ }
+
+ /**
+ * @return the width
+ */
+ public Double getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * @param width the width to set
+ */
+ public void setWidth(Double width)
+ {
+ this.width = width;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((height == null) ? 0 : height.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((width == null) ? 0 : width.hashCode());
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof Sticker))
+ {
+ return false;
+ }
+ Sticker other = (Sticker) obj;
+ if (height == null)
+ {
+ if (other.height != null)
+ {
+ return false;
+ }
+ }
+ else if (!height.equals(other.height))
+ {
+ return false;
+ }
+ if (id == null)
+ {
+ if (other.id != null)
+ {
+ return false;
+ }
+ }
+ else if (!id.equals(other.id))
+ {
+ return false;
+ }
+ if (name == null)
+ {
+ if (other.name != null)
+ {
+ return false;
+ }
+ }
+ else if (!name.equals(other.name))
+ {
+ return false;
+ }
+ if (width == null)
+ {
+ if (other.width != null)
+ {
+ return false;
+ }
+ }
+ else if (!width.equals(other.width))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder
+ .append("Sticker [id=")
+ .append(id)
+ .append(", name=")
+ .append(name)
+ .append(", height=")
+ .append(height)
+ .append(", width=")
+ .append(width)
+ .append("]");
+ return builder.toString();
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml
===================================================================
--- trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-12-02 15:18:01 UTC (rev 3728)
+++ trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-12-02 15:39:01 UTC (rev 3729)
@@ -12,5 +12,6 @@
<mapping class="it.openutils.hibernate.test.model.FullName" />
<mapping class="it.openutils.hibernate.test.model.Owner" />
<mapping class="it.openutils.hibernate.test.model.Person" />
+ <mapping class="it.openutils.hibernate.test.model.Sticker" />
</session-factory>
</hibernate-configuration>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|