@Test
  public void executeFromManageItems() throws ServletException, IOException {
    final Site site = TestUtil.createSite();
    TestUtil.createUserAndUserOnSiteRightAndLogin(site, SiteAccessLevel.ADMINISTRATOR);

    final ContactUs contactUs = TestUtil.createContactUs(site);

    final CreateContactUsWidgetRequest request = new CreateContactUsWidgetRequest();
    request.setContactUsName("name");
    request.setDisplayHeader(true);
    request.setEmail("[email protected]");
    request.setHeader("header");
    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.assertNull(response.getWidget());
    Assert.assertEquals("name", contactUs.getName());
    Assert.assertEquals("header", contactUs.getDescription());
    Assert.assertTrue(contactUs.isShowDescription());
    Assert.assertEquals(FormType.CONTACT_US, contactUs.getType());
  }
  @Test(expected = InvalidContactUsEmailException.class)
  public void executeWithoutEmail() throws ServletException, IOException {
    final Site site = TestUtil.createSite();
    TestUtil.createUserAndUserOnSiteRightAndLogin(site, SiteAccessLevel.ADMINISTRATOR);

    final ContactUs contactUs = TestUtil.createContactUs(site);

    final CreateContactUsWidgetRequest request = new CreateContactUsWidgetRequest();
    request.setContactUsName("name");
    request.setDisplayHeader(true);
    request.setEmail(null);
    request.setHeader("header");
    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);

    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(expected = ContactUsNotFoundException.class)
  public void executeWithNotFoundContactUs() 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);

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

    service.execute(request);
  }