View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.util;
21  
22  import org.apache.myfaces.tobago.internal.config.AbstractTobagoTestBase;
23  import org.apache.myfaces.tobago.validator.FileItemValidator;
24  import org.junit.jupiter.api.Assertions;
25  import org.junit.jupiter.api.Test;
26  
27  import javax.faces.application.FacesMessage;
28  import java.util.Locale;
29  
30  public class MessageUtilsUnitTest extends AbstractTobagoTestBase {
31  
32    @Test
33    public void testDummy() {
34      final FacesMessage dummy = MessageUtils.getMessage(
35          facesContext,
36          FacesMessage.SEVERITY_INFO,
37          "dummy");
38      Assertions.assertEquals("dummy", dummy.getSummary());
39      Assertions.assertEquals("dummy", dummy.getDetail());
40    }
41  
42    @Test
43    public void testDefault() {
44      final FacesMessage locale = MessageUtils.getMessage(
45          facesContext,
46          FacesMessage.SEVERITY_INFO,
47          FileItemValidator.CONTENT_TYPE_MESSAGE_ID, "application/pdf");
48      Assertions.assertEquals("Content type error", locale.getSummary());
49      Assertions.assertEquals("The given file is not content type of 'application/pdf'.", locale.getDetail());
50    }
51  
52    @Test
53    public void testGermany() {
54      facesContext.getViewRoot().setLocale(Locale.GERMANY);
55  
56      final FacesMessage locale = MessageUtils.getMessage(
57          facesContext,
58          FacesMessage.SEVERITY_INFO,
59          FileItemValidator.CONTENT_TYPE_MESSAGE_ID, "application/pdf");
60      Assertions.assertEquals("Dateityp Fehler", locale.getSummary());
61      Assertions.assertEquals("Die hochgeladene Datei ist nicht vom Typ 'application/pdf'.", locale.getDetail());
62    }
63  
64    @Test
65    public void testSpanish() {
66      facesContext.getViewRoot().setLocale(Locale.forLanguageTag("es"));
67  
68      final FacesMessage locale = MessageUtils.getMessage(
69          facesContext,
70          FacesMessage.SEVERITY_INFO,
71          FileItemValidator.CONTENT_TYPE_MESSAGE_ID, "application/pdf");
72      Assertions.assertEquals("Error de tipo de contenido", locale.getSummary());
73      Assertions.assertEquals("El archivo no es del tipo de contenido 'application/pdf'.", locale.getDetail());
74    }
75  
76    @Test
77    public void testFallback() {
78      facesContext.getViewRoot().setLocale(Locale.forLanguageTag("ja"));
79  
80      final FacesMessage locale = MessageUtils.getMessage(
81          facesContext,
82          FacesMessage.SEVERITY_INFO,
83          FileItemValidator.CONTENT_TYPE_MESSAGE_ID, "application/pdf");
84      Assertions.assertEquals("Content type error", locale.getSummary());
85      Assertions.assertEquals("The given file is not content type of 'application/pdf'.", locale.getDetail());
86    }
87  }