/*
 * 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.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 {

        Session session = sessionFactory.openSession();
        ExpressionExperiment ee = super.testHelper.getTestPersistentBasicExpressionExperiment();
        session.update(ee);
        session.close();

        session = sessionFactory.openSession();
        ExpressionExperimentSubSet subset = ExpressionExperimentSubSet.Factory.newInstance();

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


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

        session.update(persisted);
        
        assertNotNull( persisted );
        session.close();
        

        session = sessionFactory.openSession();    
        ExpressionExperimentSubSet hit = expressionExperimentSubSetDao.find( persisted );

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

    }

}

@@ -703,75 +703,8 @@
 *;%0A%0A
-import org.hibernate.Session;%0Aimport org.hibernate.SessionFactory;%0A
 impo
@@ -1273,59 +1273,8 @@
 o;%0A%0A
-    @Autowired%0A    SessionFactory sessionFactory;%0A%0A
     
@@ -1336,64 +1336,8 @@
  %7B%0A%0A
-        Session session = sessionFactory.openSession();%0A
     
@@ -1433,109 +1433,8 @@
 ();%0A
-        session.update(ee);%0A        session.close();%0A%0A        session = sessionFactory.openSession();
 %0A   
@@ -1663,385 +1663,140 @@
  );%0A
-        session.update(subset);%0A        session.close();%0A%0A%0A        session = sessionFactory.openSession();        %0A        ExpressionExperimentSubSet persisted = expressionExperimentSubSetDao.create( subset );%0A%0A        session.update(persisted);%0A        %0A        assertNotNull( persisted );%0A        session.close();%0A        %0A%0A        session = sessionFactory.openSession();    
+%0A        ExpressionExperimentSubSet persisted = expressionExperimentSubSetDao.create( subset );%0A%0A        assertNotNull( persisted );
 %0A   
@@ -1887,81 +1887,8 @@
 );%0A%0A
-        session.update(hit);%0A        session.update(persisted);%0A        %0A
     
@@ -1926,33 +1926,8 @@
 t );
-%0A        session.close();
 %0A%0A  

fix test