Skip to content

Commit

Permalink
LPS-201793 Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magjed4289 authored and brianchandotcom committed Dec 18, 2023
1 parent 78e7316 commit 3684fb2
Showing 1 changed file with 219 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ public void setUp() throws Exception {
_siteScopedObjectDefinition1, _OBJECT_FIELD_NAME_1,
_OBJECT_FIELD_VALUE_1);

_siteScopedObjectDefinition2 =
ObjectDefinitionTestUtil.publishObjectDefinition(
Arrays.asList(
ObjectFieldUtil.createObjectField(
ObjectFieldConstants.BUSINESS_TYPE_TEXT,
ObjectFieldConstants.DB_TYPE_STRING, true, true, null,
RandomTestUtil.randomString(), _OBJECT_FIELD_NAME_2,
false)),
ObjectDefinitionConstants.SCOPE_SITE);

SystemObjectDefinitionManager systemObjectDefinitionManager =
_systemObjectDefinitionManagerRegistry.
getSystemObjectDefinitionManager("User");
Expand Down Expand Up @@ -454,6 +464,16 @@ public void tearDown() throws Exception {
_objectRelationship5);
}

if (_objectRelationship6 != null) {
_objectRelationshipLocalService.deleteObjectRelationship(
_objectRelationship6);
}

if (_objectRelationship7 != null) {
_objectRelationshipLocalService.deleteObjectRelationship(
_objectRelationship7);
}

_objectDefinitionLocalService.deleteObjectDefinition(
_objectDefinition1);
_objectDefinitionLocalService.deleteObjectDefinition(
Expand All @@ -464,6 +484,8 @@ public void tearDown() throws Exception {
_objectDefinition4);
_objectDefinitionLocalService.deleteObjectDefinition(
_siteScopedObjectDefinition1);
_objectDefinitionLocalService.deleteObjectDefinition(
_siteScopedObjectDefinition2);

_listTypeDefinitionLocalService.deleteListTypeDefinition(
_listTypeDefinition);
Expand Down Expand Up @@ -4829,6 +4851,8 @@ public void testPostCustomObjectEntryWithInvalidNestedCustomObjectEntries()
public void testPostCustomObjectEntryWithNestedCustomObjectEntriesInManyToManyRelationship()
throws Exception {

// Company scope

_objectRelationship1 = ObjectRelationshipTestUtil.addObjectRelationship(
_objectDefinition1, _objectDefinition2, TestPropsValues.getUserId(),
ObjectRelationshipConstants.TYPE_MANY_TO_MANY);
Expand Down Expand Up @@ -4880,6 +4904,69 @@ public void testPostCustomObjectEntryWithNestedCustomObjectEntriesInManyToManyRe

Assert.assertEquals(2, nestedObjectEntriesJSONArray.length());

_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(0),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_1);
_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(1),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_2);

// Site scope

_objectRelationship6 = ObjectRelationshipTestUtil.addObjectRelationship(
_siteScopedObjectDefinition1, _siteScopedObjectDefinition2,
TestPropsValues.getUserId(),
ObjectRelationshipConstants.TYPE_MANY_TO_MANY);

objectEntryJSONObject = JSONUtil.put(
_objectRelationship6.getName(),
_createObjectEntriesJSONArray(
new String[] {_ERC_VALUE_1, _ERC_VALUE_2}, _OBJECT_FIELD_NAME_2,
new String[] {
_NEW_OBJECT_FIELD_VALUE_1, _NEW_OBJECT_FIELD_VALUE_2
}));

jsonObject = HTTPTestUtil.invokeToJSONObject(
objectEntryJSONObject.toString(),
_getEndpoint(
TestPropsValues.getGroupId(), _siteScopedObjectDefinition1),
Http.Method.POST);

Assert.assertEquals(
0,
jsonObject.getJSONObject(
"status"
).get(
"code"
));

nestedObjectEntriesJSONArray = jsonObject.getJSONArray(
_objectRelationship6.getName());

Assert.assertEquals(2, nestedObjectEntriesJSONArray.length());

_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(0),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_1);
_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(1),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_2);

objectEntryId = jsonObject.getString("id");

jsonObject = HTTPTestUtil.invokeToJSONObject(
null,
StringBundler.concat(
_siteScopedObjectDefinition1.getRESTContextPath(),
StringPool.SLASH, objectEntryId, "?nestedFields=",
_objectRelationship6.getName()),
Http.Method.GET);

nestedObjectEntriesJSONArray = jsonObject.getJSONArray(
_objectRelationship6.getName());

Assert.assertEquals(2, nestedObjectEntriesJSONArray.length());

_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(0),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_1);
Expand All @@ -4892,6 +4979,8 @@ public void testPostCustomObjectEntryWithNestedCustomObjectEntriesInManyToManyRe
public void testPostCustomObjectEntryWithNestedCustomObjectEntriesInManyToOneRelationship()
throws Exception {

// Company scope

_objectRelationship1 = ObjectRelationshipTestUtil.addObjectRelationship(
_objectDefinition1, _objectDefinition2, TestPropsValues.getUserId(),
ObjectRelationshipConstants.TYPE_ONE_TO_MANY);
Expand Down Expand Up @@ -4945,12 +5034,76 @@ public void testPostCustomObjectEntryWithNestedCustomObjectEntriesInManyToOneRel
StringUtil.removeLast(
_objectDefinition1.getPKObjectFieldName(), "Id"))),
_OBJECT_FIELD_NAME_1, _NEW_OBJECT_FIELD_VALUE_1);

// Site scope

