<commit_before>/**
 * $Id$
 * $URL$
 * EvalEvaluationServiceImplTest.java - evaluation - Jan 28, 2008 6:01:13 PM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Centre for Applied Research in Educational Technologies, University of Cambridge
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 *
 * <NAME> (<EMAIL>) (<EMAIL>) (<EMAIL>)
 */

package org.sakaiproject.evaluation.logic;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.sakaiproject.evaluation.constant.EvalConstants;
import org.sakaiproject.evaluation.constant.EvalEmailConstants;
import org.sakaiproject.evaluation.logic.externals.EvalSecurityChecksImpl;
import org.sakaiproject.evaluation.logic.model.EvalGroup;
import org.sakaiproject.evaluation.model.EvalAssignGroup;
import org.sakaiproject.evaluation.model.EvalAssignHierarchy;
import org.sakaiproject.evaluation.model.EvalAssignUser;
import org.sakaiproject.evaluation.model.EvalEmailTemplate;
import org.sakaiproject.evaluation.model.EvalEvaluation;
import org.sakaiproject.evaluation.model.EvalResponse;
import org.sakaiproject.evaluation.test.EvalTestDataLoad;


/**
 * Tests for the EvalEvaluationServiceImpl
 * 
 * @author <NAME> (<EMAIL>)
 */
public class EvalEvaluationServiceImplTest extends BaseTestEvalLogic {

    protected EvalEvaluationServiceImpl evaluationService;
    protected EvalSettings settings;

    // run this before each test starts
    protected void onSetUpBeforeTransaction() throws Exception {
        super.onSetUpBeforeTransaction();

        // load up any other needed spring beans
        settings = (EvalSettings) applicationContext.getBean("org.sakaiproject.evaluation.logic.EvalSettings");
        if (settings == null) {
            throw new NullPointerException("EvalSettings could not be retrieved from spring evalGroupId");
        }

        EvalSecurityChecksImpl securityChecks = 
            (EvalSecurityChecksImpl) applicationContext.getBean("org.sakaiproject.evaluation.logic.externals.EvalSecurityChecks");
        if (securityChecks == null) {
            throw new NullPointerException("EvalSecurityChecksImpl could not be retrieved from spring context");
        }

        // setup the mock objects if needed

        // create and setup the object to be tested
        evaluationService = new EvalEvaluationServiceImpl();
        evaluationService.setDao(evaluationDao);
        evaluationService.setCommonLogic(commonLogic);
        evaluationService.setSecurityChecks(securityChecks);
        evaluationService.setSettings(settings);

    }


    /**
     * ADD unit tests below here, use testMethod as the name of the unit test,
     * Note that if a method is overloaded you should include the arguments in the
     * test name like so: testMethodClassInt (for method(Class, int);
     */


    /**
     * Test method for {@link org.sakaiproject.evaluation.logic.EvalEvaluationServiceImpl#getEvaluationById(java.lang.Long)}.
     */
    public void testGetEvaluationById() {
        EvalEvaluation eval = evaluationService.getEvaluationById(etdl.evaluationActive.getId());
        assertNotNull(eval);
        assertNotNull(eval.getBlankResponsesAllowed());
        assertNotNull(eval.getModifyResponsesAllowed());
        assertNotNull(eval.getResultsSharing());
        assertNotNull(eval.getUnregisteredAllowed());
        assertEquals(etdl.evaluationActive.getId(), eval.getId());

        eval = evaluationService.getEvaluationById(etdl.evaluationNew.getId());
        assertNotNull(eval);
        assertEquals(etdl.evaluationNew.getId(), eval.getId());

        // test get eval by invalid id
        eval = evaluationService.getEvaluationById( EvalTestDataLoad.INVALID_LONG_ID );
        assertNull(eval);
    }

