forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'datahub-project:master' into master
- Loading branch information
Showing
34 changed files
with
2,331 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
datahub-graphql-core/src/test/java/com/linkedin/datahub/graphql/utils/AnalyticsUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.linkedin.datahub.graphql.utils; | ||
|
||
import static org.mockito.ArgumentMatchers.anySet; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.data.DataMap; | ||
import com.linkedin.datahub.graphql.analytics.service.AnalyticsUtil; | ||
import com.linkedin.datahub.graphql.generated.Cell; | ||
import com.linkedin.datahub.graphql.generated.Row; | ||
import com.linkedin.entity.EntityResponse; | ||
import com.linkedin.entity.EnvelopedAspect; | ||
import com.linkedin.entity.EnvelopedAspectMap; | ||
import com.linkedin.entity.client.EntityClient; | ||
import com.linkedin.identity.CorpUserEditableInfo; | ||
import com.linkedin.identity.CorpUserInfo; | ||
import com.linkedin.metadata.Constants; | ||
import io.datahubproject.metadata.context.OperationContext; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
public class AnalyticsUtilTest { | ||
|
||
@Mock private OperationContext mockOpContext; | ||
|
||
@Mock private EntityClient mockEntityClient; | ||
|
||
final String TEST_CORP_USER_INFO_TEST_USER = "Corp User"; | ||
final String TEST_CORP_USER_EDITABLE_INFO_TEST_TITLE = "Editable Info Title"; | ||
final String TEST_CORP_USER_EDITABLE_INFO_TEST_EMAIL = "Editable Info Email"; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
public void testConvertToUserInfoRows() throws Exception { | ||
List<Row> rows = new ArrayList<>(); | ||
rows.add(new Row(null, Arrays.asList(new Cell("urn:li:corpuser:testuser", null, null)))); | ||
|
||
// create a CorpUserInfo with only display name set | ||
CorpUserInfo corpUserInfo = new CorpUserInfo(); | ||
corpUserInfo.setActive(true); | ||
corpUserInfo.setDisplayName(TEST_CORP_USER_INFO_TEST_USER); | ||
|
||
// create an editableInfo with the email and title set | ||
CorpUserEditableInfo corpUserEditableInfo = new CorpUserEditableInfo(); | ||
corpUserEditableInfo.setEmail(TEST_CORP_USER_EDITABLE_INFO_TEST_EMAIL); // Overriding email | ||
corpUserEditableInfo.setTitle(TEST_CORP_USER_EDITABLE_INFO_TEST_TITLE); // Overriding title | ||
|
||
DataMap corpUserInfoDataMap = new DataMap(); | ||
corpUserInfoDataMap.put("name", Constants.CORP_USER_INFO_ASPECT_NAME); | ||
corpUserInfoDataMap.put("type", "VERSIONED"); | ||
corpUserInfoDataMap.put("value", corpUserInfo.data()); | ||
|
||
DataMap corpUserEditableInfoDataMap = new DataMap(); | ||
corpUserEditableInfoDataMap.put("name", Constants.CORP_USER_EDITABLE_INFO_ASPECT_NAME); | ||
corpUserEditableInfoDataMap.put("type", "VERSIONED"); | ||
corpUserEditableInfoDataMap.put("value", corpUserEditableInfo.data()); | ||
|
||
EnvelopedAspect corpUserInfoEnvelopedAspect = new EnvelopedAspect(corpUserInfoDataMap); | ||
EnvelopedAspect corpUserEditableInfoEnvelopedAspect = | ||
new EnvelopedAspect(corpUserEditableInfoDataMap); | ||
|
||
EnvelopedAspectMap aspectMap = new EnvelopedAspectMap(); | ||
aspectMap.put(Constants.CORP_USER_INFO_ASPECT_NAME, corpUserInfoEnvelopedAspect); | ||
aspectMap.put( | ||
Constants.CORP_USER_EDITABLE_INFO_ASPECT_NAME, corpUserEditableInfoEnvelopedAspect); | ||
|
||
EntityResponse entityResponse = new EntityResponse(); | ||
entityResponse.setAspects(aspectMap); | ||
|
||
Map<Urn, EntityResponse> entityResponseMap = new HashMap<>(); | ||
Urn userUrn = UrnUtils.getUrn("urn:li:corpuser:testuser"); | ||
entityResponseMap.put(userUrn, entityResponse); | ||
|
||
// method of the entity client we need to mock to retrieve the response map | ||
when(mockEntityClient.batchGetV2( | ||
eq(mockOpContext), eq(Constants.CORP_USER_ENTITY_NAME), anySet(), anySet())) | ||
.thenReturn(entityResponseMap); | ||
|
||
// function we are testing | ||
AnalyticsUtil.convertToUserInfoRows(mockOpContext, mockEntityClient, rows); | ||
|
||
Row updatedRow = rows.get(0); | ||
List<Cell> updatedCells = updatedRow.getCells(); | ||
|
||
// asserting that the display user is from CorpUserInfo and email, title are from EditableInfo | ||
assertEquals(updatedCells.get(0).getValue(), TEST_CORP_USER_INFO_TEST_USER); | ||
assertEquals( | ||
updatedCells.get(1).getValue(), | ||
TEST_CORP_USER_EDITABLE_INFO_TEST_TITLE); // Overriding title | ||
assertEquals( | ||
updatedCells.get(2).getValue(), | ||
TEST_CORP_USER_EDITABLE_INFO_TEST_EMAIL); // Overriding email | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1827,7 +1827,7 @@ | |
"@docusaurus/theme-search-algolia" "2.4.3" | ||
"@docusaurus/types" "2.4.3" | ||
|
||
"@docusaurus/[email protected]", "react-loadable@npm:@docusaurus/[email protected]": | ||
"@docusaurus/[email protected]": | ||
version "5.5.2" | ||
resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce" | ||
integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ== | ||
|
@@ -4757,9 +4757,9 @@ cross-fetch@^3.1.5: | |
node-fetch "^2.6.12" | ||
|
||
cross-spawn@^7.0.3: | ||
version "7.0.3" | ||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" | ||
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== | ||
version "7.0.6" | ||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" | ||
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== | ||
dependencies: | ||
path-key "^3.1.0" | ||
shebang-command "^2.0.0" | ||
|
@@ -9713,6 +9713,14 @@ react-loadable-ssr-addon-v5-slorber@^1.0.1: | |
dependencies: | ||
"@babel/runtime" "^7.10.3" | ||
|
||
"react-loadable@npm:@docusaurus/[email protected]": | ||
version "5.5.2" | ||
resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce" | ||
integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ== | ||
dependencies: | ||
"@types/react" "*" | ||
prop-types "^15.6.2" | ||
|
||
react-markdown@^8.0.6: | ||
version "8.0.7" | ||
resolved "https://registry.yarnpkg.com/react-markdown/-/react-markdown-8.0.7.tgz#c8dbd1b9ba5f1c5e7e5f2a44de465a3caafdf89b" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.