@Test(expected = PageBreakBeforeRequiredFieldsException.class)
  public void executeWithPageBreakBeforeMandatory() throws ServletException, IOException {
    final Site site = TestUtil.createSite();
    TestUtil.createUserAndUserOnSiteRightAndLogin(site, SiteAccessLevel.ADMINISTRATOR);
    final PageManager pageVersion = TestUtil.createPageVersionAndPage(site);

    WidgetItem widget = TestUtil.createWidgetItem();
    widget.setPosition(0);
    persistance.putWidget(widget);
    pageVersion.addWidget(widget);

    final CreateContactUsWidgetRequest request = new CreateContactUsWidgetRequest();
    request.setContactUsName("name");
    request.setDisplayHeader(true);
    request.setEmail("*****@*****.**");
    request.setHeader("header");
    request.setWidgetId(widget.getWidgetId());

    final List<DraftFormItem> formItems =
        TestUtil.createFormItems(
            FormItemName.FIRST_NAME, FormItemName.PAGE_BREAK, FormItemName.REGISTRATION_EMAIL);

    request.setFormItems(formItems);

    service.execute(request);
  }
  @Test(expected = ContactUsNameNotUniqueException.class)
  public void executeWithNotUniqueName() throws ServletException, IOException {
    final Site site = TestUtil.createSite();
    TestUtil.createUserAndUserOnSiteRightAndLogin(site, SiteAccessLevel.ADMINISTRATOR);
    PageManager pageVersion = TestUtil.createPageVersionAndPage(site);

    WidgetItem widget = TestUtil.createWidgetItem();
    widget.setPosition(0);
    persistance.putWidget(widget);
    pageVersion.addWidget(widget);

    DraftContactUs contactUs = new DraftContactUs();
    contactUs.setShowDescription(true);
    contactUs.setEmail("[email protected]");
    contactUs.setDescription("header");
    contactUs.setName("name2");
    contactUs.setSiteId(site.getSiteId());
    ServiceLocator.getPersistance().putContactUs(contactUs);

    DraftContactUs contactUs2 = new DraftContactUs();
    contactUs2.setShowDescription(true);
    contactUs2.setEmail("[email protected]");
    contactUs2.setDescription("header2");
    contactUs2.setName("name");
    contactUs2.setSiteId(site.getSiteId());
    ServiceLocator.getPersistance().putContactUs(contactUs2);

    widget.setDraftItem(contactUs);

    final CreateContactUsWidgetRequest request = new CreateContactUsWidgetRequest();
    request.setContactUsName("name");
    request.setContactUsId(contactUs.getId());
    request.setDisplayHeader(true);
    request.setEmail("[email protected]");
    request.setHeader("header");
    request.setWidgetId(widget.getWidgetId());
    final List<DraftFormItem> formItems =
        TestUtil.createFormItems(FormItemName.FIRST_NAME, FormItemName.REGISTRATION_EMAIL);
    request.setFormItems(formItems);

    service.execute(request);
  }
  @Test
  public void executeFromSiteEditPage() throws ServletException, IOException {
    final Site site = TestUtil.createSite();
    TestUtil.createUserAndUserOnSiteRightAndLogin(site, SiteAccessLevel.ADMINISTRATOR);
    final PageManager pageVersion = TestUtil.createPageVersionAndPage(site);

    final ContactUs contactUs = TestUtil.createContactUs(site);

    WidgetItem widget = TestUtil.createTextWidget();
    widget.setPosition(0);
    persistance.putWidget(widget);
    pageVersion.addWidget(widget);

    final CreateContactUsWidgetRequest request = new CreateContactUsWidgetRequest();
    request.setContactUsName("name");
    request.setDisplayHeader(true);
    request.setEmail("[email protected]");
    request.setHeader("header");
    request.setWidgetId(widget.getWidgetId());
    request.setContactUsId(contactUs.getId());

    DraftFormItem item = new DraftFormItem();
    item.setPosition(0);
    item.setRequired(true);
    item.setFormItemName(FormItemName.FIRST_NAME);
    ServiceLocator.getPersistance().putFormItem(item);
    List<DraftFormItem> items = new ArrayList<DraftFormItem>();
    items.add(item);
    request.setFormItems(items);

    final FunctionalWidgetInfo response = service.execute(request);

    Assert.assertNotNull(response);
    Assert.assertEquals(widget.getWidgetId(), response.getWidget().getWidgetId());
    Assert.assertEquals("name", contactUs.getName());
    Assert.assertEquals("header", contactUs.getDescription());
    Assert.assertTrue(contactUs.isShowDescription());
    Assert.assertEquals(FormType.CONTACT_US, contactUs.getType());
  }