    /**
     * Test method for {@link org.sakaiproject.evaluation.logic.EvalEvaluationServiceImpl#checkEvaluationExists(java.lang.Long)}.
     */
    public void testCheckEvaluationExists() {
        // positive
        assertTrue(evaluationService.checkEvaluationExists(etdl.evaluationActive.getId()));
        assertTrue(evaluationService.checkEvaluationExists(etdl.evaluationClosed.getId()));

        // negative
        assertFalse(evaluationService.checkEvaluationExists(EvalTestDataLoad.INVALID_LONG_ID));

        // exception
        try {
            evaluationService.checkEvaluationExists(null);<commit_msg>Committed a fun query cache test, it does not do much but it may help someone<commit_after>/**
 * $Id$
 * $URL$
 * EvalEvaluationServiceImplTest.java - evaluation - Jan 28, 2008 6:01:13 PM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Centre for Applied Research in Educational Technologies, University of Cambridge
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 *
 * <NAME> (<EMAIL>) (<EMAIL>) (<EMAIL>)
 */

package org.sakaiproject.evaluation.logic;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.sakaiproject.evaluation.constant.EvalConstants;
import org.sakaiproject.evaluation.constant.EvalEmailConstants;
import org.sakaiproject.evaluation.logic.externals.EvalSecurityChecksImpl;
import org.sakaiproject.evaluation.logic.model.EvalGroup;
import org.sakaiproject.evaluation.model.EvalAssignGroup;
import org.sakaiproject.evaluation.model.EvalAssignHierarchy;
import org.sakaiproject.evaluation.model.EvalAssignUser;
import org.sakaiproject.evaluation.model.EvalEmailTemplate;
import org.sakaiproject.evaluation.model.EvalEvaluation;
import org.sakaiproject.evaluation.model.EvalResponse;
import org.sakaiproject.evaluation.test.EvalTestDataLoad;


/**
 * Tests for the EvalEvaluationServiceImpl
 * 
 * @author <NAME> (<EMAIL>)
 */
public class EvalEvaluationServiceImplTest extends BaseTestEvalLogic {

    protected EvalEvaluationServiceImpl evaluationService;
    protected EvalSettings settings;

    // run this before each test starts
    protected void onSetUpBeforeTransaction() throws Exception {
        super.onSetUpBeforeTransaction();

        // load up any other needed spring beans
        settings = (EvalSettings) applicationContext.getBean("org.sakaiproject.evaluation.logic.EvalSettings");
        if (settings == null) {
            throw new NullPointerException("EvalSettings could not be retrieved from spring evalGroupId");
        }

        EvalSecurityChecksImpl securityChecks = 
            (EvalSecurityChecksImpl) applicationContext.getBean("org.sakaiproject.evaluation.logic.externals.EvalSecurityChecks");
        if (securityChecks == null) {
            throw new NullPointerException("EvalSecurityChecksImpl could not be retrieved from spring context");
        }

        // setup the mock objects if needed

        // create and setup the object to be tested
        evaluationService = new EvalEvaluationServiceImpl();
        evaluationService.setDao(evaluationDao);
        evaluationService.setCommonLogic(commonLogic);
        evaluationService.setSecurityChecks(securityChecks);
        evaluationService.setSettings(settings);

    }


    /**
     * ADD unit tests below here, use testMethod as the name of the unit test,
     * Note that if a method is overloaded you should include the arguments in the
     * test name like so: testMethodClassInt (for method(Class, int);
     */


    /**
     * Test method for {@link org.sakaiproject.evaluation.logic.EvalEvaluationServiceImpl#getEvaluationById(java.lang.Long)}.
     */
    public void testGetEvaluationById() {
        EvalEvaluation eval = evaluationService.getEvaluationById(etdl.evaluationActive.getId());
        assertNotNull(eval);
        assertNotNull(eval.getBlankResponsesAllowed());
        assertNotNull(eval.getModifyResponsesAllowed());
        assertNotNull(eval.getResultsSharing());
        assertNotNull(eval.getUnregisteredAllowed());
        assertEquals(etdl.evaluationActive.getId(), eval.getId());

        eval = evaluationService.getEvaluationById(etdl.evaluationNew.getId());
        assertNotNull(eval);
        assertEquals(etdl.evaluationNew.getId(), eval.getId());

        // test get eval by invalid id
        eval = evaluationService.getEvaluationById( EvalTestDataLoad.INVALID_LONG_ID );
        assertNull(eval);
    }

    public void testCacheRetrievalOfEvals() {
        System.out.println("CACHE: Testing lots of retrievals in a row");
        EvalEvaluation eval = null;

        eval = evaluationService.getEvaluationById(etdl.evaluationActive.getId());
        assertNotNull(eval);

        eval = evaluationService.getEvaluationById(EvalTestDataLoad.INVALID_LONG_ID);
        assertNull(eval);

        eval = evaluationService.getEvaluationById(etdl.evaluationActive.getId());
        assertNotNull(eval);

        eval = evaluationService.getEvaluationById(etdl.evaluationActive.getId());
        assertNotNull(eval);

        eval = evaluationService.getEvaluationById(EvalTestDataLoad.INVALID_LONG_ID);
        assertNull(eval);

        eval = evaluationService.getEvaluationById(etdl.evaluationActive.getId());
        assertNotNull(eval);

        eval = evaluationService.getEvaluationById(etdl.evaluationActive.getId());
        assertNotNull(eval);

        System.out.println("CACHE: Should have been 3 showSQL log lines");
    }

    /**
     * Test method for {@link org.sakaiproject.evaluation.logic.EvalEvaluationServiceImpl#checkEvaluationExists(java.lang.Long)}.
     */
    public void testCheckEvaluationExists() {
        // positive
        assertTrue(evaluationService.checkEvaluationExists(etdl.evaluationActive.getId()));
        assertTrue(evaluationService.checkEvaluationExists(etdl.evaluationClosed.getId()));

        // negative
        assertFalse(evaluationService.checkEvaluationExists(EvalTestDataLoad.INVALID_LONG_ID));

        // exception
        try {
            evaluationService.checkEvaluationExists(null);
{'fraction_non_alphanumeric': 0.10397583317092185, 'fraction_numerical': 0.0036055349834340283, 'mean_word_length': 3.9175850503114518, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4336340', 'n_tokens_mistral': 2807, 'n_tokens_neox': 2638, 'n_words': 577}