<commit_before>package edu.columbia.gemma.web.controller.flow.action.entrez.pubmed;

import junit.framework.TestCase;

import org.easymock.MockControl;
import org.springframework.mock.web.flow.MockRequestContext;
import org.springframework.test.JUnitAssertSupport;
import org.springframework.web.flow.Event;

import edu.columbia.gemma.common.description.BibliographicReferenceImpl;
import edu.columbia.gemma.common.description.BibliographicReferenceService;
import edu.columbia.gemma.web.controller.flow.action.entrez.pubmed.GetPubMedAction;

/**
 * Test the PubMedAction used in the flow pubMed.Search
 * 
 *
 * <hr>
 * <p>Copyright (c) 2004 - 2005 Columbia University
 * @author keshav
 * @version $Id$
 */
public class GetPubMedActionTests extends TestCase {

    /**
     * JUnit support assertion facility
     */
    private JUnitAssertSupport asserts = new JUnitAssertSupport();

    public void testDoExecuteActionError() throws Exception {
        //set up mock object
        MockControl control = MockControl.createControl( BibliographicReferenceService.class );
        BibliographicReferenceService bibliographicReferenceService = ( BibliographicReferenceService ) control
                .getMock();
        bibliographicReferenceService.getBibliographicReferenceByTitle( "mock non-existing title" );
        control.setReturnValue( null, 1 );
        control.replay();

        GetPubMedAction action = new GetPubMedAction();
        action.setBibliographicReferenceService( bibliographicReferenceService );
        MockRequestContext context = new MockRequestContext();
        context.getFlowScope().setAttribute( "title", "mock non-existing title" );
        Event result = action.execute( context );
        assertEquals( "error", result.getId() );
        asserts().assertAttributeNotPresent( context.getRequestScope(), "bibliographicReference" );
        control.verify();
    }

    public void testDoExecuteActionSuccess() throws Exception {

        //set up mock object BibliographicReferenceService
        MockControl control = MockControl.createControl( BibliographicReferenceService.class );
        BibliographicReferenceService bibliographicReferenceService = ( BibliographicReferenceService ) control
                .getMock();
        bibliographicReferenceService.getBibliographicReferenceByTitle( "mock existing title" );
        //method getBibliographicReferenceByTitle(String s) called once.
        control.setReturnValue( new BibliographicReferenceImpl(), 1 );
        control.replay();

        GetPubMedAction action = new GetPubMedAction();
        action.setBibliographicReferenceService( bibliographicReferenceService );
        MockRequestContext context = new MockRequestContext();
        context.getFlowScope().setAttribute( "title", "mock existing title" );
        Event result = action.execute( context );
        assertEquals( "success", result.getId() );
        asserts().assertAttributePresent( context.getRequestScope(), "bibliographicReference" );
        control.verify();
    }

    /**
     * Returns a support class for doing additional JUnit assertion operations not supported out-of-the-box by JUnit
     * 3.8.1.
     * 
     * @return The junit assert support.
     */
    protected JUnitAssertSupport asserts() {
        return asserts;
    }
}<commit_msg>update for compatibility with new version<commit_after>package edu.columbia.gemma.web.controller.flow.action.entrez.pubmed;

import junit.framework.TestCase;

import org.easymock.MockControl;
import org.springframework.mock.web.flow.MockRequestContext;
import org.springframework.test.JUnitAssertSupport;
import org.springframework.web.flow.Event;

import edu.columbia.gemma.common.description.BibliographicReferenceImpl;
import edu.columbia.gemma.common.description.BibliographicReferenceService;
import edu.columbia.gemma.web.controller.flow.action.entrez.pubmed.GetPubMedAction;

/**
 * Test the PubMedAction used in the flow pubMed.Search
 * 
 *
 * <hr>
 * <p>Copyright (c) 2004 - 2005 Columbia University
 * @author keshav
 * @version $Id$
 */
public class GetPubMedActionTests extends TestCase {

    /**
     * JUnit support assertion facility
     */
    private JUnitAssertSupport asserts = new JUnitAssertSupport();

    public void testDoExecuteActionError() throws Exception {
        //set up mock object
        MockControl control = MockControl.createControl( BibliographicReferenceService.class );
        BibliographicReferenceService bibliographicReferenceService = ( BibliographicReferenceService ) control
                .getMock();
        bibliographicReferenceService.findByExternalId( "19491" );
        control.setReturnValue( null, 1 );
        control.replay();

        GetPubMedAction action = new GetPubMedAction();
        action.setBibliographicReferenceService( bibliographicReferenceService );
        MockRequestContext context = new MockRequestContext();
        context.getFlowScope().setAttribute( "pubMedId", "19491" );
        Event result = action.execute( context );
        assertEquals( "error", result.getId() );
        asserts().assertAttributeNotPresent( context.getRequestScope(), "bibliographicReference" );
        control.verify();
    }

    public void testDoExecuteActionSuccess() throws Exception {

        //set up mock object BibliographicReferenceService
        MockControl control = MockControl.createControl( BibliographicReferenceService.class );
        BibliographicReferenceService bibliographicReferenceService = ( BibliographicReferenceService ) control
                .getMock();
        bibliographicReferenceService.findByExternalId( "19491" );
        //method getBibliographicReferenceByTitle(String s) called once.
        control.setReturnValue( new BibliographicReferenceImpl(), 1 );
        control.replay();

        GetPubMedAction action = new GetPubMedAction();
        action.setBibliographicReferenceService( bibliographicReferenceService );
        MockRequestContext context = new MockRequestContext();
        context.getFlowScope().setAttribute( "pubMedId", "19491" );
        Event result = action.execute( context );
        assertEquals( "success", result.getId() );
        asserts().assertAttributePresent( context.getRequestScope(), "bibliographicReference" );
        control.verify();
    }

    /**
     * Returns a support class for doing additional JUnit assertion operations not supported out-of-the-box by JUnit
     * 3.8.1.
     * 
     * @return The junit assert support.
     */
    protected JUnitAssertSupport asserts() {
        return asserts;
    }
}
{'fraction_non_alphanumeric': 0.09019131491041603, 'fraction_numerical': 0.006984512602490131, 'mean_word_length': 3.6915954415954415, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1798139', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1644, 'n_words': 373}