@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 void createNotEmptyValidation(DDMFormField ddmFormField) {
    DDMFormFieldValidation ddmFormFieldValidation = new DDMFormFieldValidation();

    ddmFormFieldValidation.setErrorMessage(
        "Field " + ddmFormField.getName() + " must not be empty.");
    ddmFormFieldValidation.setExpression("!" + ddmFormField.getName() + ".isEmpty()");

    ddmFormField.setDDMFormFieldValidation(ddmFormFieldValidation);
  }
  @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());
    }
  }