[hibernate-commits] Hibernate SVN: r20250 - in search/trunk/hibernate-search/src/test/java/org/hibernate/search/test: embedded/nested/containedIn and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Aug 24 12:09:08 EDT 2010


Author: hardy.ferentschik
Date: 2010-08-24 12:09:07 -0400 (Tue, 24 Aug 2010)
New Revision: 20250

Modified:
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java
Log:
HSEARCH-585 Made the tests work against Postgres which needs a transaction

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java	2010-08-24 15:45:32 UTC (rev 20249)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java	2010-08-24 16:09:07 UTC (rev 20250)
@@ -1,6 +1,33 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program 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 distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
+ */
+
 package org.hibernate.search.test.bridge;
 
+import java.util.List;
+
 import org.apache.lucene.queryParser.QueryParser;
+
 import org.hibernate.Session;
 import org.hibernate.Transaction;
 import org.hibernate.search.FullTextQuery;
@@ -8,67 +35,67 @@
 import org.hibernate.search.Search;
 import org.hibernate.search.test.SearchTestCase;
 
-import java.util.List;
-
 /**
  * @author Emmanuel Bernard
  */
-public class ClassBridgeAndProjectionTest  extends SearchTestCase {
+public class ClassBridgeAndProjectionTest extends SearchTestCase {
 
-    public void testClassBridgeProjection() throws Exception {
-        Session s = openSession();
-        Transaction tx = s.beginTransaction();
+	public void testClassBridgeProjection() throws Exception {
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
 
-        // create entities
-        Teacher teacher = new Teacher();
-        teacher.setName("John Smith");
-        s.persist(teacher);
+		// create entities
+		Teacher teacher = new Teacher();
+		teacher.setName( "John Smith" );
+		s.persist( teacher );
 
-        Student student1 = new Student();
-        student1.setGrade("foo");
-        student1.setName("Jack Miller");
-        student1.setTeacher(teacher);
-        teacher.getStudents().add(student1);
-        s.persist(student1);
+		Student student1 = new Student();
+		student1.setGrade( "foo" );
+		student1.setName( "Jack Miller" );
+		student1.setTeacher( teacher );
+		teacher.getStudents().add( student1 );
+		s.persist( student1 );
 
-        Student student2 = new Student();
-        student2.setGrade("bar");
-        student2.setName("Steve Marshall");
-        student2.setTeacher(teacher);
-        teacher.getStudents().add(student2);
-        s.persist(student2);
+		Student student2 = new Student();
+		student2.setGrade( "bar" );
+		student2.setName( "Steve Marshall" );
+		student2.setTeacher( teacher );
+		teacher.getStudents().add( student2 );
+		s.persist( student2 );
 
-        tx.commit();
+		tx.commit();
 
-        // test query without projection
-        FullTextSession ftSession = Search.getFullTextSession( s );
-        QueryParser parser = new QueryParser(
-        		getTargetLuceneVersion(),
-                "name", 
-                standardAnalyzer );
-        FullTextQuery query = ftSession.createFullTextQuery(parser.parse("name:John"), Teacher.class);
-        List results = query.list();
-        assertNotNull(results);
-        assertTrue(results.size() == 1);
-        assertTrue(((Teacher) results.get(0)).getStudents().size() == 2);
+		tx = s.beginTransaction();
+		// test query without projection
+		FullTextSession ftSession = Search.getFullTextSession( s );
+		QueryParser parser = new QueryParser(
+				getTargetLuceneVersion(),
+				"name",
+				standardAnalyzer
+		);
+		FullTextQuery query = ftSession.createFullTextQuery( parser.parse( "name:John" ), Teacher.class );
+		List results = query.list();
+		assertNotNull( results );
+		assertTrue( results.size() == 1 );
+		assertTrue( ( ( Teacher ) results.get( 0 ) ).getStudents().size() == 2 );
 
-        // now test with projection
-        query.setProjection("amount_of_students");
-        results = query.list();
-        assertNotNull(results);
-        assertTrue(results.size() == 1);
-        Object[] firstResult = (Object[]) results.get(0);
-        Integer amountStudents = (Integer) firstResult[0];
-        assertEquals(new Integer(2), amountStudents);
+		// now test with projection
+		query.setProjection( "amount_of_students" );
+		results = query.list();
+		assertNotNull( results );
+		assertTrue( results.size() == 1 );
+		Object[] firstResult = ( Object[] ) results.get( 0 );
+		Integer amountStudents = ( Integer ) firstResult[0];
+		assertEquals( new Integer( 2 ), amountStudents );
+		tx.commit();
+		s.close();
+	}
 
-        s.close();
-    }
-
-    @Override
-    protected Class<?>[] getAnnotatedClasses() {
-        return new Class<?>[] {
-                Student.class,
-                Teacher.class
-        };
-    }
+	@Override
+	protected Class<?>[] getAnnotatedClasses() {
+		return new Class<?>[] {
+				Student.class,
+				Teacher.class
+		};
+	}
 }

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java	2010-08-24 15:45:32 UTC (rev 20249)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java	2010-08-24 16:09:07 UTC (rev 20250)
@@ -1,3 +1,27 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program 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 distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
+ */
+
 package org.hibernate.search.test.embedded.nested.containedIn;
 
 import org.apache.lucene.index.Term;
@@ -16,26 +40,25 @@
 public class NestedContainedInTest extends SearchTestCase {
 
 	public void testAddHelpItem() {
+		openSession();
 		String tagName = "animal";
 		createHelpItem( tagName );
-		openSession(  );
 		doQuery( tagName );
 		session.close();
 	}
 
 	public void testChangeTagName() {
-
+		openSession();
 		String tagName = "animal";
 		createHelpItem( tagName );
 
-		openSession(  );
 		HelpItem check = doQuery( tagName );
-
 		Tag tag = check.getTags().get( 0 ).getTag();
 
-		Transaction tx = session.beginTransaction();
 		String newTagName = "automobile";
 		tag.setName( newTagName );
+
+		Transaction tx = session.beginTransaction();
 		session.saveOrUpdate( tag );
 		tx.commit();
 
@@ -44,7 +67,6 @@
 	}
 
 	private void createHelpItem(String tagName) {
-		openSession(  );
 		Transaction tx = session.beginTransaction();
 		HelpItem helpItem = new HelpItem();
 		helpItem.setTitle( "The quick brown fox jumps over the lazy dog." );
@@ -64,10 +86,10 @@
 		session.save( helpItemTag );
 
 		tx.commit();
-		session.close();
 	}
 
 	private HelpItem doQuery(String tagName) {
+		Transaction tx = session.beginTransaction();
 		FullTextSession fullTextSession = Search.getFullTextSession( session );
 		Query termQuery = new TermQuery( new Term( "tags.tag.name", tagName ) );
 		FullTextQuery fullTextQuery =
@@ -75,6 +97,7 @@
 		HelpItem check = ( HelpItem ) fullTextQuery.uniqueResult();
 		assertNotNull( "No HelpItem with Tag '" + tagName + "' found in Lucene index.", check );
 		assertTrue( check.getTags().get( 0 ).getTag().getName().equals( tagName ) );
+		tx.commit();
 		return check;
 	}
 



More information about the hibernate-commits mailing list