Skip to content

Commit

Permalink
LPD-44173 Integration test for localized multiselect picklist busines…
Browse files Browse the repository at this point in the history
…s type
  • Loading branch information
pedro-oliveira446 committed Dec 18, 2024
1 parent 2dbeebc commit 7372ac3
Showing 1 changed file with 118 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ public void setUp() throws Exception {

_listTypeEntryKey1 = _addListTypeEntry();
_listTypeEntryKey2 = _addListTypeEntry();
_listTypeEntryKey3 = _addListTypeEntry();
_listTypeEntryKey4 = _addListTypeEntry();

_localizedObjectFieldI18nValues = HashMapBuilder.<String, Object>put(
"localizedBooleanObjectFieldName_i18n",
Expand Down Expand Up @@ -303,6 +305,13 @@ public void setUp() throws Exception {
).put(
"pt_BR", "pt_BR localizedLongTextObjectFieldValue"
).build()
).put(
"localizedMultiPicklistObjectFieldName_i18n",
HashMapBuilder.put(
"en_US", Arrays.asList(_listTypeEntryKey3, _listTypeEntryKey4)
).put(
"pt_BR", Arrays.asList(_listTypeEntryKey4)
).build()
).put(
"localizedPicklistObjectFieldName_i18n",
HashMapBuilder.put(
Expand Down Expand Up @@ -518,6 +527,17 @@ public void setUp() throws Exception {
"localizedLongTextObjectFieldName"
).build(),
new MultiselectPicklistObjectFieldBuilder(
).labelMap(
LocalizedMapUtil.getLocalizedMap(
RandomTestUtil.randomString())
).listTypeDefinitionId(
listTypeDefinition.getListTypeDefinitionId()
).localized(
true
).name(
"localizedMultiPicklistObjectFieldName"
).build(),
new MultiselectPicklistObjectFieldBuilder(
).labelMap(
LocalizedMapUtil.getLocalizedMap(
RandomTestUtil.randomString())
Expand Down Expand Up @@ -2359,6 +2379,9 @@ public void testGetObjectEntries() throws Exception {
).put(
"localizedLongTextObjectFieldName",
"en_US localizedLongTextObjectFieldValue"
).put(
"localizedMultiPicklistObjectFieldName",
Arrays.asList(_listTypeEntryKey3, _listTypeEntryKey4)
).put(
"localizedPicklistObjectFieldName", _listTypeEntryKey1
).put(
Expand Down Expand Up @@ -2445,6 +2468,13 @@ public void testGetObjectEntries() throws Exception {
).put(
"pt_BR", 54L
).build()
).put(
"localizedMultiPicklistObjectFieldName_i18n",
HashMapBuilder.put(
"en_US", Arrays.asList(_listTypeEntryKey3)
).put(
"pt_BR", Arrays.asList(_listTypeEntryKey3, _listTypeEntryKey4)
).build()
).put(
"localizedPicklistObjectFieldName_i18n",
HashMapBuilder.put(
Expand Down Expand Up @@ -4138,6 +4168,9 @@ public void testUpdateObjectEntry() throws Exception {
).put(
"localizedLongTextObjectFieldName",
"en_US localizedLongTextObjectFieldValue"
).put(
"localizedMultiPicklistObjectFieldName",
Arrays.asList(_listTypeEntryKey3, _listTypeEntryKey4)
).put(
"localizedPicklistObjectFieldName", _listTypeEntryKey1
).put(
Expand All @@ -4163,6 +4196,9 @@ public void testUpdateObjectEntry() throws Exception {
).put(
"localizedLongTextObjectFieldName",
"pt_BR localizedLongTextObjectFieldValue"
).put(
"localizedMultiPicklistObjectFieldName",
Arrays.asList(_listTypeEntryKey4)
).put(
"localizedPicklistObjectFieldName", _listTypeEntryKey2
).put(
Expand Down Expand Up @@ -4290,6 +4326,13 @@ public void testUpdateObjectEntry() throws Exception {
).put(
"pt_BR", ""
).build()
).put(
"localizedMultiPicklistObjectFieldName_i18n",
HashMapBuilder.put(
"en_US", Arrays.asList(_listTypeEntryKey3)
).put(
"pt_BR", Arrays.asList(_listTypeEntryKey3, _listTypeEntryKey4)
).build()
).put(
"localizedPicklistObjectFieldName_i18n",
HashMapBuilder.put(
Expand Down Expand Up @@ -4373,6 +4416,9 @@ public void testUpdateObjectEntry() throws Exception {
).put(
"localizedLongTextObjectFieldName",
"en_US localizedLongTextObjectFieldValue"
).put(
"localizedMultiPicklistObjectFieldName",
Arrays.asList(_listTypeEntryKey3)
).put(
"localizedPicklistObjectFieldName", _listTypeEntryKey2
).put(
Expand All @@ -4398,6 +4444,9 @@ public void testUpdateObjectEntry() throws Exception {
).put(
"localizedLongTextObjectFieldName",
"en_US localizedLongTextObjectFieldValue"
).put(
"localizedMultiPicklistObjectFieldName",
Arrays.asList(_listTypeEntryKey3, _listTypeEntryKey4)
).put(
"localizedPicklistObjectFieldName", _listTypeEntryKey1
).put(
Expand Down Expand Up @@ -4872,22 +4921,41 @@ else if (Objects.equals(
String.valueOf(actualValues.get(entry.getKey())))));
}
}
else if (Objects.equals(
expectedEntry.getKey(),
"localizedMultiPicklistObjectFieldName")) {

_assertListTypeEntries(
(List<Object>)expectedEntry.getValue(),
(List<ListEntry>)actualObjectEntryProperties.get(
expectedEntry.getKey()));
}
else if (Objects.equals(
expectedEntry.getKey(),
"localizedMultiPicklistObjectFieldName_i18n")) {

Map<String, Object> actualValues =
(Map<String, Object>)actualObjectEntryProperties.get(
expectedEntry.getKey());
Map<String, Object> expectedValues =
(Map<String, Object>)expectedEntry.getValue();

for (Map.Entry<String, Object> entry : expectedValues.entrySet()) {
_assertListTypeEntries(
(List<Object>)entry.getValue(),
(List<ListEntry>)actualValues.get(entry.getKey()));
}
}
else if (Objects.equals(
expectedEntry.getKey(),
"localizedPicklistObjectFieldName") ||
Objects.equals(
expectedEntry.getKey(), "picklistObjectFieldName")) {

ListEntry listEntry = (ListEntry)actualObjectEntryProperties.get(
expectedEntry.getKey());

if (expectedEntry.getValue() instanceof String) {
Assert.assertEquals(
expectedEntry.getValue(), listEntry.getKey());
}
else {
Assert.assertEquals(expectedEntry.getValue(), listEntry);
}
_assertListTypeEntry(
expectedEntry.getValue(),
(ListEntry)actualObjectEntryProperties.get(
expectedEntry.getKey()));
}
else if (Objects.equals(
expectedEntry.getKey(),
Expand All @@ -4900,15 +4968,9 @@ else if (Objects.equals(
(Map<String, Object>)expectedEntry.getValue();

for (Map.Entry<String, Object> entry : expectedValues.entrySet()) {
ListEntry listEntry = (ListEntry)actualValues.get(
entry.getKey());

if (entry.getValue() instanceof String) {
Assert.assertEquals(entry.getValue(), listEntry.getKey());
}
else {
Assert.assertEquals(entry.getValue(), listEntry);
}
_assertListTypeEntry(
entry.getValue(),
(ListEntry)actualValues.get(entry.getKey()));
}
}
else if (Objects.equals(
Expand Down Expand Up @@ -5247,6 +5309,41 @@ private void _assertFilteredObjectEntriesSize(
objectEntries.toString(), size, objectEntries.size());
}

private void _assertListTypeEntries(
List<Object> expectedListTypeEntries,
List<ListEntry> actualListTypeEntries) {

if (ListUtil.isEmpty(expectedListTypeEntries)) {
return;
}

for (Object expectedListTypeEntry : expectedListTypeEntries) {
Assert.assertTrue(
ListUtil.exists(
actualListTypeEntries,
listEntry -> {
if (expectedListTypeEntry instanceof String) {
return Objects.equals(
expectedListTypeEntry, listEntry.getKey());
}

return Objects.equals(expectedListTypeEntry, listEntry);
}));
}
}

private void _assertListTypeEntry(
Object expectedListTypeEntry, ListEntry actualListTypeEntry) {

if (expectedListTypeEntry instanceof String) {
Assert.assertEquals(
expectedListTypeEntry, actualListTypeEntry.getKey());
}
else {
Assert.assertEquals(expectedListTypeEntry, actualListTypeEntry);
}
}

private void _assertLocalizedValues(
Map<String, Object> expectedLocalizedValues, String languageId,
long objectEntryId)
Expand Down Expand Up @@ -5733,6 +5830,8 @@ private void _updateLocalizedObjectEntryValues(

private String _listTypeEntryKey1;
private String _listTypeEntryKey2;
private String _listTypeEntryKey3;
private String _listTypeEntryKey4;

@Inject
private ListTypeEntryLocalService _listTypeEntryLocalService;
Expand Down

0 comments on commit 7372ac3

Please sign in to comment.