Skip to content

Commit

Permalink
LPD-33180 Inline
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchandotcom committed Aug 12, 2024
1 parent 1402440 commit 42f3155
Showing 1 changed file with 57 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,48 @@ public void testObjectEntry1toMObjectRelatedModelsProviderImpl()

// Get related models with localized object field

_assertLocalizedValues(objectEntry1);
Map<String, Serializable> expectedLocalizedValues =
HashMapBuilder.<String, Serializable>put(
"longText_i18n",
HashMapBuilder.put(
"en_US", RandomTestUtil.randomString()
).build()
).put(
"richText_i18n",
HashMapBuilder.put(
"en_US", RandomTestUtil.randomString()
).build()
).put(
"text_i18n",
HashMapBuilder.put(
"en_US", "en_US " + RandomTestUtil.randomString()
).build()
).build();

ObjectEntry objectEntry5 = _addObjectEntry(
_objectDefinition2,
HashMapBuilder.putAll(
expectedLocalizedValues
).build());

ObjectRelationshipTestUtil.addObjectRelationshipMappingTableValues(
_objectRelationship.getObjectRelationshipId(),
objectEntry1.getObjectEntryId(), objectEntry5.getObjectEntryId());

Map<String, Serializable> actualLocalizedValues =
_objectEntryLocalService.getValues(objectEntry5.getObjectEntryId());

Assert.assertEquals(
expectedLocalizedValues.get("longTextLocalized_i18n"),
actualLocalizedValues.get("longTextLocalized_i18n"));
Assert.assertEquals(
expectedLocalizedValues.get("richTextLocalized_i18n"),
actualLocalizedValues.get("richTextLocalized_i18n"));
Assert.assertEquals(
expectedLocalizedValues.get("textLocalized_i18n"),
actualLocalizedValues.get("textLocalized_i18n"));

_objectEntryLocalService.deleteObjectEntry(objectEntry5);

// Get related models with search

Expand Down Expand Up @@ -383,7 +424,7 @@ public void testObjectEntry1toMObjectRelatedModelsProviderImpl()

Group group = GroupTestUtil.addGroup();

ObjectEntry objectEntry5 = ObjectEntryTestUtil.addObjectEntry(
ObjectEntry objectEntry6 = ObjectEntryTestUtil.addObjectEntry(
group.getGroupId(),
scopeSiteObjectDefinition.getObjectDefinitionId(),
HashMapBuilder.<String, Serializable>put(
Expand All @@ -400,7 +441,7 @@ public void testObjectEntry1toMObjectRelatedModelsProviderImpl()

Assert.assertNull(
_objectEntryLocalService.fetchObjectEntry(
objectEntry5.getObjectEntryId()));
objectEntry6.getObjectEntryId()));

// Object relationship deletion type disassociate

Expand All @@ -410,32 +451,32 @@ public void testObjectEntry1toMObjectRelatedModelsProviderImpl()
ObjectRelationshipConstants.DELETION_TYPE_DISASSOCIATE,
_objectRelationship.getLabelMap());

ObjectEntry objectEntry6 = _addObjectEntry(
ObjectEntry objectEntry7 = _addObjectEntry(
_objectDefinition1, Collections.emptyMap());

ObjectEntry objectEntry7 = ObjectEntryTestUtil.addObjectEntry(
ObjectEntry objectEntry8 = ObjectEntryTestUtil.addObjectEntry(
group.getGroupId(),
scopeSiteObjectDefinition.getObjectDefinitionId(),
HashMapBuilder.<String, Serializable>put(
_relationshipObjectField.getName(),
objectEntry6.getObjectEntryId()
objectEntry7.getObjectEntryId()
).build());

ObjectRelationshipTestUtil.assertGetRelatedModels(
1, _objectRelatedModelsProvider,
_objectRelationship.getObjectRelationshipId(),
objectEntry6.getObjectEntryId());
objectEntry7.getObjectEntryId());

_objectEntryLocalService.deleteObjectEntry(objectEntry6);
_objectEntryLocalService.deleteObjectEntry(objectEntry7);

Assert.assertNotNull(
_objectEntryLocalService.fetchObjectEntry(
objectEntry7.getObjectEntryId()));
objectEntry8.getObjectEntryId()));

