@Test
  public void createForProcessOverviewShouldAddCorrectAuthorizations() throws Exception {
    doReturn("clave")
        .when(formMappingKeyGenerator)
        .generateKey(PROCESS_DEFINITION_ID, null, FormMappingType.PROCESS_OVERVIEW.getId());

    formMappingService.create(
        PROCESS_DEFINITION_ID,
        null,
        FormMappingType.PROCESS_OVERVIEW.getId(),
        SFormMapping.TARGET_URL,
        null);

    verify(pageMappingService)
        .create(
            "clave",
            null,
            EXTERNAL,
            Arrays.asList(
                IS_ADMIN,
                IS_PROCESS_OWNER,
                IS_PROCESS_INITIATOR,
                IS_TASK_PERFORMER,
                IS_INVOLVED_IN_PROCESS_INSTANCE));
  }
  @Test
  public void testSearchFormMappings() throws Exception {
    QueryOptions queryOptions = mock(QueryOptions.class);
    formMappingService.searchFormMappings(queryOptions);

    verify(persistenceService)
        .searchEntity(SFormMapping.class, queryOptions, Collections.<String, Object>emptyMap());
  }
  @Test
  public void testGetNumberOfFormMappings() throws Exception {
    QueryOptions queryOptions = mock(QueryOptions.class);
    formMappingService.getNumberOfFormMappings(queryOptions);

    verify(persistenceService)
        .getNumberOfEntities(
            SFormMapping.class, queryOptions, Collections.<String, Object>emptyMap());
  }
  @Test
  public void createWithInternalPageShouldCallPageMapping_create() throws Exception {
    doReturn("theKey").when(formMappingKeyGenerator).generateKey(PROCESS_DEFINITION_ID, "step1", 2);

    formMappingService.create(
        PROCESS_DEFINITION_ID, "step1", 2, SFormMapping.TARGET_INTERNAL, null);

    verify(pageMappingService).create(eq("theKey"), isNull(Long.class), anyList());
  }
  @Test
  public void createFormMappingWithUndefinedTargetShouldNotAddPageMapping() throws Exception {
    doReturn("mockedKey")
        .when(formMappingKeyGenerator)
        .generateKey(PROCESS_DEFINITION_ID, "someHumanTask", 84);

    formMappingService.create(
        PROCESS_DEFINITION_ID, "someHumanTask", 84, SFormMapping.TARGET_UNDEFINED, null);

    verifyZeroInteractions(pageMappingService);
  }
  @Test
  public void testGetByKey() throws Exception {
    formMappingService.get("theKey");

    verify(persistenceService)
        .selectOne(
            new SelectOneDescriptor<SFormMapping>(
                "getFormMappingByKey",
                Collections.<String, Object>singletonMap("key", "theKey"),
                SFormMapping.class));
  }
  @Test
  public void test_update_with_page() throws Exception {
    SFormMapping formMapping = createFormMapping(ID);

    formMappingService.update(formMapping, null, PAGE_ID);

    verify(recorder).recordUpdate(updateRecordCaptor.capture(), updateEventCaptor.capture());
    assertThat(updateRecordCaptor.getValue().getFields())
        .contains(
            entry("target", SFormMapping.TARGET_INTERNAL),
            entry("pageMapping.url", null),
            entry("pageMapping.pageId", PAGE_ID),
            entry("pageMapping.urlAdapter", null));
  }
  @Test
  public void createLegacyFormShouldNotAddCorrectAuthorizations() throws Exception {
    doReturn("keye")
        .when(formMappingKeyGenerator)
        .generateKey(PROCESS_DEFINITION_ID, null, FormMappingType.PROCESS_START.getId());

    formMappingService.create(
        PROCESS_DEFINITION_ID,
        null,
        FormMappingType.PROCESS_START.getId(),
        SFormMapping.TARGET_LEGACY,
        null);

    verify(pageMappingService).create("keye", null, LEGACY, null);
  }
  @Test
  public void createForProcessStartShouldAddCorrectAuthorizations() throws Exception {
    doReturn("keye")
        .when(formMappingKeyGenerator)
        .generateKey(PROCESS_DEFINITION_ID, null, FormMappingType.PROCESS_START.getId());

    formMappingService.create(
        PROCESS_DEFINITION_ID,
        null,
        FormMappingType.PROCESS_START.getId(),
        SFormMapping.TARGET_URL,
        null);

    verify(pageMappingService)
        .create(
            "keye", null, EXTERNAL, Arrays.asList(IS_ADMIN, IS_PROCESS_OWNER, IS_ACTOR_INITIATOR));
  }
  @Test
  public void createForTaskShouldAddCorrectAuthorizations() throws Exception {
    doReturn("clef")
        .when(formMappingKeyGenerator)
        .generateKey(PROCESS_DEFINITION_ID, "task", FormMappingType.TASK.getId());

    formMappingService.create(
        PROCESS_DEFINITION_ID,
        "task",
        FormMappingType.TASK.getId(),
        SFormMapping.TARGET_INTERNAL,
        null);

    verify(pageMappingService)
        .create(
            "clef", null, Arrays.asList(IS_ADMIN, IS_PROCESS_OWNER, IS_TASK_AVAILABLE_FOR_USER));
  }
  @Test(expected = SObjectModificationException.class)
  public void test_update_with_invalid_parameters3() throws Exception {
    SFormMapping formMapping = createFormMapping(ID);

    formMappingService.update(formMapping, "", null);
  }
  @Test(expected = SObjectModificationException.class)
  public void test_update_with_page_that_does_not_exists() throws Exception {
    SFormMapping formMapping = createFormMapping(ID);

    formMappingService.update(formMapping, null, 557441l);
  }
 @Test(expected = IllegalArgumentException.class)
 public void testCreateWithNullTarget() throws Exception {
   formMappingService.create(1654L, "step1", 1, null, null);
 }