<commit_before>/*
 * Copyright 2010 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
 * 
 * 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 org.kuali.kfs.module.endow.batch.service.impl;

import static org.kuali.kfs.sys.fixture.UserNameFixture.kfs;

import java.util.Calendar;

import org.kuali.kfs.module.endow.batch.service.RollFrequencyDatesService;
import org.kuali.kfs.module.endow.document.service.FrequencyDatesService;
import org.kuali.kfs.module.endow.document.service.KEMService;
import org.kuali.kfs.module.endow.fixture.RollFrequencyCodeFixture;
import org.kuali.kfs.sys.ConfigureContext;
import org.kuali.kfs.sys.context.KualiTestBase;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.kfs.sys.context.TestUtils;

@ConfigureContext(session = kfs)
public class RollFrequencyDatesServiceImplTest extends KualiTestBase {

    protected RollFrequencyDatesServiceImpl rollFrequencyDatesService;
    protected FrequencyDatesService frequencyDatesService;
    protected KEMService kemService;
    
    /**
     * @see junit.framework.TestCase#setUp()
     */
    @Override
    protected void setUp() throws Exception {        
        super.setUp();
        
        // Initialize service objects.
        frequencyDatesService = SpringContext.getBean(FrequencyDatesService.class);
        rollFrequencyDatesService = (RollFrequencyDatesServiceImpl) TestUtils.getUnproxiedService("mockRollFrequencyDatesService");       
        kemService = SpringContext.getBean(KEMService.class);
    }
    
    /**
     * 
     * @see junit.framework.TestCase#tearDown()
     */
    @Override
    protected void tearDown() throws Exception {
        frequencyDatesService = null;
        rollFrequencyDatesService = null;        
        kemService = null;
        super.tearDown();
    }

    public void testCalculateNextDueDate_InvalidFrequency() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.INVALID_FREQUENCY_CODE;
        Calendar cal = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        assertNull(frequencyCode + " must be invalid", frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(cal.getTimeInMillis())));        
    }
    
    /**
     * checks the next due date for daily code 
     */
    public void testCalculateNextDueDate_Daily() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.DAILY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.DAILY_EXPECTED_DATE.getCalendar();
        assertEquals("The calculation of the next daily date is incorect.", new java.sql.Date(expectedCalendar.getTimeInMillis()), frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis())));        
    }
  
    /**
     * checks the next due date for weekly code 
     */
    public void testCalculateNextDueDate_Weekly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.WEEKLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.WEEKLY_EXPECTED_DATE.getCalendar();
        assertEquals("The calculation of the next weekly date is incorect.", new java.sql.Date(expectedCalendar.getTimeInMillis()), frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis())));        
    }
 
    /**
     * checks the next due date for semi-monthly code 
     */
    public void testCalculateNextDueDate_SemiMonthly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.SEMI_MONTHLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.SEMI_MONTHLY_EXPECTED_DATE.getCalendar();
        assertEquals("The calculation of the next semi-monthly date is incorect.", new java.sql.Date(expectedCalendar.getTimeInMillis()), frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis())));        
    }
    
    /**
     * checks the next due date for monthly code 
     */
    public void testCalculateNextDueDate_Monthly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.MONTHLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.MONTHLY_EXPECTED_DATE.getCalendar();
        assertEquals("The calculation of the next monthly date is incorect.", new java.sql.Date(expectedCalendar.getTimeInMillis()), frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis())));        
    }

    /**
     * checks the next due date for quarterly code 
     */
    public void testCalculateNextDueDate_Quarterly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.QUARTERLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.QUARTERLY_EXPECTED_DATE.getCalendar();
        assertEquals("The calculation of the next quarterly date is incorect.", new java.sql.Date(expectedCalendar.getTimeInMillis()), frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis())));        
    }
    
    /**
     * checks the next due date for semi-annual code 
     */
    public void testCalculateNextDueDate_SemiAnnually() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.SEMI_ANNUALLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.SEMI_ANNUALLY_EXPECTED_DATE.getCalendar();
        assertEquals("The calculation of the next semi-annual date is incorect.", new java.sql.Date(expectedCalendar.getTimeInMillis()), frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis())));        
    }
    
    /**
     * checks the next due date for annual code 
     */
    public void testCalculateNextDueDate_Annually() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.ANNUALLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.ANNUALLY_EXPECTED_DATE.getCalendar();
        assertEquals("The calculation of the next annual date is incorect.", new java.sql.Date(expectedCalendar.getTimeInMillis()), frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis())));        
    }
    
    /**
     * tests RollFrequencyDatesService#updateSecurityIncomeNextPayDates
     */
    public void testRollFrequencyDatesService_updateSecurityIncomeNextPayDates() {        
        assertTrue("updateSecurityIncomeNextPayDates() failed.", rollFrequencyDatesService.updateSecurityIncomeNextPayDates());        
    }

    /**
     * tests RollFrequencyDatesService#updateTicklerNextDueDates
     */   
    public void testRollFrequencyDatesService_updateTicklerNextDueDates() {        
        assertTrue("updateTicklerNextDueDates() failed.", rollFrequencyDatesService.updateTicklerNextDueDates());        
    }
    
    /**
     * tests RollFrequencyDatesService#updateFeeMethodProcessDates
     */
    public void testRollFrequencyDatesService_updateFeeMethodProcessDates() {        
        assertTrue("updateFeeMethodProcessDates failed.", rollFrequencyDatesService.updateFeeMethodProcessDates());        
    }
    
    /**<commit_msg>KFSMI-6262: Created the comparison of Calendar and Date<commit_after>/*
 * Copyright 2010 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
 * 
 * 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 org.kuali.kfs.module.endow.batch.service.impl;

import static org.kuali.kfs.sys.fixture.UserNameFixture.kfs;

import java.sql.Date;
import java.util.Calendar;

import org.kuali.kfs.module.endow.document.service.FrequencyDatesService;
import org.kuali.kfs.module.endow.document.service.KEMService;
import org.kuali.kfs.module.endow.fixture.RollFrequencyCodeFixture;
import org.kuali.kfs.sys.ConfigureContext;
import org.kuali.kfs.sys.context.KualiTestBase;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.kfs.sys.context.TestUtils;

@ConfigureContext(session = kfs)
public class RollFrequencyDatesServiceImplTest extends KualiTestBase {

    protected RollFrequencyDatesServiceImpl rollFrequencyDatesService;
    protected FrequencyDatesService frequencyDatesService;
    protected KEMService kemService;
    
    /**
     * @see junit.framework.TestCase#setUp()
     */
    @Override
    protected void setUp() throws Exception {        
        super.setUp();
        
        // Initialize service objects.
        frequencyDatesService = SpringContext.getBean(FrequencyDatesService.class);
        rollFrequencyDatesService = (RollFrequencyDatesServiceImpl) TestUtils.getUnproxiedService("mockRollFrequencyDatesService");       
        kemService = SpringContext.getBean(KEMService.class);
    }
    
    /**
     * 
     * @see junit.framework.TestCase#tearDown()
     */
    @Override
    protected void tearDown() throws Exception {
        frequencyDatesService = null;
        rollFrequencyDatesService = null;        
        kemService = null;
        super.tearDown();
    }

    /**
     * compares Calendar and Date 
     * @param expectedDate
     * @param targetDate
     * @return
     */
    protected boolean compareDates(Calendar expectedDate, Date targetDate) {
        Calendar targetDateCalendar = Calendar.getInstance();
        targetDateCalendar.setTime(targetDate);
        if (targetDateCalendar.get(Calendar.YEAR) != expectedDate.get(Calendar.YEAR)) return false;
        if (targetDateCalendar.get(Calendar.MONTH) != expectedDate.get(Calendar.MONTH)) return false;
        if (targetDateCalendar.get(Calendar.DATE) != expectedDate.get(Calendar.DATE)) return false;        
        return true;
    }
    
    /**
     * validates the frequency code
     */
    public void testCalculateNextDueDate_InvalidFrequency() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.INVALID_FREQUENCY_CODE;
        Calendar cal = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        assertNull(frequencyCode + " must be invalid", frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(cal.getTimeInMillis())));        
    }
    
    /**
     * validates the next due date for daily code 
     */
    public void testCalculateNextDueDate_Daily() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.DAILY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.DAILY_EXPECTED_DATE.getCalendar();
        assertTrue("The calculation of the next daily date is incorrect.", compareDates(expectedCalendar, frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis()))));
    }
  
    /**
     * validates the next due date for weekly code 
     */
    public void testCalculateNextDueDate_Weekly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.WEEKLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.WEEKLY_EXPECTED_DATE.getCalendar();
        assertTrue("The calculation of the next weekly date is incorrect.", compareDates(expectedCalendar, frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis()))));        
    }
 
    /**
     * validates the next due date for semi-monthly code 
     */
    public void testCalculateNextDueDate_SemiMonthly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.SEMI_MONTHLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.SEMI_MONTHLY_EXPECTED_DATE.getCalendar();
        assertTrue("The calculation of the next semi-monthly date is incorrect.", compareDates(expectedCalendar, frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis()))));        
    }
    
    /**
     * validates the next due date for monthly code 
     */
    public void testCalculateNextDueDate_Monthly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.MONTHLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.MONTHLY_EXPECTED_DATE.getCalendar();
        assertTrue("The calculation of the next monthly date is incorrect.", compareDates(expectedCalendar, frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis()))));        
    }

    /**
     * validates the next due date for quarterly code 
     */
    public void testCalculateNextDueDate_Quarterly() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.QUARTERLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.QUARTERLY_EXPECTED_DATE.getCalendar();
        assertTrue("The calculation of the next quarterly date is incorrect.", compareDates(expectedCalendar, frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis()))));        
    }
    
    /**
     * validates the next due date for semi-annual code 
     */
    public void testCalculateNextDueDate_SemiAnnually() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.SEMI_ANNUALLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.SEMI_ANNUALLY_EXPECTED_DATE.getCalendar();
        assertTrue("The calculation of the next semi-annual date is incorrect.", compareDates(expectedCalendar, frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis()))));        
    }
    
    /**
     * validates the next due date for annual code 
     */
    public void testCalculateNextDueDate_Annually() {
        RollFrequencyCodeFixture rollFrequencyCodeFixture = RollFrequencyCodeFixture.ANNUALLY_TARGET_DATE;
        Calendar targetCalendar = rollFrequencyCodeFixture.getCalendar();
        String frequencyCode = rollFrequencyCodeFixture.getFrequencyCode();
        Calendar expectedCalendar = RollFrequencyCodeFixture.ANNUALLY_EXPECTED_DATE.getCalendar();
        assertTrue("The calculation of the next annual date is incorrect.", compareDates(expectedCalendar, frequencyDatesService.calculateNextDueDate(frequencyCode, new java.sql.Date(targetCalendar.getTimeInMillis()))));        
    }
    
    /**
     * tests RollFrequencyDatesService#updateSecurityIncomeNextPayDates
     */
    public void testRollFrequencyDatesService_updateSecurityIncomeNextPayDates() {        
        assertTrue("updateSecurityIncomeNextPayDates() failed.", rollFrequencyDatesService.updateSecurityIncomeNextPayDates());        
    }

    /**
     * tests RollFrequencyDatesService#updateTicklerNextDueDates
     */   
    public void testRollFrequencyDatesService_updateTicklerNextDueDates() {        
        assertTrue("updateTicklerNextDueDates() failed.", rollFrequencyDatesService.updateTicklerNextDueDates());        
    }
    
    /**
     * tests RollFrequencyDatesService#updateFeeMethodProcessDates
     */
    public void testRollFrequencyDatesService_updateFeeMethodProcessDates() {        
        assertTrue("updateFeeMethodProcessDates failed.", rollFrequencyDatesService.updateFeeMethodProcessDates());        
    }
    
    /**
{'fraction_non_alphanumeric': 0.07694397652556649, 'fraction_numerical': 0.0009781013965114384, 'mean_word_length': 4.064391854705558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3962174', 'n_tokens_mistral': 5037, 'n_tokens_neox': 4762, 'n_words': 960}