@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()); }
public FormData(final FilledForm filledForm) { description = filledForm.getFormDescription(); final DraftForm form = ServiceLocator.getPersistance().getFormById(filledForm.getFormId()); formId = form.getFormId(); formName = form.getName(); showDescription = form.isShowDescription(); termsAndConditions = form instanceof DraftRegistrationForm ? ((DraftRegistrationForm) form).getTermsAndConditions() : null; requireTermsAndConditions = form instanceof DraftRegistrationForm && ((DraftRegistrationForm) form).isRequireTermsAndConditions(); updateChildSiteRegistrationFields(form); this.formItems = FormItemsManager.createFormItemsByFilledForm(filledForm, form); }
@Test public void execute() throws Exception { TestUtil.createUserAndLogin(); final Site site = TestUtil.createSite(); final PageManager pageVersion = TestUtil.createPageVersionSiteUser(); Widget widgetCustomForm = TestUtil.createCustomFormWidget(pageVersion); final DraftCustomForm customForm = TestUtil.createCustomForm(site); final List<FilledFormItem> filledFormItems = TestUtil.createFilledFormItems(FormItemName.FIRST_NAME, FormItemName.LAST_NAME); filledFormItems.get(0).setValue("FN1"); filledFormItems.get(1).setValue("LN1"); final SubmitCustomFormRequest request = new SubmitCustomFormRequest(); request.setFormId(customForm.getFormId()); request.setWidgetId(widgetCustomForm.getWidgetId()); request.setFilledFormItems(new ArrayList<FilledFormItem>()); request.setVerificationCode("aaaaaa"); request.setFilledFormItems(filledFormItems); ServiceLocator.getSessionStorage() .setNoBotCode(null, "customForm" + widgetCustomForm.getWidgetId(), "aaaaaa"); final SubmitCustomFormResponse response = service.execute(request); Assert.assertNull(response.getNextPageHtml()); final FilledForm filledCustomForm = ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId()); Assert.assertNotNull(filledCustomForm); Assert.assertEquals( filledFormItems.get(0).getValues(), filledCustomForm.getFilledFormItems().get(0).getValues()); Assert.assertEquals( filledFormItems.get(1).getValues(), filledCustomForm.getFilledFormItems().get(1).getValues()); }
@DefaultHandler public Resolution upload() { try { if (fileData == null || filledFormId < 1) { throw new UnsupportedOperationException(); } final FilledForm filledForm = persistance.getFilledFormById(filledFormId); final DraftForm form = persistance.getFormById(filledForm.getFormId()); final FilledFormItem filledFormItem = FilledFormManager.getFilledFormItemByItemPosition(filledForm, position); final FormVideo formVideo = getFormVideoOrCreateNew(filledFormItem); final int siteId = form.getSiteId(); final SourceVideoFileCreator sourceVideoFileCreator = new SourceVideoFileCreator( siteId, FileNameUtil.createExtension(fileData.getFileName()), fileData.getFileName(), fileData.getInputStream()); final Video video = sourceVideoFileCreator.execute(); persistanceTransaction.execute( new PersistanceTransactionContext<Void>() { public Void execute() { if (formItemName == FormItemName.VIDEO_FILE_UPLOAD) { try { video.setFilledFormId(filledForm.getFilledFormId()); video.setFilledFormItemId(filledFormItem.getItemId()); formVideo.setVideoId(video.getVideoId()); FlvVideoManager.getFlvVideoOrCreateNew( video.getVideoId(), video.getSourceWidth(), video.getSourceHeight(), formVideo.getQuality(), video.getSiteId()); } catch (Exception exception) { logger.log(Level.SEVERE, "Can`t create video file!", exception); } } else if (formItemName == FormItemName.IMAGE_FILE_UPLOAD) { formVideo.setImageId((new CreateFormFileUtil().createFormFile(fileData, siteId))); } return null; } }); ServiceLocator.getPersistanceTransaction() .execute( new Runnable() { public void run() { GalleriesManager.updateVideoFilesForGalleriesThatUseCurentForm( filledForm.getFormId()); } }); } catch (Exception exception1) { try { this.getContext().getResponse().getOutputStream().println("-200"); } catch (Exception exception2) { logger.log(Level.SEVERE, "Error while writing file", exception2); } logger.log(Level.SEVERE, "Error while writing file", exception1); return resolutionCreator.forwardToUrl("/SWFUpload/error.jsp"); } return resolutionCreator.forwardToUrl("/SWFUpload/success.jsp"); }
@Test public void testExecute_WithFirstState() throws Exception { ServiceLocator.getConfigStorage().get().setUserSitesUrl("web-deva.com"); User user = TestUtil.createUser(); user.setActiveted(null); Site parentSite = TestUtil.createSite(); DraftChildSiteRegistration registration = TestUtil.createChildSiteRegistration(parentSite); ChildSiteSettings settings = TestUtil.createChildSiteSettings(registration, parentSite); settings.setCreatedDate(new Date()); settings.setUserId(user.getUserId()); settings.setConfirmCode("confirm"); settings.setAccessLevel(SiteAccessLevel.ADMINISTRATOR); FilledForm filledForm = TestUtil.createFilledForm(registration.getFormId()); FilledFormItem filledFormItemDomainName = TestUtil.createFilledFormItem(FormItemName.YOUR_OWN_DOMAIN_NAME); List<String> values = Arrays.asList("domainName"); filledFormItemDomainName.setValues(values); FilledFormItem filledFormItemSiteName = TestUtil.createFilledFormItem(FormItemName.YOUR_PAGE_SITE_NAME); List<String> siteNameValues = Arrays.asList("siteName"); filledFormItemSiteName.setValues(siteNameValues); filledForm.setFilledFormItems(Arrays.asList(filledFormItemDomainName, filledFormItemSiteName)); settings.setFilledFormId(filledForm.getFilledFormId()); action.setSettingsId(settings.getChildSiteSettingsId()); action.setConfirmCode("confirm"); DraftChildSiteRegistration childSiteRegistration = TestUtil.createChildSiteRegistration("name", "comment"); Site blueprint = TestUtil.createBlueprint(); childSiteRegistration.setBlueprintsId(Arrays.asList(blueprint.getSiteId())); settings.setRequiredToUseSiteBlueprint(true); final SitePaymentSettings sitePaymentSettings = new SitePaymentSettings(); sitePaymentSettings.setSiteStatus(SiteStatus.ACTIVE); settings.setSitePaymentSettings(sitePaymentSettings); settings.setChildSiteRegistration(childSiteRegistration); Assert.assertNull(user.getActiveted()); Assert.assertNull(new UsersManager().getLoginedUser()); Assert.assertNull(ServiceLocator.getPersistance().getSiteBySubDomain("domainname")); ForwardResolution resolutionMock = (ForwardResolution) action.show(); Assert.assertNotNull(new UsersManager().getLoginedUser()); Assert.assertEquals(user, new UsersManager().getLoginedUser()); Assert.assertEquals( "/account/registration/childSiteRigistrationConfirmationFirstState.jsp", resolutionMock.getPath()); Assert.assertNotNull(user.getActiveted()); Assert.assertNotNull(new UsersManager().getLoginedUser()); Assert.assertEquals(user, new UsersManager().getLoginedUser()); Site site = ServiceLocator.getPersistance().getSiteBySubDomain("domainname"); Assert.assertNotNull(site); Assert.assertNotNull(new UserRightManager(user).toSite(site).getSiteAccessType()); Assert.assertEquals( settings.getAccessLevel(), new UserRightManager(user).toSite(site).getSiteAccessType()); Assert.assertEquals("domainname", site.getSubDomain()); Assert.assertEquals("http://domainname.web-deva.com", action.getUrl()); Assert.assertNotNull(action.getTellFriendHtml()); Assert.assertEquals(2, site.getPages().size()); Assert.assertEquals("siteName", site.getTitle()); Assert.assertEquals(blueprint, site.getBlueprintParent()); }
@Test public void executeWithPageBreaks() throws Exception { TestUtil.createUserAndLogin(); final Site site = TestUtil.createSite(); final PageManager pageVersion = TestUtil.createPageVersionSiteUser(); Widget widgetCustomForm = TestUtil.createCustomFormWidget(pageVersion); final DraftCustomForm customForm = TestUtil.createCustomForm(site); final List<DraftFormItem> formItems = new ArrayList<DraftFormItem>(); formItems.add(TestUtil.createFormItem(FormItemName.FIRST_NAME, 0)); formItems.add(TestUtil.createFormItem(FormItemName.PAGE_BREAK, 1)); formItems.add(TestUtil.createFormItem(FormItemName.LAST_NAME, 2)); customForm.setFormItems(formItems); // FIRST PAGE List<FilledFormItem> filledFormItems = TestUtil.createFilledFormItems(FormItemName.FIRST_NAME); filledFormItems.get(0).setValue("FN1"); SubmitCustomFormRequest request = new SubmitCustomFormRequest(); request.setFormId(customForm.getFormId()); request.setWidgetId(widgetCustomForm.getWidgetId()); request.setFilledFormItems(new ArrayList<FilledFormItem>()); request.setRequestNextPage(true); request.setPageBreaksToPass(1); request.setVerificationCode("aaaaaa"); request.setFilledFormItems(filledFormItems); ServiceLocator.getSessionStorage() .setNoBotCode(null, "customForm" + widgetCustomForm.getWidgetId(), "aaaaaa"); SubmitCustomFormResponse response = service.execute(request); Assert.assertNotNull(response.getNextPageHtml()); FilledForm filledContactUsForm = ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId()); Assert.assertNotNull(filledContactUsForm); Assert.assertEquals( filledFormItems.get(0).getValues(), filledContactUsForm.getFilledFormItems().get(0).getValues()); // SECOND PAGE filledFormItems = TestUtil.createFilledFormItems(FormItemName.LAST_NAME); filledFormItems.get(0).setValue("LN1"); request = new SubmitCustomFormRequest(); request.setFormId(customForm.getFormId()); request.setWidgetId(widgetCustomForm.getWidgetId()); request.setFilledFormItems(new ArrayList<FilledFormItem>()); request.setRequestNextPage(true); request.setFilledFormId(response.getFilledFormId()); request.setPageBreaksToPass(2); request.setFilledFormItems(filledFormItems); response = service.execute(request); // Ok, now after we have filled out last form page we need to show first form page again with // the // message about successfull form submit. Assert.assertNotNull(response.getNextPageHtml()); Assert.assertTrue(response.isShowSuccessfullSubmitMessage()); filledContactUsForm = ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId()); Assert.assertEquals( filledFormItems.get(0).getValues(), filledContactUsForm.getFilledFormItems().get(1).getValues()); }
@Test public void executeWithPageBreaksFromAddRecord() throws Exception { TestUtil.createUserAndLogin(); final Site site = TestUtil.createSite(); final DraftCustomForm customForm = TestUtil.createCustomForm(site); final List<DraftFormItem> formItems = new ArrayList<DraftFormItem>(); formItems.add(TestUtil.createFormItem(FormItemName.FIRST_NAME, 0)); formItems.add(TestUtil.createFormItem(FormItemName.PAGE_BREAK, 1)); formItems.add(TestUtil.createFormItem(FormItemName.LAST_NAME, 2)); customForm.setFormItems(formItems); // FIRST PAGE List<FilledFormItem> filledFormItems = TestUtil.createFilledFormItems(FormItemName.FIRST_NAME); filledFormItems.get(0).setValue("FN1"); SubmitCustomFormRequest request = new SubmitCustomFormRequest(); request.setFormId(customForm.getFormId()); request.setWidgetId(0); request.setFilledFormItems(new ArrayList<FilledFormItem>()); request.setRequestNextPage(true); request.setPageBreaksToPass(1); request.setVerificationCode("aaaaaa"); request.setFilledFormItems(filledFormItems); request.setShowFromAddRecord(true); SubmitCustomFormResponse response = service.execute(request); Assert.assertEquals( "/site/showCustomForm.action?formId=" + request.getFormId() + "&showFromAddRecord=true" + "&pageBreaksToPass="******"&filledFormToUpdateId=" + response.getFilledFormId(), response.getNextPageHtml()); FilledForm filledContactUsForm = ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId()); Assert.assertNotNull(filledContactUsForm); Assert.assertEquals( filledFormItems.get(0).getValues(), filledContactUsForm.getFilledFormItems().get(0).getValues()); // SECOND PAGE filledFormItems = TestUtil.createFilledFormItems(FormItemName.LAST_NAME); filledFormItems.get(0).setValue("LN1"); request = new SubmitCustomFormRequest(); request.setFormId(customForm.getFormId()); request.setWidgetId(0); request.setFilledFormItems(new ArrayList<FilledFormItem>()); request.setShowFromAddRecord(true); request.setRequestNextPage(true); request.setFilledFormId(response.getFilledFormId()); request.setPageBreaksToPass(2); request.setFilledFormItems(filledFormItems); response = service.execute(request); Assert.assertNull(response.getNextPageHtml()); filledContactUsForm = ServiceLocator.getPersistance().getFilledFormById(response.getFilledFormId()); Assert.assertEquals( filledFormItems.get(0).getValues(), filledContactUsForm.getFilledFormItems().get(1).getValues()); }