Skip to content

Commit

Permalink
TRUNK-5065 Test saving allowed locales without default
Browse files Browse the repository at this point in the history
add test that shows its not allowed to save a locale list via global
property if the list doesnt contain the default locale currently set.
  • Loading branch information
teleivo committed Apr 9, 2018
1 parent 0ac5840 commit dc33df6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions api/src/test/java/org/openmrs/api/AdministrationServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand All @@ -29,7 +30,9 @@

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.openmrs.GlobalProperty;
import org.openmrs.ImplementationId;
Expand All @@ -41,6 +44,7 @@
import org.openmrs.messagesource.impl.MutableResourceBundleMessageSource;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.util.HttpClient;
import org.openmrs.util.LocaleUtility;
import org.openmrs.util.OpenmrsConstants;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
Expand All @@ -61,6 +65,9 @@ public class AdministrationServiceTest extends BaseContextSensitiveTest {

private CacheManager cacheManager;

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Before
public void runBeforeEachTest() {
adminService = Context.getAdministrationService();
Expand Down Expand Up @@ -428,6 +435,21 @@ public void saveGlobalProperty_shouldOverwriteGlobalPropertyIfExists() {
assertEquals("new-even-more-correct-value", adminService.getGlobalProperty("a_valid_gp_key"));
}

@Test
public void saveGlobalProperty_shouldFailIfGivenAllowedLocaleListDoesNotContainDefaultLocale() {

String localeList = "fr,es";

assertThat("localeList contains default locale but should not for this test case", localeList,
not(containsString(LocaleUtility.getDefaultLocale().toString())));

expectedException.expect(APIException.class);
expectedException.expectMessage("can not be removed from allowed locales list because it is the default locale");

adminService.saveGlobalProperty(
new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, localeList));
}

@Test
public void getAllowedLocales_shouldNotReturnDuplicatesEvenIfTheGlobalPropertyHasThem() {
adminService.saveGlobalProperty(
Expand Down

0 comments on commit dc33df6

Please sign in to comment.