use of org.alfresco.rest.api.search.model.Localization in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromTimezone.
@Test
public void fromTimezone() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromLocalization(searchParameters, null);
searchMapper.fromLocalization(searchParameters, new Localization("", null));
try {
searchMapper.fromLocalization(searchParameters, new Localization("nonsense", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("Invalid timezone"));
}
try {
searchMapper.fromLocalization(searchParameters, new Localization("GMT+25", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("Invalid timezone"));
}
searchMapper.fromLocalization(searchParameters, new Localization("America/New_York", null));
assertEquals("America/New_York", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("America/Denver", null));
assertEquals("America/Denver", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("America/Los_Angeles", null));
assertEquals("America/Los_Angeles", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("Europe/Madrid", null));
assertEquals("Europe/Madrid", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT+1", null));
assertEquals("GMT+01:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT+01:00", null));
assertEquals("GMT+01:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT-9", null));
assertEquals("GMT-09:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT+08:00", null));
assertEquals("GMT+08:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT-12:00", null));
assertEquals("GMT-12:00", searchParameters.getTimezone());
try {
searchMapper.fromLocalization(searchParameters, new Localization("UTC+5", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue("UTC is not support by java.util.timezone", iae.getLocalizedMessage().contains("Incompatible timezoneId"));
}
try {
searchMapper.fromLocalization(searchParameters, new Localization("UTC+06:00", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("Incompatible timezoneId"));
}
}
use of org.alfresco.rest.api.search.model.Localization in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromLocales.
@Test
public void fromLocales() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromLocalization(searchParameters, null);
searchMapper.fromLocalization(searchParameters, new Localization(null, null));
List<String> testLocales = new ArrayList<>();
testLocales.add(null);
try {
searchMapper.fromLocalization(searchParameters, new Localization(null, testLocales));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("Invalid locale"));
}
// Unfortunately this isn't validated, language can be anything.
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("NOTTHIS")));
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr")));
assertEquals(Locale.FRENCH, searchParameters.getLocales().get(0));
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr_FR")));
assertEquals(Locale.FRANCE, searchParameters.getLocales().get(0));
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr-FR")));
assertEquals(Locale.FRANCE, searchParameters.getLocales().get(0));
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr-fr")));
assertEquals(Locale.FRANCE, searchParameters.getSortLocale());
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr-ca")));
assertEquals(Locale.CANADA_FRENCH, searchParameters.getSortLocale());
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr_ca")));
assertEquals(Locale.CANADA_FRENCH, searchParameters.getSortLocale());
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("en-gb")));
assertEquals(Locale.UK, searchParameters.getSortLocale());
searchParameters = new SearchParameters();
searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("en-us")));
assertEquals(Locale.US, searchParameters.getSortLocale());
}
Aggregations