<commit_before>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.i18n;

import org.opencms.gwt.I_CmsClientMessageBundle;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsStringUtil;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import junit.framework.TestCase;

/**
 * Tests for the CmsMessageBundles.<p>
 * 
 * @since 6.0.0
 */
public abstract class TestCmsMessageBundles extends TestCase {

    /** Prefix for the error messages in the bundles. */
    private static final String KEY_PREFIX_ERR = "ERR_";

    /** Prefix for the gui messages in the bundles. */
    private static final String KEY_PREFIX_GUI = "GUI_";

    /** Prefix for the initialization messages in the bundles. */
    private static final String KEY_PREFIX_INIT = "INIT_";

    /** Prefix for the log messages in the bundles. */
    private static final String KEY_PREFIX_LOG = "LOG_";

    /** Prefix for the report messages in the bundles. */
    private static final String KEY_PREFIX_RPT = "RPT_";

    /** The source folder to copy the resource bundles from. */
    private static final String SOURCE_FOLDER_INFIX = "/resources/system/workplace/locales/";

    /** The source folder to copy the resource bundles from. */
    private static final String SOURCE_FOLDER_PREFIX = "modules/org.opencms.locale.";

    /** The source folder to copy the resource bundles from. */
    private static final String SOURCE_FOLDER_SUFFIX = "/messages/";

    /** The taget folder to copy the resource bundles to. */
    private static final String TARGET_FOLDER = "bin/";

    /** Cache the resource bundle to exclude from additional locales tests. */
    private Map<Locale, List<I_CmsMessageBundle>> m_excludedBundles = new HashMap<Locale, List<I_CmsMessageBundle>>();

    /**
     * Checks all message bundles for the DE locale.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testLocale_DE_MessagesBundles() throws Exception {

        messagesBundleConstantTest(Locale.GERMAN);
    }

    /**
     * Checks all message bundles for the EN locale.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testLocale_EN_MessagesBundles() throws Exception {

        messagesBundleConstantTest(Locale.ENGLISH);
    }

    /**
     * Checks all message bundles for the ES locale.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testLocale_ES_MessagesBundles() throws Exception {

        messagesBundleConstantTest(new Locale("es"));
    }

    /**
     * Performs some key and language independent tests.<p>
     * 
     * @param className the bundle implementing class name
     * @param bundleName the bundle name to test
     * @param locale the locale to test<commit_msg>Removed Spanish message bundle from test cases.<commit_after>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.i18n;

import org.opencms.gwt.I_CmsClientMessageBundle;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsStringUtil;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import junit.framework.TestCase;

/**
 * Tests for the CmsMessageBundles.<p>
 * 
 * @since 6.0.0
 */
public abstract class TestCmsMessageBundles extends TestCase {

    /** Prefix for the error messages in the bundles. */
    private static final String KEY_PREFIX_ERR = "ERR_";

    /** Prefix for the gui messages in the bundles. */
    private static final String KEY_PREFIX_GUI = "GUI_";

    /** Prefix for the initialization messages in the bundles. */
    private static final String KEY_PREFIX_INIT = "INIT_";

    /** Prefix for the log messages in the bundles. */
    private static final String KEY_PREFIX_LOG = "LOG_";

    /** Prefix for the report messages in the bundles. */
    private static final String KEY_PREFIX_RPT = "RPT_";

    /** The source folder to copy the resource bundles from. */
    private static final String SOURCE_FOLDER_INFIX = "/resources/system/workplace/locales/";

    /** The source folder to copy the resource bundles from. */
    private static final String SOURCE_FOLDER_PREFIX = "modules/org.opencms.locale.";

    /** The source folder to copy the resource bundles from. */
    private static final String SOURCE_FOLDER_SUFFIX = "/messages/";

    /** The taget folder to copy the resource bundles to. */
    private static final String TARGET_FOLDER = "bin/";

    /** Cache the resource bundle to exclude from additional locales tests. */
    private Map<Locale, List<I_CmsMessageBundle>> m_excludedBundles = new HashMap<Locale, List<I_CmsMessageBundle>>();

    /**
     * Checks all message bundles for the DE locale.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testLocale_DE_MessagesBundles() throws Exception {

        messagesBundleConstantTest(Locale.GERMAN);
    }

    /**
     * Checks all message bundles for the EN locale.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testLocale_EN_MessagesBundles() throws Exception {

        messagesBundleConstantTest(Locale.ENGLISH);
    }

    /**
     * Performs some key and language independent tests.<p>
     * 
     * @param className the bundle implementing class name
     * @param bundleName the bundle name to test
     * @param locale the locale to test
{'fraction_non_alphanumeric': 0.08358061325420375, 'fraction_numerical': 0.0051928783382789315, 'mean_word_length': 3.454295154185022, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2361017', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2192, 'n_words': 868}