Skip to content

Commit

Permalink
chore(nested-domains): list and create tests (datahub-project#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaeilers authored Aug 25, 2023
2 parents efcc8cb + 00d9c3e commit 0fbc505
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public CompletableFuture<ListDomainsResult> get(final DataFetchingEnvironment en
final QueryContext context = environment.getContext();

return CompletableFuture.supplyAsync(() -> {
// todo - implement parentDomain permissions

if (AuthorizationUtils.canCreateDomains(context)) {
final ListDomainsInput input = bindArgument(environment.getArgument("input"), ListDomainsInput.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
public class CreateDomainResolverTest {

private static final CreateDomainInput TEST_INPUT = new CreateDomainInput(
"test-id",
"test-name",
"test-description",
"urn:li:domain:test-id-parent"
);

private static final CreateDomainInput TEST_INPUT_NO_PARENT_DOMAIN = new CreateDomainInput(
"test-id",
"test-name",
"test-description",
null
);

private static final Urn TEST_ACTOR_URN = UrnUtils.getUrn("urn:li:corpuser:test");
private static final String TEST_ENTITY_URN = "urn:li:dataset:(urn:li:dataPlatform:mysql,my-test,PROD)";
private static final String TEST_TAG_1_URN = "urn:li:tag:test-id-1";
private static final String TEST_TAG_2_URN = "urn:li:tag:test-id-2";


@Test
public void testGetSuccess() throws Exception {
Expand All @@ -52,6 +58,43 @@ public void testGetSuccess() throws Exception {

resolver.get(mockEnv).get();

final DomainKey key = new DomainKey();
key.setId("test-id");
final MetadataChangeProposal proposal = new MetadataChangeProposal();
proposal.setEntityKeyAspect(GenericRecordUtils.serializeAspect(key));
proposal.setEntityType(Constants.DOMAIN_ENTITY_NAME);
DomainProperties props = new DomainProperties();
props.setDescription("test-description");
props.setName("test-name");
props.setCreated(new AuditStamp().setActor(TEST_ACTOR_URN).setTime(0L));
props.setParentDomain(Urn.createFromString("urn:li:domain:test-id-parent"));
proposal.setAspectName(Constants.DOMAIN_PROPERTIES_ASPECT_NAME);
proposal.setAspect(GenericRecordUtils.serializeAspect(props));
proposal.setChangeType(ChangeType.UPSERT);

// Not ideal to match against "any", but we don't know the auto-generated execution request id
Mockito.verify(mockClient, Mockito.times(1)).ingestProposal(
Mockito.argThat(new CreateDomainProposalMatcher(proposal)),
Mockito.any(Authentication.class),
Mockito.eq(false)
);
}

@Test
public void testGetSuccessNoParentNode() throws Exception {
// Create resolver
EntityClient mockClient = Mockito.mock(EntityClient.class);
EntityService mockService = Mockito.mock(EntityService.class);
CreateDomainResolver resolver = new CreateDomainResolver(mockClient, mockService);

// Execute resolver
QueryContext mockContext = getMockAllowContext();
DataFetchingEnvironment mockEnv = Mockito.mock(DataFetchingEnvironment.class);
Mockito.when(mockEnv.getArgument(Mockito.eq("input"))).thenReturn(TEST_INPUT_NO_PARENT_DOMAIN);
Mockito.when(mockEnv.getContext()).thenReturn(mockContext);

resolver.get(mockEnv).get();

final DomainKey key = new DomainKey();
key.setId("test-id");
final MetadataChangeProposal proposal = new MetadataChangeProposal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class ListDomainsResolverTest {
private static final Urn TEST_DOMAIN_URN = Urn.createFromTuple("domain", "test-id");

private static final ListDomainsInput TEST_INPUT = new ListDomainsInput(
0, 20, null, "urn:li:domain:test-id-parent"
);

private static final ListDomainsInput TEST_INPUT_NO_PARENT_DOMAIN = new ListDomainsInput(
0, 20, null, null
);

Expand All @@ -44,7 +48,7 @@ public void testGetSuccess() throws Exception {
Mockito.when(mockClient.search(
Mockito.eq(Constants.DOMAIN_ENTITY_NAME),
Mockito.eq(""),
Mockito.eq(QueryUtils.newFilter(QueryUtils.newCriterion(PARENT_DOMAIN_INDEX_FIELD_NAME, "", Condition.IS_NULL))),
Mockito.eq(QueryUtils.newFilter(QueryUtils.newCriterion(PARENT_DOMAIN_INDEX_FIELD_NAME, "urn:li:domain:test-id-parent", Condition.EQUAL))),
Mockito.eq(new SortCriterion().setField(DOMAIN_CREATED_TIME_INDEX_FIELD_NAME).setOrder(SortOrder.DESCENDING)),
Mockito.eq(0),
Mockito.eq(20),
Expand Down Expand Up @@ -74,6 +78,44 @@ public void testGetSuccess() throws Exception {
assertEquals(resolver.get(mockEnv).get().getDomains().get(0).getUrn(), TEST_DOMAIN_URN.toString());
}

@Test
public void testGetSuccessNoParentDomain() throws Exception {
// Create resolver
EntityClient mockClient = Mockito.mock(EntityClient.class);

Mockito.when(mockClient.search(
Mockito.eq(Constants.DOMAIN_ENTITY_NAME),
Mockito.eq(""),
Mockito.eq(QueryUtils.newFilter(QueryUtils.newCriterion(PARENT_DOMAIN_INDEX_FIELD_NAME, "", Condition.IS_NULL))),
Mockito.eq(new SortCriterion().setField(DOMAIN_CREATED_TIME_INDEX_FIELD_NAME).setOrder(SortOrder.DESCENDING)),
Mockito.eq(0),
Mockito.eq(20),
Mockito.any(Authentication.class),
Mockito.eq(new SearchFlags().setFulltext(true))
)).thenReturn(
new SearchResult()
.setFrom(0)
.setPageSize(1)
.setNumEntities(1)
.setEntities(new SearchEntityArray(ImmutableSet.of(new SearchEntity().setEntity(TEST_DOMAIN_URN))))
);

ListDomainsResolver resolver = new ListDomainsResolver(mockClient);

// Execute resolver
QueryContext mockContext = getMockAllowContext();
DataFetchingEnvironment mockEnv = Mockito.mock(DataFetchingEnvironment.class);
Mockito.when(mockEnv.getArgument(Mockito.eq("input"))).thenReturn(TEST_INPUT_NO_PARENT_DOMAIN);
Mockito.when(mockEnv.getContext()).thenReturn(mockContext);

// Data Assertions
assertEquals((int) resolver.get(mockEnv).get().getStart(), 0);
assertEquals((int) resolver.get(mockEnv).get().getCount(), 1);
assertEquals((int) resolver.get(mockEnv).get().getTotal(), 1);
assertEquals(resolver.get(mockEnv).get().getDomains().size(), 1);
assertEquals(resolver.get(mockEnv).get().getDomains().get(0).getUrn(), TEST_DOMAIN_URN.toString());
}

@Test
public void testGetUnauthorized() throws Exception {
// Create resolver
Expand Down

0 comments on commit 0fbc505

Please sign in to comment.