From: <gca...@us...> - 2013-03-11 15:03:22
|
Revision: 4195 http://openutils.svn.sourceforge.net/openutils/?rev=4195&view=rev Author: gcatania Date: 2013-03-11 15:03:14 +0000 (Mon, 11 Mar 2013) Log Message: ----------- BSHD-19 failing tests added (currently disabled) Modified Paths: -------------- trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml Added Paths: ----------- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.java trunk/openutils-bshd5/src/test/resources/preload-data.sql Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,147 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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; + +import it.openutils.hibernate.test.dao.BarDAO; +import it.openutils.hibernate.test.dao.FooDAO; +import it.openutils.hibernate.test.model.Bar; +import it.openutils.hibernate.test.model.Foo; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +/** + * @author gcatania + */ +@ContextConfiguration(locations = "/spring-tests.xml") +public class HibernateDAOLazyLoadTest extends AbstractTransactionalTestNGSpringContextTests +{ + + @Autowired + private FooDAO fooDAO; + + @Autowired + private BarDAO barDAO; + + @BeforeClass + protected final void preloadData() + { + executeSqlScript("/preload-data.sql", false); + } + + private List<Foo> findFoo(String s, Bar bar) + { + Foo filter = new Foo(); + filter.setBar(bar); + filter.setS(s); + List<Foo> found = fooDAO.findFiltered(filter); + return found; + } + + private void testFind(long barId, String fooStr, Bar bar) + { + List<Foo> found = findFoo(fooStr, bar); + Assert.assertEquals(found.size(), 1); + Foo foo = found.get(0); + Assert.assertEquals(foo.getS(), fooStr); + Assert.assertEquals(foo.getBar().getId().longValue(), barId); + } + + private void testDontFind(String fooStr, Bar bar) + { + List<Foo> found = findFoo(fooStr, bar); + Assert.assertEquals(found.size(), 0); + } + + private void testFindEager(long barId, String fooStr) + { + Bar bar = barDAO.get(barId); + testFind(barId, fooStr, bar); + } + + private void testFindLazy(long barId, String fooStr) + { + Bar bar = barDAO.load(barId); + testFind(barId, fooStr, bar); + } + + @Test + public void testFindWithEagerParent1() + { + testFindEager(1L, "foo1_2"); + } + + @Test + public void testFindWithEagerParent2() + { + testFindEager(1L, "fooX_X"); + } + + @Test + public void testFindWithLazyParent1() + { + testFindLazy(1L, "foo1_2"); + } + + /** + * FIXME enable this test and fix BSHD-19 + */ + @Test(enabled = false) + public void testFindWithLazyParent2() + { + testFindLazy(1L, "fooX_X"); + } + + @Test + public void testDontFindWithEagerParent() + { + long barId = 1L; + String fooStr = "foo2_2"; + + Bar bar1 = barDAO.get(barId); + testDontFind(fooStr, bar1); + } + + /** + * FIXME enable this test and fix BSHD-19 + */ + @Test(enabled = false) + public void testDontFindWithLazyParent() + { + long barId = 1L; + String fooStr = "foo2_2"; + + Bar bar1 = barDAO.load(barId); + testDontFind(fooStr, bar1); + } +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,55 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.Bar; + +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + + +/** + * @author gcatania + */ +public interface BarDAO extends HibernateDAO<Bar, Long> +{ + + @Repository("barDAO") + class PersonDAOImpl extends HibernateDAOImpl<Bar, Long> implements BarDAO + { + + @Autowired + public PersonDAOImpl(SessionFactory factory) + { + super(Bar.class); + setSessionFactory(factory); + } + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,55 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.Foo; + +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + + +/** + * @author gcatania + */ +public interface FooDAO extends HibernateDAO<Foo, Long> +{ + + @Repository("fooDAO") + class PersonDAOImpl extends HibernateDAOImpl<Foo, Long> implements FooDAO + { + + @Autowired + public PersonDAOImpl(SessionFactory factory) + { + super(Foo.class); + setSessionFactory(factory); + } + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,80 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + + +/** + * @author gcatania + * @version $Id$ + */ +@Entity +public class Bar implements Cloneable +{ + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String s; + + /** + * @return the id + */ + public Long getId() + { + return id; + } + + /** + * @param id the id to set + */ + public void setId(Long id) + { + this.id = id; + } + + /** + * @return the s + */ + public String getS() + { + return s; + } + + /** + * @param s the s to set + */ + public void setS(String s) + { + this.s = s; + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,102 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + + +/** + * @author gcatania + * @version $Id$ + */ +@Entity +public class Foo implements Cloneable +{ + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @ManyToOne + private Bar bar; + + @Column + private String s; + + /** + * @return the id + */ + public Long getId() + { + return id; + } + + /** + * @param id the id to set + */ + public void setId(Long id) + { + this.id = id; + } + + /** + * @return the bar + */ + public Bar getBar() + { + return bar; + } + + /** + * @param bar the bar to set + */ + public void setBar(Bar bar) + { + this.bar = bar; + } + + /** + * @return the s + */ + public String getS() + { + return s; + } + + /** + * @param s the s to set + */ + public void setS(String s) + { + this.s = s; + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.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 2013-02-14 16:17:10 UTC (rev 4194) +++ trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2013-03-11 15:03:14 UTC (rev 4195) @@ -13,5 +13,8 @@ <mapping class="it.openutils.hibernate.test.model.Owner" /> <mapping class="it.openutils.hibernate.test.model.Person" /> <mapping class="it.openutils.hibernate.test.model.Sticker" /> + + <mapping class="it.openutils.hibernate.test.model.Foo" /> + <mapping class="it.openutils.hibernate.test.model.Bar" /> </session-factory> </hibernate-configuration> \ No newline at end of file Added: trunk/openutils-bshd5/src/test/resources/preload-data.sql =================================================================== --- trunk/openutils-bshd5/src/test/resources/preload-data.sql (rev 0) +++ trunk/openutils-bshd5/src/test/resources/preload-data.sql 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,17 @@ +insert into bar (id, s) +values (1, 'bar1'); +insert into bar (id, s) +values (2, 'bar2'); + +insert into foo (id, bar_id, s) +values ( 1, 1, 'foo1_1' ); +insert into foo (id, bar_id, s) +values ( 2, 1, 'foo1_2' ); +insert into foo (id, bar_id, s) +values ( 3, 1, 'fooX_X' ); +insert into foo (id, bar_id, s) +values ( 4, 2, 'foo2_1' ); +insert into foo (id, bar_id, s) +values ( 5, 2, 'foo2_2' ); +insert into foo (id, bar_id, s) +values ( 6, 2, 'fooX_X' ); \ No newline at end of file Property changes on: trunk/openutils-bshd5/src/test/resources/preload-data.sql ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |