@Test(expected = DDMFormValuesValidationException.RequiredValue.class) public void testUpdateWithInvalidDDMFormValues() throws Exception { DDMStructure structure = addStructure(_CLASS_NAME_ID, "Default Structure"); DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField("text", false, false, true); ddmForm.addDDMFormField(ddmFormField); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue("text", "text value"); ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue); long classPK = _jsonStorageAdapter.create( TestPropsValues.getCompanyId(), structure.getStructureId(), ddmFormValues, ServiceContextTestUtil.getServiceContext(group.getGroupId())); ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm); _jsonStorageAdapter.update( classPK, ddmFormValues, ServiceContextTestUtil.getServiceContext(group.getGroupId())); }
@Test public void testCreateWithValidDDMFieldValue() throws Exception { DDMStructure structure = addStructure(_CLASS_NAME_ID, "Default Structure"); DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField("text", false, false, false); DDMFormFieldValidation ddmFormFieldValidation = new DDMFormFieldValidation(); ddmFormFieldValidation.setExpression("!text.isEmpty()"); ddmFormFieldValidation.setErrorMessage("custom validation error message"); ddmFormField.setDDMFormFieldValidation(ddmFormFieldValidation); ddmForm.addDDMFormField(ddmFormField); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue("text", "not empty"); ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue); _jsonStorageAdapter.create( TestPropsValues.getCompanyId(), structure.getStructureId(), ddmFormValues, ServiceContextTestUtil.getServiceContext(group.getGroupId())); }
protected DDMForm getDDMForm(DDMStructure ddmStructure, boolean requireCaptcha) { DDMForm ddmForm = ddmStructure.getDDMForm(); if (requireCaptcha) { DDMFormField captchaDDMFormField = new DDMFormField(_DDM_FORM_FIELD_NAME_CAPTCHA, "captcha"); captchaDDMFormField.setDataType("string"); captchaDDMFormField.setProperty("url", createCaptchaResourceURL()); ddmForm.addDDMFormField(captchaDDMFormField); } return ddmForm; }
@Test public void testCreateWithInvalidDDMFieldValue() throws Exception { DDMStructure structure = addStructure(_CLASS_NAME_ID, "Default Structure"); DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField("text", false, false, false); DDMFormFieldValidation ddmFormFieldValidation = new DDMFormFieldValidation(); ddmFormFieldValidation.setExpression("text.contains(\"test\")"); ddmFormFieldValidation.setErrorMessage("custom validation error message"); ddmFormField.setDDMFormFieldValidation(ddmFormFieldValidation); ddmForm.addDDMFormField(ddmFormField); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues(ddmForm); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue("text", "text value"); ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue); try { _jsonStorageAdapter.create( TestPropsValues.getCompanyId(), structure.getStructureId(), ddmFormValues, ServiceContextTestUtil.getServiceContext(group.getGroupId())); Assert.fail(); } catch (DDMFormValuesValidationException.MustSetValidValues msvv) { List<DDMFormFieldEvaluationResult> ddmFormFieldEvaluationResults = msvv.getDDMFormFieldEvaluationResults(); Assert.assertEquals(1, ddmFormFieldEvaluationResults.size()); DDMFormFieldEvaluationResult ddmFormFieldEvaluationResult = ddmFormFieldEvaluationResults.get(0); Assert.assertEquals("text", ddmFormFieldEvaluationResult.getName()); Assert.assertEquals( "custom validation error message", ddmFormFieldEvaluationResult.getErrorMessage()); } }