Skip to content

Commit

Permalink
Add test to check encoding of message properties
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Dec 3, 2024
1 parent 68b5975 commit a7cba1a
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Kitodo/src/main/resources/messages/errors_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ error=Fehler...
errors=Fehler

# A
errorAdding=Fehler beim Hinzuf\u00FCgen von ''{0}''
errorAdding=Fehler beim Hinzufügen von ''{0}''
authorityAssignedError=Berechtigung kann nicht gel\u00F6scht werden, da dieser noch Rollen zugewiesen sind.

# B
batchPropertyEmpty=Die Eigenschaft {0} im Vorgang {1} ist ein Pflichtfeld, enth\u00E4lt aber keinen Wert.
batchPropertyEmpty=Die Eigenschaft {0} im Vorgang {1} ist ein Pflichtfeld, enthält aber keinen Wert.

# C
calendar.upload.error=Fehler beim Laden der Datei\:
calendar.upload.isEmpty=Es wurde keine Datei \u00FCbertragen.
calendar.upload.isEmpty=Es wurde keine Datei übertragen.
calendar.upload.missingMandatoryElement=Ein erforderliches XML-Element konnte nicht gefunden werden.
calendar.upload.missingMandatoryValue=Ein erforderlicher Wert konnte nicht gefunden werden.
calendar.upload.overlappingDateRanges=Der Erscheinungsverlauf konnte nicht importiert werden, da sich Datumsbereiche von Bl\u00F6cken \u00FCberlappen\:
Expand Down Expand Up @@ -98,7 +98,7 @@ kitodoScript.importProcesses.indir.isNull=Parameter ''indir'' fehlt!
kitodoScript.importProcesses.indir.isNoDirectory=''indir'' ist kein existierendes Verzeichnis!
kitodoScript.importProcesses.indir.cannotExecute=Der Inhalt des Importverzeichnisses kann nicht abgerufen werden (fehlende Berechtigung \u201Cexecute\u201D)
kitodoScript.importProcesses.missingChildren=Vorgang {0} enth\u004E Verweise auf fehlendene Kindvorg\u004Enge {1}
kitodoScript.importProcesses.noProcessTitleRule=Regelsatz gibt keine Bildungsvorschrift für den ''processTitle'' für Division {0} an!
kitodoScript.importProcesses.noProcessTitleRule=Regelsatz gibt keine Bildungsvorschrift für den ''processTitle'' für Division {0} an!
kitodoScript.importProcesses.project.isNull=Parameter ''project'' fehlt!
kitodoScript.importProcesses.project.isNoProjectID=''project'' ist keine g\u00FCltige Projekt-ID
kitodoScript.importProcesses.project.noProjectWithID=Ein solches Projekt existiert nicht!
Expand Down
2 changes: 1 addition & 1 deletion Kitodo/src/main/resources/messages/errors_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ kitodoScript.importProcesses.project.noProjectWithID=¡El proyecto con ese ID no
kitodoScript.importProcesses.template.isNull=¡Falta la variable ''template''!
kitodoScript.importProcesses.template.isNoTemplateID=¡''template'' no es un entero!
kitodoScript.importProcesses.template.noTemplateWithID=No existe la plantilla con este ID
kitodoScript.noStructureOfTypeFound=No se encontró ningún elemento estructurado de tipo "{0}"
kitodoScript.noStructureOfTypeFound=No se encontró ningún elemento estructurado de tipo "{0}"

# L
errorLoadingDocTypes=Error de configuración del conjunto de reglas: No se ha encontrado ningún DocType ('division')
Expand Down
4 changes: 2 additions & 2 deletions Kitodo/src/main/resources/messages/password_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
# GPL3-License.txt file that was distributed with this source code.
#

HISTORY_VIOLATION=Passwort entspricht einem von %1$s der vorherigen Passw\u00F6rter.
HISTORY_VIOLATION=Passwort entspricht einem von %1$s der vorherigen Passwörter.
ILLEGAL_WORD=Passwort enth\u00E4lt das W\u00F6rterbuchwort '%1$s'.
ILLEGAL_WORD_REVERSED=Passwort enth\u00E4lt das umgekehrte W\u00F6rterbuchwort '%1$s'.
ILLEGAL_MATCH=Passwort stimmt mit dem ung\u00FCltigen Muster \u00FCberein '%1$s'.
ALLOWED_MATCH=Passwort muss dem Muster '%1$s' entsprechen.
ILLEGAL_CHAR=Passwort enth\u00E4lt das unzul\u00E4ssige Zeichen '%1$s'.
ALLOWED_CHAR=Passwort enth\u00E4lt das unzul\u00E4ssige Zeichen '%1$s'.
ILLEGAL_SEQUENCE=Passwort enth\u00E4lt die ung\u00FCltige Sequenz '%1$s'.
ILLEGAL_USERNAME=Passwort enth\u00E4lt die Benutzer-ID '%1$s'.
ILLEGAL_USERNAME=Passwort enthält die Benutzer-ID '%1$s'.
ILLEGAL_USERNAME_REVERSED=Passwort enth\u00E4lt die umgekehrte Benutzer-ID '%1$s'.
ILLEGAL_WHITESPACE=Passwort darf keine Leerzeichen enthalten.
INSUFFICIENT_UPPERCASE=Passwort muss mindestens %1$s Gro\u00DFbuchstaben enthalten.
Expand Down
40 changes: 20 additions & 20 deletions Kitodo/src/main/resources/messages/password_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
# GPL3-License.txt file that was distributed with this source code.
#