ObjectRelationshipTestUtil.assertGetRelatedModels(
0, _objectRelatedModelsProvider,
_objectRelationship.getObjectRelationshipId(),
objectEntry6.getObjectEntryId());
objectEntry7.getObjectEntryId());

// Object relationship deletion type prevent

Expand All @@ -445,33 +486,33 @@ public void testObjectEntry1toMObjectRelatedModelsProviderImpl()
ObjectRelationshipConstants.DELETION_TYPE_PREVENT,
_objectRelationship.getLabelMap());

ObjectEntry objectEntry8 = _addObjectEntry(
ObjectEntry objectEntry9 = _addObjectEntry(
_objectDefinition1, Collections.emptyMap());

_updateObjectEntry(
objectEntry7.getObjectEntryId(),
objectEntry8.getObjectEntryId(),
HashMapBuilder.<String, Serializable>put(
_relationshipObjectField.getName(),
objectEntry8.getObjectEntryId()
objectEntry9.getObjectEntryId()
).build());

ObjectRelationshipTestUtil.assertGetRelatedModels(
1, _objectRelatedModelsProvider,
_objectRelationship.getObjectRelationshipId(),
objectEntry8.getObjectEntryId());
objectEntry9.getObjectEntryId());

AssertUtils.assertFailure(
RequiredObjectRelationshipException.class,
StringBundler.concat(
"Object relationship ",
_objectRelationship.getObjectRelationshipId(),
" does not allow deletes"),
() -> _objectEntryLocalService.deleteObjectEntry(objectEntry8));
() -> _objectEntryLocalService.deleteObjectEntry(objectEntry9));

ObjectRelationshipTestUtil.assertGetRelatedModels(
1, _objectRelatedModelsProvider,
_objectRelationship.getObjectRelationshipId(),
objectEntry8.getObjectEntryId());
objectEntry9.getObjectEntryId());

_objectRelationshipLocalService.deleteObjectRelationship(
_objectRelationship);
Expand Down Expand Up @@ -633,54 +674,6 @@ private void _addObjectRelationship(
objectDefinition2.getCompanyId(), relationshipType);
}

private void _assertLocalizedValues(ObjectEntry parentObjectEntry)
throws Exception {

Map<String, Serializable> expectedLocalizedValues =
HashMapBuilder.<String, Serializable>put(
"longText_i18n",
HashMapBuilder.put(
"en_US", RandomTestUtil.randomString()
).build()
).put(
"richText_i18n",
HashMapBuilder.put(
"en_US", RandomTestUtil.randomString()
).build()
).put(
"text_i18n",
HashMapBuilder.put(
"en_US", "en_US " + RandomTestUtil.randomString()
).build()
).build();

ObjectEntry objectEntry = _addObjectEntry(
_objectDefinition2,
HashMapBuilder.putAll(
expectedLocalizedValues
).build());

ObjectRelationshipTestUtil.addObjectRelationshipMappingTableValues(
_objectRelationship.getObjectRelationshipId(),
parentObjectEntry.getObjectEntryId(),
objectEntry.getObjectEntryId());

Map<String, Serializable> actualLocalizedValues =
_objectEntryLocalService.getValues(objectEntry.getObjectEntryId());

Assert.assertEquals(
expectedLocalizedValues.get("longTextLocalized_i18n"),
actualLocalizedValues.get("longTextLocalized_i18n"));
Assert.assertEquals(
expectedLocalizedValues.get("richTextLocalized_i18n"),
actualLocalizedValues.get("richTextLocalized_i18n"));
Assert.assertEquals(
expectedLocalizedValues.get("textLocalized_i18n"),
actualLocalizedValues.get("textLocalized_i18n"));

_objectEntryLocalService.deleteObjectEntry(objectEntry);
}

private void _assertViewPermission(
int expectedRelatedModelsCount, ObjectDefinition objectDefinition,
ObjectEntry parentObjectEntry, long primKey, int scope)
Expand Down

0 comments on commit 42f3155

Please sign in to comment.