package edu.duke.cabig.c3pr.xml;

import static edu.duke.cabig.c3pr.C3PRUseCase.EXPORT_STUDY;
import static edu.duke.cabig.c3pr.C3PRUseCase.IMPORT_STUDY;

import java.io.InputStream;
import java.io.StringReader;

import edu.duke.cabig.c3pr.C3PRUseCases;
import edu.duke.cabig.c3pr.dao.StudyDao;
import edu.duke.cabig.c3pr.domain.Study;
import edu.duke.cabig.c3pr.domain.repository.impl.StudyRepositoryImpl;
import edu.duke.cabig.c3pr.service.StudyXMLImporterService;
import edu.duke.cabig.c3pr.utils.MasqueradingDaoTestCase;
import gov.nih.nci.cagrid.common.Utils;

/**
 * Created by IntelliJ IDEA. User: kherm Date: Dec 3, 2007 Time: 9:18:10 AM To change this template
 * use File | Settings | File Templates.
 */
@C3PRUseCases( { IMPORT_STUDY, EXPORT_STUDY })
public class StudyDeserializationFromFileTest extends MasqueradingDaoTestCase<StudyDao> {
    XmlMarshaller marshaller;

    StudyDao dao;
    private StudyRepositoryImpl studyRepositoryImpl;
    

    StudyXMLImporterService importService;

    protected void setUp() throws Exception {
        super.setUp(); // To change body of overridden methods use File | Settings | File
                        // Templates.
        marshaller = (XmlMarshaller) getApplicationContext().getBean("xmlUtility");
        importService = (StudyXMLImporterService) getApplicationContext().getBean(
                        "studyXMLImporterService");

    }

    public void testStudyImport() throws Exception {
        InputStream studyXMLin = getClass().getResourceAsStream("SampleStudy.xml");
        StringBuffer buf = Utils.inputStreamToStringBuffer(studyXMLin);
        Study study = (Study) marshaller.fromXML(new StringReader(buf.toString()));
        studyRepositoryImpl.buildAndSave(study);

    }

    /**
     * What dao class is the test trying to Masquerade
     * 
     * @return
     */
    public Class getMasqueradingDaoClassName() {
        return StudyDao.class;
    }

	public StudyRepositoryImpl getStudyRepositoryImpl() {
		return studyRepositoryImpl;
	}

	public void setStudyRepositoryImpl(StudyRepositoryImpl studyRepositoryImpl) {
		this.studyRepositoryImpl = studyRepositoryImpl;
	}

}

@@ -378,13 +378,8 @@
 ory.
-impl.
 Stud
@@ -389,20 +389,16 @@
 pository
-Impl
 ;%0Aimport
@@ -904,36 +904,32 @@
  StudyRepository
-Impl
  studyRepository
@@ -928,20 +928,16 @@
 pository
-Impl
 ;%0A    %0A%0A
@@ -1373,16 +1373,111 @@
 vice%22);%0A
+        studyRepository = (StudyRepository) getApplicationContext().getBean(%22studyRepository%22);
 %0A    %7D%0A%0A
@@ -1792,20 +1792,16 @@
 pository
-Impl
 .buildAn
@@ -2026,20 +2026,16 @@
 pository
-Impl
  getStud
@@ -2074,28 +2074,24 @@
 dyRepository
-Impl
 ;%0A%09%7D%0A%0A%09publi
@@ -2115,20 +2115,16 @@
 pository
-Impl
 (StudyRe
@@ -2131,20 +2131,16 @@
 pository
-Impl
  studyRe
@@ -2147,20 +2147,16 @@
 pository
-Impl
 ) %7B%0A%09%09th
@@ -2173,20 +2173,16 @@
 pository
-Impl
  = study
@@ -2191,20 +2191,16 @@
 pository
-Impl
 ;%0A%09%7D%0A%0A%7D%0A

test case fix