Skip to content

Commit

Permalink
LPD-20030 [Integration test] Add test to assert the data provider con…
Browse files Browse the repository at this point in the history
…tent is translated according to the ddmDataProviderRequest locale
  • Loading branch information
p-albuquerque authored and brianchandotcom committed Mar 27, 2024
1 parent 6f83854 commit 9df1d49
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.liferay.portal.kernel.cache.PortalCache;
import com.liferay.portal.kernel.cache.PortalCacheHelperUtil;
import com.liferay.portal.kernel.cache.PortalCacheManagerNames;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.model.ResourceConstants;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.User;
Expand Down Expand Up @@ -250,6 +252,27 @@ public void testGetDataWithInputParametersInURL() throws Exception {
Assert.assertEquals("Brazil", keyValuePair.getValue());
}

@Test
public void testGetDataWithLocale() throws Exception {
_setUserPermissionChecker(false);

String outputParameterId = StringUtil.randomString();

long ddmDataProviderId = _addDDMDataProviderInstance(
_createDDMDataProviderDDMFormValues(
false, false, StringPool.BLANK, null, outputParameterId,
"nameCurrentValue;name", "list", null, null,
_GET_COUNTRIES_URL),
false);

_testGetDataWithLocale(
ddmDataProviderId, LocaleUtil.FRANCE, outputParameterId);
_testGetDataWithLocale(
ddmDataProviderId, LocaleUtil.GERMANY, outputParameterId);
_testGetDataWithLocale(
ddmDataProviderId, LocaleUtil.US, outputParameterId);
}

@Test
public void testGetDataWithNumberOutput() throws Exception {
_setUserPermissionChecker(false);
Expand Down Expand Up @@ -610,6 +633,25 @@ private void _setUserPermissionChecker(boolean guest) throws Exception {
PermissionCheckerFactoryUtil.create(user));
}

private void _testGetDataWithLocale(
long ddmDataProviderId, Locale locale, String outputParameterId)
throws Exception {

DDMDataProviderResponse ddmDataProviderResponse =
_ddmDataProvider.getData(
_createDDMDataProviderRequest(
ddmDataProviderId, null, null, null, locale, null, null));

for (KeyValuePair keyValuePair :
(List<KeyValuePair>)ddmDataProviderResponse.getOutput(
outputParameterId, List.class)) {

Assert.assertEquals(
LanguageUtil.get(locale, "country." + keyValuePair.getKey()),
keyValuePair.getValue());
}
}

private static final String _GET_COUNTRIES_URL =
"http://localhost:8080/api/jsonws/country/get-countries";

Expand All @@ -628,6 +670,9 @@ private void _setUserPermissionChecker(boolean guest) throws Exception {
private DDMDataProviderInstanceLocalService
_ddmDataProviderInstanceLocalService;

@Inject
private Language _language;

private PermissionChecker _originalPermissionChecker;

@Inject(type = RoleLocalService.class)
Expand Down

0 comments on commit 9df1d49

Please sign in to comment.