@Test
  public void testIngestSaveCascade() {
    Ingest ingest = new IngestOGP();
    ingest.setBeginDate(new Date());
    ingest.setFrequency(Frequency.ONCE);
    ingest.setLastRun(new Date());
    ingest.setNameOgpRepository("Name Ogp Repository");
    ingest.setUrl("http://geodata.tufts.edu");
    ingest.setScheduled(true);
    ingest.setName("Test name");

    ingest = ingestRepository.save(ingest);

    assertNotNull(ingest.getId());

    IngestJobStatus jStatus = new IngestJobStatus();
    jStatus.setStatus(IngestJobStatusValue.SUCCESSED);
    jStatus.setStartTime(new Date());
    jStatus.setEndTime(new Date());
    jStatus.setIngest(ingest);
    jStatus = jobStatusService.save(jStatus);

    long numRecords = 1000L;
    ingest = ingestRepository.save(ingest);
    IngestReport iReport = new IngestReport();
    iReport.setPublicRecords(numRecords);
    iReport.setRasterRecords(numRecords);
    iReport.setRestrictedRecords(numRecords);
    iReport.setUnrequiredFieldWarnings(numRecords);
    iReport.setVectorRecords(numRecords);
    iReport.setWebServiceWarnings(numRecords);
    iReport.setJobStatus(jStatus);
    iReport = reportService.save(iReport);

    for (int i = 0; i < numRecords; i++) {
      IngestReportError error = new IngestReportError();
      error.setField("my_field");
      error.setMessage("My error message");
      error.setMetadata("My metadata");
      error.setType(IngestReportErrorType.REQUIRED_FIELD_ERROR);
      error.setReport(iReport);
      error = reportErrorService.save(error);
    }

    ingest.setLastRun(new Date());
    ingest = ingestRepository.save(ingest);
  }
  @Test
  @DatabaseSetup("ingestData.xml")
  public void testUpdateIngestWithJob() {
    Ingest ingest = ingestRepository.findOne(2L);

    IngestJobStatus jobStatus = new IngestJobStatus();
    jobStatus.setStatus(IngestJobStatusValue.SUCCESSED);
    jobStatus.setStartTime(new Date());
    jobStatus.setEndTime(new Date());
    jobStatus.setIngest(ingest);
    jobStatus = jobStatusService.save(jobStatus);

    IngestReport report = new IngestReport();
    report.setPublicRecords(100);
    report.setRestrictedRecords(20);
    report.setRasterRecords(70);
    report.setVectorRecords(50);

    report.setWebServiceWarnings(20);
    report.setUnrequiredFieldWarnings(60);
    report.setJobStatus(jobStatus);
    report = reportService.save(report);
    jobStatus.setIngestReport(report);
    jobStatus = jobStatusService.save(jobStatus);

    IngestReportError reportError = new IngestReportError();
    reportError.setField("title");
    reportError.setType(IngestReportErrorType.REQUIRED_FIELD_ERROR);
    reportError.setReport(report);
    reportError = reportErrorService.save(reportError);

    Ingest ingestUpdated = ingestRepository.save(ingest);

    Assert.assertNotNull(ingestUpdated);

    Ingest ingestRetrieved = ingestRepository.findOne(2L);
    Assert.assertEquals(ingestUpdated, ingestRetrieved);

    List<IngestJobStatus> jobStatuses = jobStatusService.getStatusesForIngest(ingest.getId());
    Assert.assertEquals(1, jobStatuses.size());

    IngestReport reportRetrieved = jobStatuses.get(0).getIngestReport();
    Assert.assertEquals(reportRetrieved, report);

    Assert.assertEquals(IngestJobStatusValue.SUCCESSED, jobStatuses.get(0).getStatus());
    Assert.assertEquals(100, reportRetrieved.getPublicRecords());
    Assert.assertEquals(20, reportRetrieved.getRestrictedRecords());
  }