@Override
 public void mapFormOnEntity(JobForm form, JobFormEntity entity) {
   JobSource source = form.getSource();
   List<ReportParameter> params = source.getParameters();
   Map<String, Set<String>> values = mapSourceParamValues(params);
   entity.setSourceUri(source.getUri());
   entity.setSourceParameters(values);
 }
  @Test
  public void should_map_start_date_on_entity() throws Exception {
    JobFormEntity formEntity = formFactory.givenNewJobFormEntity();
    JobForm form = formFactory.givenJobFormWithValues();

    mapperUnderTest.mapFormOnEntity(form, formEntity);

    JobSimpleTriggerEntity simpleTrigger = formEntity.getSimpleTrigger();
    assertThat(simpleTrigger.getStartType(), is(2));
    assertThat(simpleTrigger.getStartDate(), is(formFactory.provideStartDateSrc()));
  }
  @Override
  public void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity) {
    JobSource.Builder builder = new JobSource.Builder();
    builder.withUri(entity.getSourceUri());

    Map<String, Set<String>> parameters = entity.getSourceParameters();
    if (parameters != null) {
      List<ReportParameter> params = mapParams(parameters);
      builder.withParameters(params);
    }

    JobSource source = builder.build();
    form.withJobSource(source);
  }
  @Test
  public void should_map_on_entity() throws Exception {
    JobFormEntity formEntity = formFactory.givenNewJobFormEntity();
    JobForm form =
        formFactory
            .givenJobFormBuilderWithValues()
            .withStartDate(null) // immediate start type
            .build();

    mapperUnderTest.mapFormOnEntity(form, formEntity);

    JobSimpleTriggerEntity simpleTrigger = formEntity.getSimpleTrigger();
    assertThat(simpleTrigger.getOccurrenceCount(), is(1));
    assertThat(simpleTrigger.getRecurrenceInterval(), is(1));
    assertThat(simpleTrigger.getRecurrenceIntervalUnit(), is("DAY"));
    assertThat(simpleTrigger.getTimezone(), is(formFactory.provideTimeZone().getID()));
    assertThat(simpleTrigger.getStartType(), is(1));
  }
  @Test
  public void should_map_none_trigger_type_as_simple_one() throws Exception {
    JobForm.Builder formBuilder = formFactory.givenJobFormBuilderWithValues();
    JobFormEntity jobFormEntity = formFactory.givenJobFormEntityWithValues();

    JobSimpleTriggerEntity simpleTrigger = new JobSimpleTriggerEntity();
    simpleTrigger.setOccurrenceCount(1);
    simpleTrigger.setStartDate(formFactory.provideStartDateSrc());
    simpleTrigger.setTimezone(formFactory.provideTimeZone().getID());

    jobFormEntity.setSimpleTrigger(simpleTrigger);

    mapperUnderTest.mapEntityOnForm(formBuilder, jobFormEntity);
    JobForm expected = formBuilder.build();

    assertThat(expected.getStartDate(), is(formFactory.provideStartDate()));
    assertThat(expected.getTimeZone(), is(formFactory.provideTimeZone()));
    assertThat(expected.getTrigger(), is(nullValue()));
  }