private String validateConfig(ContentHandlerName contentHandlerName, String xmlData) {
    org.jdom.Element configEl;

    try {
      org.jdom.Element contentTypeEl = JDOMUtil.parseDocument(xmlData).getRootElement();
      org.jdom.Element moduleDataEl = contentTypeEl.getChild("moduledata");
      if (moduleDataEl == null) {
        configEl = contentTypeEl.getChild("config");
      } else {
        configEl = moduleDataEl.getChild("config");
      }

    } catch (IOException e) {
      throw new RuntimeException("Failed to validate content type config", e);
    } catch (JDOMException e) {
      throw new RuntimeException("Failed to validate content type config", e);
    }

    if (configEl != null) {
      // Parse the content type config... the parser will throw exceptions if anything is not
      // correctly written
      try {
        if (contentHandlerName.equals(ContentHandlerName.CUSTOM)) {
          final ContentTypeConfig contentTypeConfig =
              ContentTypeConfigParser.parse(contentHandlerName, configEl);
          contentTypeConfig.validate();
        }
      } catch (InvalidContentTypeConfigException e) {
        return e.getMessage();
      }
    }

    return null;
  }
  @Test
  public void testUpdateCurrentVersion() {
    ContentKey relatedContentKey1 = storeSimpleContent("rel1");
    ContentKey relatedContentKey2 = storeSimpleContent("rel2");
    ContentKey relatedContentKey3 = storeSimpleContent("rel3");
    ContentKey relatedContentKey4 = storeSimpleContent("rel4");
    ContentKey relatedContentKey5 = storeSimpleContent("rel5");

    ContentEntity content = factory.createContent("MyCategory", "en", "testuser", "0", new Date());
    ContentVersionEntity version = factory.createContentVersion("0", "testuser");

    ContentTypeConfig contentTypeConfig =
        ContentTypeConfigParser.parse(ContentHandlerName.CUSTOM, configEl);
    CustomContentData contentData = new CustomContentData(contentTypeConfig);
    TextDataEntryConfig titleConfig =
        new TextDataEntryConfig("myTitle", true, "Tittel", "contentdata/mytitle");
    contentData.add(new TextDataEntry(titleConfig, "test title"));

    RelatedContentDataEntryConfig multipleRelatedContentsConfig =
        (RelatedContentDataEntryConfig)
            contentTypeConfig.getInputConfig("myMultipleRelatedContent");

    contentData.add(
        new RelatedContentsDataEntry(multipleRelatedContentsConfig)
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey1))
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey2)));

    RelatedContentDataEntryConfig soleRelatedConfig =
        (RelatedContentDataEntryConfig) contentTypeConfig.getInputConfig("mySoleRelatedContent");

    contentData.add(new RelatedContentDataEntry(soleRelatedConfig, relatedContentKey3));

    version.setContentData(contentData);

    UserEntity runningUser = fixture.findUserByName("testuser");

    CreateContentCommand createContentCommand = new CreateContentCommand();
    createContentCommand.setCreator(runningUser);

    createContentCommand.populateCommandWithContentValues(content);
    createContentCommand.populateCommandWithContentVersionValues(version);

    createContentCommand.setBinaryDatas(new ArrayList<BinaryDataAndBinary>());
    createContentCommand.setUseCommandsBinaryDataToAdd(true);

    ContentKey contentKey = contentService.createContent(createContentCommand);

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    ContentEntity persistedContent = contentDao.findByKey(contentKey);
    assertNotNull(persistedContent);

    ContentVersionEntity persistedVersion = persistedContent.getMainVersion();
    assertNotNull(persistedVersion);

    assertEquals(3, persistedVersion.getRelatedChildren(true).size());

    ContentEntity changedContent =
        factory.createContent("MyCategory", "en", "testuser", "0", new Date());
    changedContent.setKey(contentKey);
    ContentVersionEntity changedVersion = factory.createContentVersion("0", "testuser");
    changedVersion.setKey(persistedVersion.getKey());

    CustomContentData changedCD = new CustomContentData(contentTypeConfig);

    TextDataEntryConfig changedTitleConfig =
        new TextDataEntryConfig("myTitle", true, "Tittel", "contentdata/mytitle");
    changedCD.add(new TextDataEntry(changedTitleConfig, "changed title"));

    changedCD.add(
        new RelatedContentsDataEntry(multipleRelatedContentsConfig)
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey3))
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey5)));

    changedCD.add(new RelatedContentDataEntry(soleRelatedConfig, relatedContentKey4));

    changedVersion.setContentData(changedCD);

    UpdateContentCommand updateContentCommand =
        UpdateContentCommand.updateExistingVersion2(persistedVersion.getKey());
    updateContentCommand.setModifier(runningUser);
    updateContentCommand.setUpdateAsMainVersion(false);

    updateContentCommand.populateContentValuesFromContent(persistedContent);
    updateContentCommand.populateContentVersionValuesFromContentVersion(changedVersion);

    contentService.updateContent(updateContentCommand);

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    ContentEntity contentAfterUpdate = contentDao.findByKey(contentKey);
    ContentVersionEntity versionAfterUpdate =
        contentVersionDao.findByKey(persistedVersion.getKey());

    Document contentDataXmlAfterUpdate = versionAfterUpdate.getContentDataAsJDomDocument();

    AssertTool.assertXPathEquals(
        "/contentdata/mysolerelatedcontent/@key",
        contentDataXmlAfterUpdate,
        relatedContentKey4.toString());
    AssertTool.assertXPathEquals(
        "/contentdata/myrelatedcontents/content[1]/@key",
        contentDataXmlAfterUpdate,
        relatedContentKey3.toString());
    AssertTool.assertXPathEquals(
        "/contentdata/myrelatedcontents/content[2]/@key",
        contentDataXmlAfterUpdate,
        relatedContentKey5.toString());

    assertEquals(3, versionAfterUpdate.getRelatedChildren(true).size());
  }