forked from Raxa/raxacore
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAH 3407|Fix of locale issue in the visit search handler (#244)
* BAH-3407|Fix locale issue in search handler * BAH-3407|Add null check for concept list * BAH-3407| Fix VisitFormsSearchHandlerTest test cases * BAH-3407 | Refactor. used conceptsByName method and fix tests * BAH-3407| Refactor. Usage of locale in VisitFormsSearchHandler * BAH-3407| Refactor. Usage of locale in VisitFormsSearchHandler and test * BAH-3407| Refactor. Use of searchLocale or default. * BAH-3407 | Refactor. get concept name in default locale if null in user locale * BAH-3407 | Extracted identify locale method to separate class * BAH-3407 | Fix. test failures * BAH-3407| Add tests for LocaleResolver class. * BAH-3407 | Add. test case for searching concept in default locale if match not found in user locale * BAH-3407| Refactor. Use of static identify locale method. * BAH-3407| Add check for concept to choose correct locale * BAH-3407| Fix VisitFormsSearchHandlerTest * BAH-3407 | Refactor. pass false instead of null * BAH-3407 | Fix. test failures --------- Co-authored-by: SanoferSameera <[email protected]>
- Loading branch information
1 parent
d0b60bb
commit 21f340a
Showing
6 changed files
with
182 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.bahmni.module.bahmnicore.web.v1_0; | ||
|
||
import org.openmrs.api.APIException; | ||
import org.openmrs.util.LocaleUtility; | ||
|
||
import java.util.Locale; | ||
|
||
public class LocaleResolver { | ||
|
||
public static Locale identifyLocale(String locale) { | ||
if (locale != null && !locale.isEmpty()) { | ||
Locale searchLocale = LocaleUtility.fromSpecification(locale); | ||
if (searchLocale.getLanguage().isEmpty()) { | ||
throw new APIException("Invalid locale: " + locale); | ||
} | ||
return searchLocale; | ||
} else { | ||
return LocaleUtility.getDefaultLocale(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.bahmni.module.bahmnicore.web.v1_0; | ||
|
||
import static org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver.identifyLocale; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
import org.junit.Test; | ||
import org.openmrs.util.LocaleUtility; | ||
|
||
import java.util.Locale; | ||
|
||
public class LocaleResolverTest { | ||
|
||
@Test | ||
public void shouldReturnDefaultLocaleIfNull() { | ||
Locale locale = identifyLocale(null); | ||
assertEquals(LocaleUtility.getDefaultLocale(), locale); | ||
} | ||
|
||
@Test | ||
public void shouldReturnDefaultLocaleIfEmpty() { | ||
Locale locale = identifyLocale(""); | ||
assertEquals(LocaleUtility.getDefaultLocale(), locale); | ||
} | ||
|
||
@Test | ||
public void shouldReturnParsedLocaleIfValid() { | ||
Locale locale = identifyLocale("en_US"); | ||
assertEquals(new Locale("en", "US"), locale); | ||
} | ||
|
||
@Test(expected = AssertionError.class) | ||
public void shouldThrowExceptionIfInvalidLocale() { | ||
identifyLocale("invalid"); | ||
fail("Should have thrown exception"); | ||
} | ||
|
||
} |
Oops, something went wrong.