_objectRelationship7 = ObjectRelationshipTestUtil.addObjectRelationship(
_siteScopedObjectDefinition1, _siteScopedObjectDefinition2,
TestPropsValues.getUserId(),
ObjectRelationshipConstants.TYPE_ONE_TO_MANY);

objectEntryJSONObject = JSONUtil.put(
_objectRelationship7.getName(),
JSONFactoryUtil.createJSONObject(
JSONUtil.put(
_OBJECT_FIELD_NAME_1, _NEW_OBJECT_FIELD_VALUE_1
).put(
"externalReferenceCode", _ERC_VALUE_1
).toString()));

jsonObject = HTTPTestUtil.invokeToJSONObject(
objectEntryJSONObject.toString(),
_getEndpoint(
TestPropsValues.getGroupId(), _siteScopedObjectDefinition2),
Http.Method.POST);

Assert.assertEquals(
0,
jsonObject.getJSONObject(
"status"
).get(
"code"
));

_assertObjectEntryField(
jsonObject.getJSONObject(
StringBundler.concat(
"r_", _objectRelationship7.getName(), "_",
StringUtil.replaceLast(
_siteScopedObjectDefinition1.getPKObjectFieldName(),
"Id", ""))),
_OBJECT_FIELD_NAME_1, _NEW_OBJECT_FIELD_VALUE_1);

objectEntryId = jsonObject.getString("id");

jsonObject = HTTPTestUtil.invokeToJSONObject(
null,
StringBundler.concat(
_siteScopedObjectDefinition2.getRESTContextPath(),
StringPool.SLASH, objectEntryId, "?nestedFields=",
StringBundler.concat(
"r_", _objectRelationship7.getName(), "_",
StringUtil.removeLast(
_siteScopedObjectDefinition1.getPKObjectFieldName(),
"Id"))),
Http.Method.GET);

_assertObjectEntryField(
jsonObject.getJSONObject(
StringBundler.concat(
"r_", _objectRelationship7.getName(), "_",
StringUtil.removeLast(
_siteScopedObjectDefinition1.getPKObjectFieldName(),
"Id"))),
_OBJECT_FIELD_NAME_1, _NEW_OBJECT_FIELD_VALUE_1);
}

@Test
public void testPostCustomObjectEntryWithNestedCustomObjectEntriesInOneToManyRelationship()
throws Exception {

// Company scope

_objectRelationship1 = ObjectRelationshipTestUtil.addObjectRelationship(
_objectDefinition1, _objectDefinition2, TestPropsValues.getUserId(),
ObjectRelationshipConstants.TYPE_ONE_TO_MANY);
Expand Down Expand Up @@ -5002,6 +5155,69 @@ public void testPostCustomObjectEntryWithNestedCustomObjectEntriesInOneToManyRel

Assert.assertEquals(2, nestedObjectEntriesJSONArray.length());

_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(0),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_1);
_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(1),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_2);

// Site scope

_objectRelationship7 = ObjectRelationshipTestUtil.addObjectRelationship(
_siteScopedObjectDefinition1, _siteScopedObjectDefinition2,
TestPropsValues.getUserId(),
ObjectRelationshipConstants.TYPE_ONE_TO_MANY);

objectEntryJSONObject = JSONUtil.put(
_objectRelationship7.getName(),
_createObjectEntriesJSONArray(
new String[] {_ERC_VALUE_1, _ERC_VALUE_2}, _OBJECT_FIELD_NAME_2,
new String[] {
_NEW_OBJECT_FIELD_VALUE_1, _NEW_OBJECT_FIELD_VALUE_2
}));

jsonObject = HTTPTestUtil.invokeToJSONObject(
objectEntryJSONObject.toString(),
_getEndpoint(
TestPropsValues.getGroupId(), _siteScopedObjectDefinition1),
Http.Method.POST);

Assert.assertEquals(
0,
jsonObject.getJSONObject(
"status"
).get(
"code"
));

nestedObjectEntriesJSONArray = jsonObject.getJSONArray(
_objectRelationship7.getName());

Assert.assertEquals(2, nestedObjectEntriesJSONArray.length());

_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(0),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_1);
_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(1),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_2);

objectEntryId = jsonObject.getString("id");

jsonObject = HTTPTestUtil.invokeToJSONObject(
null,
StringBundler.concat(
_siteScopedObjectDefinition1.getRESTContextPath(),
StringPool.SLASH, objectEntryId, "?nestedFields=",
_objectRelationship7.getName()),
Http.Method.GET);

nestedObjectEntriesJSONArray = jsonObject.getJSONArray(
_objectRelationship7.getName());

Assert.assertEquals(2, nestedObjectEntriesJSONArray.length());

_assertObjectEntryField(
(JSONObject)nestedObjectEntriesJSONArray.get(0),
_OBJECT_FIELD_NAME_2, _NEW_OBJECT_FIELD_VALUE_1);
Expand Down Expand Up @@ -7822,6 +8038,8 @@ private JSONObject _toFileEntryJSONObject(
private ObjectRelationship _objectRelationship3;
private ObjectRelationship _objectRelationship4;
private ObjectRelationship _objectRelationship5;
private ObjectRelationship _objectRelationship6;
private ObjectRelationship _objectRelationship7;

@Inject
private ObjectRelationshipLocalService _objectRelationshipLocalService;
Expand All @@ -7839,6 +8057,7 @@ private JSONObject _toFileEntryJSONObject(
private RoleLocalService _roleLocalService;

private ObjectDefinition _siteScopedObjectDefinition1;
private ObjectDefinition _siteScopedObjectDefinition2;
private ObjectEntry _siteScopedObjectEntry1;

@Inject
Expand Down

0 comments on commit 3684fb2

Please sign in to comment.