HISTORY_VIOLATION=La contraseña corresponde a uno de los %1$s de las contraseñas anteriores.
ILLEGAL_WORD=La contraseña contiene la palabra del diccionario '%1$s'.
ILLEGAL_WORD_REVERSED=La contraseña contiene la palabra invertida del diccionario '%1$s'.
ILLEGAL_MATCH=La contraseña coincide con el modelo no válido '%1$s'.
ALLOWED_MATCH=La contraseña debe coincidir con el modelo '%1$s'.
ILLEGAL_CHAR=La contraseña contiene el carácter inválida '%1$s'.
ALLOWED_CHAR=La contraseña contiene el carácter permitido '%1$s'.
ILLEGAL_SEQUENCE=La contraseña contiene la secuencia inválida '%1$s'.
ILLEGAL_USERNAME=La contraseña contiene la identificación del usuario '%1$s'.
ILLEGAL_USERNAME_REVERSED=La contraseña contiene la identificación invertida del usuario '%1$s'.
ILLEGAL_WHITESPACE=La contraseña no debe contener espacios.
INSUFFICIENT_UPPERCASE=La contraseña debe contener al menos %1$s letras mayúsculas.
INSUFFICIENT_LOWERCASE=La contraseña debe contener al menos %1$s letras minúsculas.
INSUFFICIENT_ALPHABETICAL=La contraseña debe contener al menos %1$s caracteres alfabéticos.
INSUFFICIENT_DIGIT=La contraseña debe contener al menos %1$s dígitos.
INSUFFICIENT_SPECIAL=La contraseña debe contener al menos %1$s caracteres especiales.
INSUFFICIENT_CHARACTERISTICS=La contraseña coincide con %1$s de %3$s reglas de caracteres, pero %2$s son obligatorios.
SOURCE_VIOLATION=La contraseña no debe ser la misma que su contraseña %1$s.
TOO_LONG=La contraseña no debe tener más de %2$s caracteres.
TOO_SHORT=La contraseña debe tener al menos %1$s caracteres.
HISTORY_VIOLATION=La contraseña corresponde a uno de los %1$s de las contraseñas anteriores.
ILLEGAL_WORD=La contraseña contiene la palabra del diccionario '%1$s'.
ILLEGAL_WORD_REVERSED=La contraseña contiene la palabra invertida del diccionario '%1$s'.
ILLEGAL_MATCH=La contraseña coincide con el modelo no válido '%1$s'.
ALLOWED_MATCH=La contraseña debe coincidir con el modelo '%1$s'.
ILLEGAL_CHAR=La contraseña contiene el carácter inválida '%1$s'.
ALLOWED_CHAR=La contraseña contiene el carácter permitido '%1$s'.
ILLEGAL_SEQUENCE=La contraseña contiene la secuencia inválida '%1$s'.
ILLEGAL_USERNAME=La contraseña contiene la identificación del usuario '%1$s'.
ILLEGAL_USERNAME_REVERSED=La contraseña contiene la identificación invertida del usuario '%1$s'.
ILLEGAL_WHITESPACE=La contraseña no debe contener espacios.
INSUFFICIENT_UPPERCASE=La contraseña debe contener al menos %1$s letras mayúsculas.
INSUFFICIENT_LOWERCASE=La contraseña debe contener al menos %1$s letras minúsculas.
INSUFFICIENT_ALPHABETICAL=La contraseña debe contener al menos %1$s caracteres alfabéticos.
INSUFFICIENT_DIGIT=La contraseña debe contener al menos %1$s dígitos.
INSUFFICIENT_SPECIAL=La contraseña debe contener al menos %1$s caracteres especiales.
INSUFFICIENT_CHARACTERISTICS=La contraseña coincide con %1$s de %3$s reglas de caracteres, pero %2$s son obligatorios.
SOURCE_VIOLATION=La contraseña no debe ser la misma que su contraseña %1$s.
TOO_LONG=La contraseña no debe tener más de %2$s caracteres.
TOO_SHORT=La contraseña debe tener al menos %1$s caracteres.
185 changes: 185 additions & 0 deletions Kitodo/src/test/java/org/kitodo/PropertyEncodingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertyEncodingTest {

private Properties messages;
private static final Charset CORRECT_ENCODING = StandardCharsets.UTF_8;
private static final Charset WRONG_ENCODING = StandardCharsets.ISO_8859_1;
private static final String MESSAGES_DIR = "src/main/resources/messages/";
private static final HashMap<String, String> GERMAN_TEST_MESSAGES = new HashMap<>();
private static final HashMap<String, String> GERMAN_ERROR_MESSAGES = new HashMap<>();
private static final HashMap<String, String> GERMAN_PASSWORD_MESSAGES = new HashMap<>();
private static final HashMap<String, String> SPANISH_TEST_MESSAGES = new HashMap<>();
private static final HashMap<String, String> SPANISH_ERROR_MESSAGES = new HashMap<>();
private static final HashMap<String, String> SPANISH_PASSWORD_MESSAGES = new HashMap<>();
private static final String GERMAN_MESSAGE_PROPERTIES = MESSAGES_DIR + "messages_de.properties";
private static final String SPANISH_MESSAGE_PROPERTIES = MESSAGES_DIR + "messages_es.properties";
private static final String GERMAN_ERROR_PROPERTIES = MESSAGES_DIR + "errors_de.properties";
private static final String SPANISH_ERROR_PROPERTIES = MESSAGES_DIR + "errors_es.properties";
private static final String GERMAN_PASSWORD_PROPERTIES = MESSAGES_DIR + "password_de.properties";
private static final String SPANISH_PASSWORD_PROPERTIES = MESSAGES_DIR + "password_es.properties";

@BeforeAll
public static void prepare() {
// prepare German test messages
GERMAN_TEST_MESSAGES.put("viewPageInNewWindow", "Seite in neuem Browser-Fenster öffnen");
GERMAN_TEST_MESSAGES.put("importConfig.searchFields.idPrefix", "ID-Präfix");
GERMAN_TEST_MESSAGES.put("addMappingFile", "Abbildungsdatei hinzufügen");

// prepare German error test messages
GERMAN_ERROR_MESSAGES.put("errorAdding", "Fehler beim Hinzufügen von ''{0}''");
GERMAN_ERROR_MESSAGES.put("batchPropertyEmpty", "Die Eigenschaft {0} im Vorgang {1} ist ein Pflichtfeld, enthält aber keinen Wert.");
GERMAN_ERROR_MESSAGES.put("calendar.upload.isEmpty", "Es wurde keine Datei übertragen.");

// prepare German password test messages
GERMAN_PASSWORD_MESSAGES.put("HISTORY_VIOLATION", "Passwort entspricht einem von %1$s der vorherigen Passwörter.");
GERMAN_PASSWORD_MESSAGES.put("ILLEGAL_USERNAME", "Passwort enthält die Benutzer-ID '%1$s'.");

// prepare Spanish test messages
SPANISH_TEST_MESSAGES.put("confirm", "Esta acción puede llevar algún tiempo. ¿Estás seguro de que deseas continuar?");
SPANISH_TEST_MESSAGES.put("passwordChanged", "La contraseña se ha cambiado con éxito.");
SPANISH_TEST_MESSAGES.put("projectNotAssignedToCurrentUser", "¡El proyecto \"{0}\" no está asignado al usuario actual!");

// prepare Spanish error test messages
SPANISH_ERROR_MESSAGES.put("errorAdding", "Error al añadir ''{0}''");
SPANISH_ERROR_MESSAGES.put("projectTitleAlreadyInUse", "El título del proyecto ya está en uso.");
SPANISH_ERROR_MESSAGES.put("workflowExceptionParallelGatewayNoTask", "¡Ninguna tarea sigue la ramificación paralela!");

// prepare Spanish password test messages
SPANISH_PASSWORD_MESSAGES.put("HISTORY_VIOLATION", "La contraseña corresponde a uno de los %1$s de las contraseñas anteriores.");
SPANISH_PASSWORD_MESSAGES.put("ILLEGAL_WORD", "La contraseña contiene la palabra del diccionario '%1$s'.");
}

@Test
public void checkCharacterEncodingOfGermanMessagesFile() throws Exception {
// ensure messages are decoded as expected using UTF-8 encoding
messages = readPropertiesWithEncoding(GERMAN_MESSAGE_PROPERTIES, CORRECT_ENCODING);
for (Map.Entry<String, String> testMessage : GERMAN_TEST_MESSAGES.entrySet()) {
assertEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}

// ensure messages are _not_ decoded as expected using ISO_8859_1 encoding
messages = readPropertiesWithEncoding(GERMAN_MESSAGE_PROPERTIES, WRONG_ENCODING);
for (Map.Entry<String, String> testMessage : GERMAN_TEST_MESSAGES.entrySet()) {
assertNotEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}
}

@Test
public void checkCharacterEncodingsOfGermanErrorMessageFile() throws Exception {
// ensure messages are decoded as expected using UTF-8 encoding
messages = readPropertiesWithEncoding(GERMAN_ERROR_PROPERTIES, CORRECT_ENCODING);
for (Map.Entry<String, String> testMessage : GERMAN_ERROR_MESSAGES.entrySet()) {
assertEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}

// ensure messages are _not_ decoded as expected using ISO_8859_1 encoding
messages = readPropertiesWithEncoding(GERMAN_ERROR_PROPERTIES, WRONG_ENCODING);
for (Map.Entry<String, String> testMessage : GERMAN_ERROR_MESSAGES.entrySet()) {
assertNotEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}
}

@Test
public void checkCharacterEncodingOfGermanPasswordMessageFile() throws Exception {
// ensure messages are decoded as expected using UTF-8 encoding
messages = readPropertiesWithEncoding(GERMAN_PASSWORD_PROPERTIES, CORRECT_ENCODING);
for (Map.Entry<String, String> testMessage : GERMAN_PASSWORD_MESSAGES.entrySet()) {
assertEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}

// ensure messages are _not_ decoded as expected using ISO_8895_1 encoding
messages = readPropertiesWithEncoding(GERMAN_PASSWORD_PROPERTIES, WRONG_ENCODING);
for (Map.Entry<String, String> testMessage : GERMAN_PASSWORD_MESSAGES.entrySet()) {
assertNotEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}
}

@Test
public void checkCharacterEncodingsOfSpanishMessagesFile() throws Exception {
// ensure messages are decoded as expected using UTF-8 encoding
messages = readPropertiesWithEncoding(SPANISH_MESSAGE_PROPERTIES, CORRECT_ENCODING);
for (Map.Entry<String, String> testMessage : SPANISH_TEST_MESSAGES.entrySet()) {
assertEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}

// ensure messages are _not_ decoded as expected using ISO_8859_1 encoding
messages = readPropertiesWithEncoding(SPANISH_MESSAGE_PROPERTIES, WRONG_ENCODING);
for (Map.Entry<String, String> testMessage : SPANISH_TEST_MESSAGES.entrySet()) {
assertNotEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}
}

@Test
public void checkCharacterEncodingsOfSpanishErrorMessagesFile() throws Exception {
// ensure messages are decoded as expected using UTF-8 encoding
messages = readPropertiesWithEncoding(SPANISH_ERROR_PROPERTIES, CORRECT_ENCODING);
for (Map.Entry<String, String> testMessage : SPANISH_ERROR_MESSAGES.entrySet()) {
assertEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}

// ensure messages are _not_ decoded as expected using ISO_8859_1 encoding
messages = readPropertiesWithEncoding(SPANISH_ERROR_PROPERTIES, WRONG_ENCODING);
for (Map.Entry<String, String> testMessage : SPANISH_ERROR_MESSAGES.entrySet()) {
assertNotEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}
}

@Test
public void checkCharacterEncodingOfSpanishPasswordMessageFile() throws Exception {
// ensure messages are decoded as expected using UTF-8 encoding
messages = readPropertiesWithEncoding(SPANISH_PASSWORD_PROPERTIES, CORRECT_ENCODING);
for (Map.Entry<String, String> testMessage : SPANISH_PASSWORD_MESSAGES.entrySet()) {
assertEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}

// ensure messages are _not_ decoded as expected using ISO_8859_1 encoding
messages = readPropertiesWithEncoding(SPANISH_PASSWORD_PROPERTIES, WRONG_ENCODING);
for (Map.Entry<String, String> testMessage : SPANISH_PASSWORD_MESSAGES.entrySet()) {
assertNotEquals(testMessage.getValue(), messages.getProperty(testMessage.getKey()));
}
}

private Properties readPropertiesWithEncoding(String pathString, Charset encoding)
throws IOException {
Path path = Paths.get(pathString);
assertTrue(Files.exists(path));
Properties properties = new Properties();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path.toFile()),
encoding))) {
properties.load(reader);
return properties;
}
}
}

0 comments on commit a7cba1a

Please sign in to comment.