/*
 * The Gemma project
 * 
 * Copyright (c) 2010 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package ubic.gemma.model.expression;

import static org.junit.Assert.*;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import ubic.gemma.model.expression.experiment.ExpressionExperiment;
import ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet;
import ubic.gemma.model.expression.experiment.ExpressionExperimentSubSetDao;
import ubic.gemma.testing.BaseSpringContextTest;

/**
 * @author paul
 * @version $Id$
 */
public class ExpressionExperimentSubSetDaoImplTest extends BaseSpringContextTest {

    @Autowired
    private ExpressionExperimentSubSetDao expressionExperimentSubSetDao;

    @Autowired
    SessionFactory sessionFactory;
    
    @Test
    public final void testFind() throws Exception {

        ExpressionExperiment ee = super.testHelper.getTestPersistentBasicExpressionExperiment();

        ExpressionExperimentSubSet subset = ExpressionExperimentSubSet.Factory.newInstance();

        subset.setSourceExperiment( ee );
        subset.getBioAssays().addAll( ee.getBioAssays() );
        subset.setName( "foo" );

        Session session = sessionFactory.openSession();
        ExpressionExperimentSubSet persisted = expressionExperimentSubSetDao.create( subset );
        //session.update( persisted );

        assertNotNull( persisted );
        session.close();
                

        session = sessionFactory.openSession();
        ExpressionExperimentSubSet hit = expressionExperimentSubSetDao.find( subset );
        //session.update( hit );

        assertNotNull( hit );
        assertEquals( persisted, hit );
        session.close();

    }

}

@@ -733,45 +733,8 @@
 on;%0A
-import org.hibernate.SessionFactory;%0A
 impo
@@ -1337,63 +1337,8 @@
 o;%0A%0A
-    @Autowired%0A    SessionFactory sessionFactory;%0A    %0A
     
@@ -1719,24 +1719,32 @@
 e( %22foo%22 );%0A
+        
 %0A        Ses
@@ -1750,33 +1750,81 @@
 ssion session = 
-s
+this.hibernateSupport.getHibernateTemplate().getS
 essionFactory.op
@@ -1812,32 +1812,34 @@
 etSessionFactory
+()
 .openSession();%0A
@@ -1830,32 +1830,85 @@
 .openSession();%0A
+        Transaction tx = session.beginTransaction();%0A
         Expressi
@@ -1998,36 +1998,18 @@
     
-//session.update( persisted 
+tx.commit(
 );%0A%0A
@@ -2048,33 +2048,8 @@
  );%0A
-        session.close();%0A
     
@@ -2061,25 +2061,24 @@
        %0A
-%0A
         
 session 
@@ -2069,23 +2069,18 @@
         
-session
+tx
  = sessi
@@ -2085,24 +2085,22 @@
 sion
-Factory.openSess
+.beginTransact
 ion(
@@ -2201,64 +2201,22 @@
     
-//session.update( hit );%0A%0A        assertNotNull( hit 
+tx.commit(
 );%0A
+%0A
     
@@ -2254,33 +2254,8 @@
 t );
-%0A        session.close();
 %0A%0A  

Rollback failed test fix