protected void onSetUpInTransaction() throws Exception {
    super.onSetUpInTransaction();

    servletConfig = new MockServletConfig(new MockServletContext(), "simple");
    MockServletConfig complexConfig =
        new MockServletConfig(servletConfig.getServletContext(), "complex");
    complexConfig.addInitParameter("publishContext", "false");
    complexConfig.addInitParameter("class", "notWritable");
    complexConfig.addInitParameter("unknownParam", "someValue");

    simpleDispatcherServlet = new DispatcherServlet();
    simpleDispatcherServlet.setContextClass(SimpleWebApplicationContext.class);
    simpleDispatcherServlet.init(servletConfig);

    complexDispatcherServlet = new DispatcherServlet();
    complexDispatcherServlet.setContextClass(WebApplicationContext.class);
    complexDispatcherServlet.setNamespace("test");

    Constants constants = (Constants) applicationContext.getBean("constants");
    Authentication auth = constants.getAuthentication(applicationContext);
    SecurityContextHolder.getContext().setAuthentication(auth);

    parent = (Controller) applicationContext.getBean("workCodeController");
    child = (Controller) applicationContext.getBean("workCodeFormController");
    sf = (SessionFactory) applicationContext.getBean("sessionFactory");
  }
  protected void onSetUpInTransaction() throws Exception {
    super.onSetUpInTransaction();
    HoursWorked hours = null;
    HoursWorkedDaoHibernate dao = null;
    JobManager mgrJob = null;

    FulltimeAgreements fulltimeAgreement = null;
    FulltimeAgreementDao fulltimeDao = null;
    WorkCodeDao workcodeDao = null;

    PeoplePropertiesDao peopleDao = null;
    JobDao jobDao = null;
    HoursWorkedDao hoursDao = null;
    PeopleProperties people = null;

    super.onSetUpBeforeTransaction();

    mgrJob = (JobManager) applicationContext.getBean("jobManager");

    Constants constants = (Constants) applicationContext.getBean("constants");
    Authentication auth = constants.getAuthentication(applicationContext);
    SecurityContextHolder.getContext().setAuthentication(auth);

    CodeTermDao termDao = (CodeTermDao) applicationContext.getBean("termDao");
    CodeTerm term = termDao.findTerm("FA");
    if (term == null) {
      term = new CodeTerm();
      term.setTerm("FA");
      termDao.saveTerms(term);
    }

    PayPeriodDao payDao = (PayPeriodDao) applicationContext.getBean("payPeriodDao");
    PayPeriodDao payPeriodDao = (PayPeriodDao) applicationContext.getBean("payPeriodDao");
    workcodeDao = (WorkCodeDao) applicationContext.getBean("workCodeDao");

    peopleDao = (PeoplePropertiesDao) applicationContext.getBean("peoplePropertiesDao");
    people = peopleDao.getPerson("000201922");
    if (people == null) {
      // inserted = true;
      people = new PeopleProperties();
      people.setFirstName("first");
      people.setLastName("last");
      people.setMiddleName("middle");
      people.setGovernmentId("999999999");
      people.setPeopleId("000201922");
      peopleDao.save(people);
      log.debug("INSERTED PERSON");
    }
    // 133	Bus.Office	01-IS-00-133	59	000203290	01-IS-00-133

    jobDao = (JobDao) applicationContext.getBean("jobDao");
    Job jobBus = mgrJob.getJobByDepartment("133");
    if (jobBus == null) {
      log.debug("insert job ");
      // insertedJob = true;
      jobBus = new Job();
      // job.setId(1L);
      jobBus.setAccountNumber("XXX");
      jobBus.setDepartment("133");
      jobBus.setDescription("bus.off");
      jobDao.saveJob(jobBus);
    }
    Job jobIt = jobDao.getJob("071");
    if (jobIt == null) {
      log.debug("insert job ");
      jobIt = new Job();
      jobIt.setAccountNumber("XXX");
      jobIt.setDepartment("071");
      jobIt.setDescription("it");
      jobDao.saveJob(jobIt);
    }

    fulltimeDao = (FulltimeAgreementDao) applicationContext.getBean("fulltimeAgreementDao");
    Set<FulltimeAgreements> agreements = people.getFulltimeAgreements();
    fulltimeAgreement = new FulltimeAgreements();
    fulltimeAgreement.setActive(true);
    fulltimeAgreement.setJob(jobIt);
    fulltimeAgreement.setOvertime(555);
    fulltimeAgreement.setRate(555);
    fulltimeAgreement.setPeople(people);
    agreements.add(fulltimeAgreement);

    hoursDao = (HoursWorkedDao) applicationContext.getBean("hoursWorkedDao");
    List<HoursWorked> hoursList =
        hoursDao.getHoursWorked("000201922", "133", Constants.getDate("MM/dd/yyyy", "01/01/2008"));
    if (hoursList == null || hoursList.size() < 1) {
      log.debug("insert hours ");
      // insertedJob = true;
      hours = new HoursWorked();

      hours.setPeopleId("000201922");
      hours.setJob(mgrJob.getJobByDepartment("133"));
      hours.setDateIn(Constants.getDate("MM/dd/yyyy", "01/01/2008"));
      WorkCode w = workcodeDao.getWorkCode("LOGIN");
      hours.setWorkcode(w);
      hoursDao.saveHoursWorked(hours);
    }

    termDao = (CodeTermDao) applicationContext.getBean("termDao");
    term = termDao.findTerm("FA");
    if (term == null) {
      term = new CodeTerm();
      term.setTerm("FA");
      termDao.saveTerms(term);
    }

    payPeriodDao = (PayPeriodDao) applicationContext.getBean("payPeriodDao");
    java.sql.Date beginDate = Constants.getSqlDate("MM/dd/yyyy", "01/01/2008");
    PayPer pay = (PayPer) payPeriodDao.getPeriod(beginDate, false);
    if (pay == null) {
      pay = new PayPer();
      pay.setCodeTerm(term);
      pay.setBeginDate(beginDate);
      pay.setEndDate(
          Constants.addField(Calendar.DATE, -1, Constants.addField(Calendar.MONTH, 1, beginDate)));
      pay.setPpYear("" + Constants.year(beginDate));
      payPeriodDao.savePeriod(pay);
    }

    AwardedDao awardDao = (AwardedDao) applicationContext.getBean("awardedDao");
    List<Awarded> awarded = (List<Awarded>) awardDao.getAward("000201922", "2008", "FA");

    if (awarded == null || awarded.size() == 0) {
      AgreementsDao agreeDao = (AgreementsDao) applicationContext.getBean("agreementsDao");

      Awarded award1 = new Awarded();
      award1.setAmount(2000);
      award1.setAwards(awardDao.getAwards("IWX652"));
      award1.setCodeTerm(term);
      PeopleProperties p = new PeopleProperties();
      p.setPeopleId("000201922");
      award1.setPerson(p);
      award1.setYear("2008");
      awardDao.saveAward(award1);

      Agreements agree = new Agreements();
      agree.setAmount(-1);
      agree.setAwarded(award1);
      agree.setJob(jobBus);
      agree.setRate(655);
      agreeDao.saveAgreement(agree);

      Awarded award2 = new Awarded();
      award2.setAmount(444);
      award2.setAwards(awardDao.getAwards("FWN651"));
      award2.setCodeTerm(term);
      p = new PeopleProperties();
      p.setPeopleId("000198239");
      award1.setPerson(p);
      award2.setYear("2008");
      awardDao.saveAward(award2);
      Agreements agree2 = new Agreements();
      agree2.setAmount(100);
      agree2.setAwarded(award2);
      agree2.setJob(jobIt);
      agree2.setRate(655);
      agreeDao.saveAgreement(agree2);
    }
  }
  public void testNew() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request = new MockHttpServletRequest("GET", "/workCodeForm.html");
    MockHttpServletResponse response = new MockHttpServletResponse();
    simpleDispatcherServlet.service(request, response);
    ModelAndView mv = child.handleRequest(request, response);

    Map m = mv.getModel();
    log.debug("m = " + m);
    WorkCodeFormBacking backing = (WorkCodeFormBacking) m.get("workCodeFormBacking");
    log.debug(Constants.toReflexString(backing));

    MockPageContext ctx = new MockPageContext();
    Iterator i = m.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      ctx.setAttribute(key, m.get(key));
    }

    RequestContext r = new RequestContext(request, m);

    BindStatus b = r.getBindStatus("workCodeFormBacking.workCode.description");
    log.debug("expression = " + b.getExpression());
    log.debug("value = " + b.getValue());

    String description =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.description}", String.class, ctx);

    // request.addParameter(name, description);
    String parttime =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.parttime}", String.class, ctx);
    String code =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.code}", String.class, ctx);
    String id =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.id}", String.class, ctx);
    String save =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.save}", String.class, ctx);

    log.debug("description = " + description);
    log.debug("parttime = " + parttime);
    log.debug("code = " + code);
    log.debug("id = " + id);
    log.debug("save = " + save);

    HashMap newMap = new HashMap();
    newMap.put(
        r.getBindStatus("workCodeFormBacking.workCode.description").getExpression(), description);
    newMap.put(r.getBindStatus("workCodeFormBacking.workCode.parttime").getExpression(), parttime);
    newMap.put(r.getBindStatus("workCodeFormBacking.workCode.code").getExpression(), code);
    newMap.put(r.getBindStatus("workCodeFormBacking.workCode.id").getExpression(), id);
    newMap.put(r.getBindStatus("workCodeFormBacking.save").getExpression(), "save");

    request = new MockHttpServletRequest("POST", "/workCodeForm.html");
    i = newMap.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      log.debug("add parameter " + key + "  " + newMap.get(key));
      request.addParameter(key, (String) newMap.get(key));
    }
    mv = child.handleRequest(request, response);
    m = mv.getModel();
    log.debug("m = " + m);
    BeanPropertyBindingResult br =
        (BeanPropertyBindingResult)
            m.get("org.springframework.validation.BindingResult.workCodeFormBacking");
    log.debug("field errors " + br.getFieldErrorCount());
    log.debug("errors " + br.getErrorCount());
    assertTrue(br.getFieldError("workCode.code") != null);
    assertTrue(br.getFieldError("workCode.description") != null);
    backing = (WorkCodeFormBacking) m.get("workCodeFormBacking");
    log.debug(response.getErrorMessage());
    log.debug(Constants.toReflexString(backing));
    log.debug("view = " + mv.getViewName());
    assertTrue("workCodeForm".equals(mv.getViewName()));
  }