⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testtimesheetutils.java

📁 一个很好的开源项目管理系统源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            throws Exception {        // test when start date is not 1        Timesheet timesheet = new Timesheet();        timesheet.setFromDt(timesheetUtils.convertStringToDate("20050602",                "yyyyMMdd"));        timesheet.setThruDt(timesheetUtils.convertStringToDate("20050615",                "yyyyMMdd"));        try {            timesheetUtils.validateTimesheetPeriod(timesheet);            fail("An InvalidTimesheetPeriodException should be raised");        }        catch (InvalidTimesheetPeriodException expected) {            assertTrue(true);        }    }    public void testValidateTimesheetPeriod_semiMonthly_secondHalfInvalidFromDt()            throws Exception {        // test when start date is not 16        Timesheet timesheet = new Timesheet();        timesheet.setFromDt(timesheetUtils.convertStringToDate("20050617",                "yyyyMMdd"));        timesheet.setThruDt(timesheetUtils.convertStringToDate("20050630",                "yyyyMMdd"));        try {            timesheetUtils.validateTimesheetPeriod(timesheet);            fail("An InvalidTimesheetPeriodException should be raised");        }        catch (InvalidTimesheetPeriodException expected) {            assertTrue(true);        }    }    public void testValidateTimesheetPeriod_semiMonthly_firstHalfInvalidPeriod()            throws Exception {        // test where the fromDt is valid but the range is invalid.1st half of        // month        Timesheet timesheet = new Timesheet();        timesheet.setFromDt(timesheetUtils.convertStringToDate("20050601",                "yyyyMMdd"));        timesheet.setThruDt(timesheetUtils.convertStringToDate("20050616",                "yyyyMMdd"));        try {            timesheetUtils.validateTimesheetPeriod(timesheet);            fail("An InvalidTimesheetPeriodException should be raised.");        }        catch (InvalidTimesheetPeriodException expected) {            assertTrue(true);        }    }    public void testValidateTimesheetPeriod_semiMonthly_secondHalfInvalidPeriod()            throws Exception {        // invalid range for 2nd half of month        Timesheet timesheet = new Timesheet();        timesheet.setFromDt(timesheetUtils.convertStringToDate("20050616",                "yyyyMMdd"));        timesheet.setThruDt(timesheetUtils.convertStringToDate("20050629",                "yyyyMMdd"));        try {            timesheetUtils.validateTimesheetPeriod(timesheet);            fail("An InvalidTimesheetPeriodException should be raised.");        }        catch (InvalidTimesheetPeriodException expected) {            assertTrue(true);        }    }    public void testValidateHours_range_0_24() throws Exception {        Timesheet timesheet = new Timesheet();        timesheet.setTimesheetId(new Long(1));        timesheet.setPartyCd("xyz");        timesheet.setFromDt(timesheetUtils.convertStringToDate("20050613",                "yyyyMMdd"));        timesheet.setThruDt(timesheetUtils.convertStringToDate("20050619",                "yyyyMMdd"));        List timeEntryList = new ArrayList();        TimeEntry te1 = new TimeEntry();        te1.setTimesheetId(new Long(1));        te1.setWorkId(new Long(1));        te1.setRateTypeCd("RT");        te1.setDay0(new BigDecimal("-1.00"));        timeEntryList.add(te1);        timesheet.setTimeEntries(timeEntryList);        try {            timesheetUtils.validateHours(timesheet);            fail("Should raise InvalidHoursException");        }        catch (InvalidHoursException expected) {            assertTrue(true);        }        te1.setDay0(new BigDecimal("25.00"));        try {            timesheetUtils.validateHours(timesheet);            fail("Should raise InvalidHoursException");        }        catch (InvalidHoursException expected) {            assertTrue(true);        }    }    public void testValidateHours_dayTotalOver24() throws Exception {        Timesheet timesheet = new Timesheet();        timesheet.setTimesheetId(new Long(1));        timesheet.setPartyCd("xyz");        timesheet.setFromDt(timesheetUtils.convertStringToDate("20050613",                "yyyyMMdd"));        timesheet.setThruDt(timesheetUtils.convertStringToDate("20050619",                "yyyyMMdd"));        List timeEntryList = new ArrayList();        TimeEntry te1 = new TimeEntry();        te1.setTimesheetId(new Long(1));        te1.setWorkId(new Long(1));        te1.setRateTypeCd("RT");        te1.setDay6(new BigDecimal("15.00"));        timeEntryList.add(te1);        TimeEntry te2 = new TimeEntry();        te2.setTimesheetId(new Long(1));        te2.setWorkId(new Long(2));        te2.setRateTypeCd("RT");        te2.setDay6(new BigDecimal("10.00"));        timeEntryList.add(te2);        timesheet.setTimeEntries(timeEntryList);        try {            timesheetUtils.validateHours(timesheet);            fail("Should raise InvalidHoursException");        }        catch (InvalidHoursException expected) {            assertTrue(true);        }    }    public void testValidateHours_hourEntryBeyoundThruDt() throws Exception {        Timesheet timesheet = new Timesheet();        timesheet.setTimesheetId(new Long(1));        timesheet.setPartyCd("xyz");        timesheet.setFromDt(timesheetUtils.convertStringToDate("20050613",                "yyyyMMdd"));        timesheet.setThruDt(timesheetUtils.convertStringToDate("20050619",                "yyyyMMdd"));        List timeEntryList = new ArrayList();        TimeEntry te1 = new TimeEntry();        te1.setTimesheetId(new Long(1));        te1.setWorkId(new Long(1));        te1.setRateTypeCd("RT");        te1.setDay15(new BigDecimal("15.00"));        timeEntryList.add(te1);        timesheet.setTimeEntries(timeEntryList);        try {            timesheetUtils.validateHours(timesheet);            fail("Should raise IllegalStateException");        }        catch (IllegalStateException expected) {            assertTrue(true);        }    }    public void testCalculateAmountForDay_singleRateType() throws Exception {        BigDecimal hours = new BigDecimal("8.5");        Date date = timesheetUtils.convertStringToDate("20050613", "yyyyMMdd");        PartyRate pr1 = new PartyRate();        pr1.setFromDt(timesheetUtils                .convertStringToDate("20050606", "yyyyMMdd"));        pr1.setRateTypeCd("RT");        pr1.setRate(new BigDecimal(10.00));        pr1.setRateCur("USD");        List partyRateList = new ArrayList();        partyRateList.add(pr1);        Money tot = timesheetUtils.calculateAmountForDay(hours, date, "RT",                partyRateList);        assertEquals("Amount should be 85.00", new BigDecimal("85.00"), tot                .getAmount());    }    public void testCalculateAmountForDay_multipleRateType() throws Exception {        BigDecimal hours = new BigDecimal("8.5");        Date date = timesheetUtils.convertStringToDate("20050613", "yyyyMMdd");        PartyRate pr1 = new PartyRate();        pr1.setFromDt(timesheetUtils                .convertStringToDate("20050606", "yyyyMMdd"));        pr1.setRateTypeCd("RT");        pr1.setRate(new BigDecimal(10.00));        pr1.setRateCur("USD");        List partyRateList = new ArrayList();        partyRateList.add(pr1);        // test OT rate        PartyRate pr2 = new PartyRate();        pr2.setFromDt(timesheetUtils                .convertStringToDate("20050606", "yyyyMMdd"));        pr2.setRateTypeCd("OT");        pr2.setRate(new BigDecimal(20.00));        pr2.setRateCur("USD");        partyRateList.add(pr2);        Money tot = timesheetUtils.calculateAmountForDay(hours, date, "OT",                partyRateList);        assertEquals("Amount should be 170.00", new BigDecimal("170.00"), tot                .getAmount());    }    public void testCalculateAmountForDay_rateForOneDayOnly() throws Exception {        List partyRateList = new ArrayList();        BigDecimal hours = new BigDecimal("8.00");        // test for which there is rate only for one day        PartyRate pr3 = new PartyRate();        pr3.setFromDt(timesheetUtils                .convertStringToDate("20050601", "yyyyMMdd"));        pr3.setThruDt(timesheetUtils                .convertStringToDate("20050601", "yyyyMMdd"));        pr3.setRateTypeCd("RT");        pr3.setRate(new BigDecimal(30.00));        pr3.setRateCur("USD");        partyRateList.add(pr3);        Money tot = timesheetUtils.calculateAmountForDay(hours, timesheetUtils                .convertStringToDate("20050601", "yyyyMMdd"), "RT",                partyRateList);        assertEquals("Amount should be 240.00", new BigDecimal("240.00"), tot                .getAmount());    }    public void testCalculateAmountForDay_noRateForDate() throws Exception {        List partyRateList = new ArrayList();        BigDecimal hours = new BigDecimal("8.00");        // test for which there is rate only for one day        PartyRate pr3 = new PartyRate();        pr3.setFromDt(timesheetUtils                .convertStringToDate("20050601", "yyyyMMdd"));        pr3.setThruDt(timesheetUtils                .convertStringToDate("20050610", "yyyyMMdd"));        pr3.setRateTypeCd("RT");        pr3.setRate(new BigDecimal(30.00));        pr3.setRateCur("USD");        partyRateList.add(pr3);        // test for date which has no rate available in partyRate        try {            Money tot = timesheetUtils.calculateAmountForDay(hours,                    timesheetUtils.convertStringToDate("20050611", "yyyyMMdd"),                    "RT", partyRateList);            fail("An RateNotFoundException should be raised.");        }        catch (RateNotFoundException expected) {            assertTrue(true);        }    }    public void testCalculateAmountForDay_rateTypeNotPresent() throws Exception {        // test where the rateType is not present        List partyRateList = new ArrayList();        BigDecimal hours = new BigDecimal("8.00");        // test for which there is rate only for one day        PartyRate pr3 = new PartyRate();        pr3.setFromDt(timesheetUtils                .convertStringToDate("20050601", "yyyyMMdd"));        pr3.setThruDt(timesheetUtils                .convertStringToDate("20050610", "yyyyMMdd"));        pr3.setRateTypeCd("RT");        pr3.setRate(new BigDecimal(30.00));        pr3.setRateCur("USD");        partyRateList.add(pr3);        try {            Money tot = timesheetUtils.calculateAmountForDay(hours,                    timesheetUtils.convertStringToDate("20050601", "yyyyMMdd"),                    "XXX", partyRateList);            fail("An RateNotFoundException should be raised");        }        catch (RateNotFoundException expected) {            assertTrue(true);        }    }    public void testCalculateTimeEntryLineAmount_singleRate() throws Exception {        TimeEntry timeEntry = new TimeEntry();        timeEntry.setTimesheetId(new Long(1));        timeEntry.setWorkId(new Long(1));        timeEntry.setRateTypeCd("RT");        timeEntry.setDay0(new BigDecimal("1.00"));        timeEntry.setDay1(new BigDecimal("2.00"));        timeEntry.setDay2(new BigDecimal("3.00"));        timeEntry.setDay3(new BigDecimal("4.00"));        timeEntry.setDay4(new BigDecimal("5.00"));        timeEntry.setDay5(new BigDecimal("6.00"));        timeEntry.setDay6(new BigDecimal("7.00"));        PartyRate pr1 = new PartyRate();        pr1.setFromDt(timesheetUtils                .convertStringToDate("20050606", "yyyyMMdd"));        pr1.setRateTypeCd("RT");        pr1.setRate(new BigDecimal(10.00));        pr1.setRateCur("USD");        pr1.setPartyCd("xyz");        List partyRateList = new ArrayList();        partyRateList.add(pr1);        Date fromDt = timesheetUtils                .convertStringToDate("20050613", "yyyyMMdd");        timesheetUtils.calculateTimeEntryLineAmount(timeEntry, partyRateList,                fromDt, 7);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -