Search in sources :

Example 61 with Locale

use of java.util.Locale in project head by mifos.

the class LocalizationConverterTest method testGetDateSeparator.

/**
     * Currently broken -- incomplete support for multiple locales for numeric
     * input.
     */
@Ignore
@Test
public void testGetDateSeparator() {
    String separator = "/";
    Locale locale = Localization.getInstance().getConfiguredLocale();
    String dateSeparator = converter.getDateSeparatorForCurrentLocale();
    if (locale.getCountry().equalsIgnoreCase("GB") && locale.getLanguage().equalsIgnoreCase("EN")) {
        Assert.assertEquals(separator, dateSeparator);
    }
    converter.setCurrentLocale(new Locale("IS", "is"));
    dateSeparator = converter.getDateSeparatorForCurrentLocale();
    Assert.assertEquals(".", dateSeparator);
    converter.setCurrentLocale(locale);
}
Also used : Locale(java.util.Locale) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 62 with Locale

use of java.util.Locale in project head by mifos.

the class LocalizationConverterTest method testGetDoubleValueForCurrentLocale.

/*
     * get convert a string to a double to the config locale and the format is
     * the money format 7.1
     */
@Test
public void testGetDoubleValueForCurrentLocale() {
    String doubleValueString = "223.59";
    Double dValue = 223.59;
    Locale locale = Localization.getInstance().getConfiguredLocale();
    Double dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
    if (locale.getCountry().equalsIgnoreCase("GB") && locale.getLanguage().equalsIgnoreCase("EN")) {
        Assert.assertEquals(dNumber, dValue);
        // if the wrong decimal separator is entered, it will throw
        // exception
        doubleValueString = "223,59";
        try {
            dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
        } catch (Exception ex) {
            Assert.assertTrue(ex.getMessage().startsWith("The format of the number is invalid."));
        }
    }
    converter.setCurrentLocale(new Locale("IS", "is"));
    doubleValueString = "223,59";
    dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
    Assert.assertEquals(dNumber, dValue);
    // if the wrong decimal separator is entered, it will throw exception
    doubleValueString = "223.59";
    try {
        dNumber = converter.getDoubleValueForCurrentLocale(doubleValueString);
    } catch (Exception ex) {
        Assert.assertTrue(ex.getMessage().startsWith("The format of the number is invalid."));
    }
    converter.setCurrentLocale(locale);
}
Also used : Locale(java.util.Locale) Test(org.junit.Test)

Example 63 with Locale

use of java.util.Locale in project head by mifos.

the class LocalizationConverterTest method testGetDoubleStringForInterest.

@Test
public void testGetDoubleStringForInterest() {
    String doubleValueString = "2123.12345";
    Double dValue = 2123.12345000000;
    Locale locale = Localization.getInstance().getConfiguredLocale();
    String dString = converter.getDoubleStringForInterest(dValue);
    if (locale.getCountry().equalsIgnoreCase("GB") && locale.getLanguage().equalsIgnoreCase("EN")) {
        Assert.assertEquals(doubleValueString, dString);
    }
    converter.setCurrentLocale(new Locale("IS", "is"));
    doubleValueString = "2123,12345";
    dString = converter.getDoubleStringForInterest(dValue);
    Assert.assertEquals(doubleValueString, dString);
    converter.setCurrentLocale(locale);
}
Also used : Locale(java.util.Locale) Test(org.junit.Test)

Example 64 with Locale

use of java.util.Locale in project head by mifos.

the class BundleKeyTest method testEqualsObject.

public void testEqualsObject() {
    Assert.assertTrue(bundleKey.equals(bundleKey));
    Assert.assertFalse(bundleKey.equals(null));
    Locale locale = new Locale("EN");
    Assert.assertFalse(bundleKey.equals(new BundleKey(locale, "wrongKey")));
    locale = new Locale("SP");
    Assert.assertFalse(bundleKey.equals(new BundleKey(locale, "Key")));
}
Also used : Locale(java.util.Locale)

Example 65 with Locale

use of java.util.Locale in project head by mifos.

the class DateFormatter method exec.

/**
     * @param args
     *            a list of arguments passed in from FTL in this order:
     *            <ul>
     *            <li>date object to be formatted. It can be an instance of either java.util.Date,
     *            org.joda.time.DateTime or org.joda.time.LocalDate</li>
     *            <li>pattern: date format pattern see {@link java.text.SimpleDateFormat}</li>
     *            <li>locale: an instance of java.util.Locale</li>
     *            </ul>
     */
@Override
public Object exec(List args) throws TemplateModelException {
    if (args.size() != 3) {
        throw new IllegalArgumentException("Wrong arguments");
    }
    Object date = DeepUnwrap.unwrap((TemplateModel) args.get(0));
    String pattern = (String) DeepUnwrap.unwrap((TemplateModel) args.get(1));
    Locale locale = (Locale) DeepUnwrap.unwrap((TemplateModel) args.get(2));
    if (date instanceof LocalDate) {
        date = ((LocalDate) date).toDateTimeAtStartOfDay();
    }
    String formatted = "";
    if (date instanceof DateTime) {
        formatted = DateTimeFormat.forPattern(pattern).withLocale(locale).print((DateTime) date);
    } else if (date instanceof Date) {
        formatted = new SimpleDateFormat(pattern, locale).format((Date) date);
    } else if (date != null) {
        throw new IllegalArgumentException("Unsupported date type: " + date.getClass());
    }
    return formatted;
}
Also used : Locale(java.util.Locale) TemplateModel(freemarker.template.TemplateModel) LocalDate(org.joda.time.LocalDate) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) LocalDate(org.joda.time.LocalDate) Date(java.util.Date)

Aggregations

Locale (java.util.Locale)5854 Test (org.junit.Test)902 HashMap (java.util.HashMap)548 GenericValue (org.apache.ofbiz.entity.GenericValue)504 ArrayList (java.util.ArrayList)486 Delegator (org.apache.ofbiz.entity.Delegator)484 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)398 IOException (java.io.IOException)313 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)296 Date (java.util.Date)273 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)271 Map (java.util.Map)244 BigDecimal (java.math.BigDecimal)214 SimpleDateFormat (java.text.SimpleDateFormat)198 ResourceBundle (java.util.ResourceBundle)197 File (java.io.File)166 LinkedList (java.util.LinkedList)158 ULocale (android.icu.util.ULocale)156 List (java.util.List)147 Test (org.junit.jupiter.api.Test)132