@Test
  public void removeForumFromForumWidget() {
    DraftForum forum = new DraftForum();
    forum.setName("name");
    persistance.putItem(forum);

    Site site = new Site();
    site.getSitePaymentSettings().setUserId(-1);
    site.setTitle("f");
    site.getThemeId().setTemplateDirectory("f");
    site.getThemeId().setThemeCss("f");
    site.setSubDomain("f");
    persistance.putSite(site);

    Page page = TestUtil.createPage(site);
    PageManager pageVersion = new PageManager(page);

    WidgetItem widgetForum = new WidgetItem();
    widgetForum.setDraftItem(forum);
    persistance.putWidget(widgetForum);
    pageVersion.addWidget(widgetForum);

    persistance.removeDraftItem(forum);

    Assert.assertNull(persistance.getDraftItem(forum.getId()));
    Assert.assertNotNull(widgetForum.getDraftItem());
  }
  @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
  public void executeWithSEOInGallery() throws IOException, ServletException {
    final Site site = TestUtil.createSite();
    final PageManager pageVersion = new PageManager(TestUtil.createPage(site));
    final Gallery gallery = TestUtil.createGallery(site);
    final WidgetItem galleryWidget = TestUtil.createWidgetItem();
    galleryWidget.setDraftItem((DraftItem) gallery);
    pageVersion.addWidget(galleryWidget);

    final DraftForm galleryForm = TestUtil.createCustomForm(site);
    TestUtil.createFormItem(FormItemName.SEO_KEYWORDS, galleryForm, 0);

    gallery.setFormId1(galleryForm.getFormId());

    final FilledForm filledForm = TestUtil.createFilledForm(galleryForm);
    final FilledFormItem filledFormItem = TestUtil.createFilledFormItem(FormItemName.SEO_KEYWORDS);
    filledFormItem.setValue("seo1;seo2;seo3");
    filledForm.addFilledFormItem(filledFormItem);

    stringBuilder.append("<!-- PAGE_HEADER -->");

    MockHttpServletRequest mockRequest = new MockHttpServletRequest("", "");
    mockRequest.setAttribute(
        "currentDisplayedFilledFormId" + gallery.getId(), filledForm.getFilledFormId());
    RenderContext context = new RenderContext(mockRequest, null, null, null, false);

    final Render render = new RenderKeywordsMetaTags(pageVersion, SiteShowOption.ON_USER_PAGES);
    render.execute(context, stringBuilder);

    Assert.assertEquals(
        "<meta name=\"keywords\" content=\"seo1, seo2, seo3\">\n" + "<!-- PAGE_HEADER -->",
        stringBuilder.toString());
  }
  @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());
  }