Skip to content

Commit

Permalink
fix spotlessjavacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonhyejin committed Jan 10, 2025
1 parent f2c89ed commit f8670cd
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testMapWithoutActor() {
@Test
public void testMapNull() {
AuditStamp result = TimeStampToAuditStampMapper.map(null, null);

assertNull(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
import com.linkedin.common.urn.DataPlatformUrn;
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.generated.DataPlatformInstance;
import com.linkedin.datahub.graphql.types.common.mappers.DataPlatformInstanceAspectMapper;
import com.linkedin.datahub.graphql.generated.EntityType;
import com.linkedin.datahub.graphql.types.common.mappers.DataPlatformInstanceAspectMapper;
import org.testng.annotations.Test;

public class DataPlatformInstanceAspectMapperTest {

private static final String TEST_PLATFORM = "hive";
private static final String TEST_INSTANCE = "prod";
private static final String TEST_PLATFORM_URN = "urn:li:dataPlatform:" + TEST_PLATFORM;
private static final String TEST_INSTANCE_URN =
String.format("urn:li:dataPlatformInstance:(urn:li:dataPlatform:%s,%s)", TEST_PLATFORM, TEST_INSTANCE);
private static final String TEST_INSTANCE_URN =
String.format(
"urn:li:dataPlatformInstance:(urn:li:dataPlatform:%s,%s)", TEST_PLATFORM, TEST_INSTANCE);

@Test
public void testMapWithInstance() throws Exception {
// Create test input
com.linkedin.common.DataPlatformInstance input = new com.linkedin.common.DataPlatformInstance();
DataPlatformUrn platformUrn = new DataPlatformUrn(TEST_PLATFORM);
Urn instanceUrn = Urn.createFromString(TEST_INSTANCE_URN);

input.setPlatform(platformUrn);
input.setInstance(instanceUrn);

Expand All @@ -33,7 +34,7 @@ public void testMapWithInstance() throws Exception {
assertNotNull(result);
assertEquals(result.getType(), EntityType.DATA_PLATFORM_INSTANCE);
assertEquals(result.getUrn(), TEST_INSTANCE_URN);

// Verify platform mapping
assertNotNull(result.getPlatform());
assertEquals(result.getPlatform().getType(), EntityType.DATA_PLATFORM);
Expand All @@ -51,9 +52,9 @@ public void testMapWithoutInstance() throws Exception {
DataPlatformInstance result = DataPlatformInstanceAspectMapper.map(null, input);

assertNotNull(result);
assertNull(result.getType()); // Type should be null when no instance
assertNull(result.getUrn()); // URN should be null when no instance
assertNull(result.getType()); // Type should be null when no instance
assertNull(result.getUrn()); // URN should be null when no instance

// Verify platform is still mapped correctly
assertNotNull(result.getPlatform());
assertEquals(result.getPlatform().getType(), EntityType.DATA_PLATFORM);
Expand All @@ -68,6 +69,7 @@ public void testMapNull() {
@Test
public void testSingleton() {
assertNotNull(DataPlatformInstanceAspectMapper.INSTANCE);
assertSame(DataPlatformInstanceAspectMapper.INSTANCE, DataPlatformInstanceAspectMapper.INSTANCE);
assertSame(
DataPlatformInstanceAspectMapper.INSTANCE, DataPlatformInstanceAspectMapper.INSTANCE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,98 +5,81 @@
import static org.testng.Assert.*;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.featureflags.FeatureFlags;
import com.linkedin.datahub.graphql.generated.DataProcessInstance;
import com.linkedin.datahub.graphql.generated.EntityType;
import com.linkedin.datahub.graphql.featureflags.FeatureFlags;
import com.linkedin.entity.Aspect;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.EnvelopedAspect;
import com.linkedin.entity.EnvelopedAspectMap;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.metadata.Constants;
import com.linkedin.dataprocess.DataProcessInstanceProperties;
import com.linkedin.common.AuditStamp;
import com.linkedin.data.template.StringMap;
import com.linkedin.r2.RemoteInvocationException;
import graphql.execution.DataFetcherResult;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.mockito.Mockito;
import org.testng.annotations.Test;

public class DataProcessInstanceTypeTest {

private static final String TEST_INSTANCE_URN = "urn:li:dataProcessInstance:(test-workflow,test-instance-1)";
private static final String TEST_INSTANCE_URN =
"urn:li:dataProcessInstance:(test-workflow,test-instance-1)";

@Test
public void testBatchLoad() throws Exception {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(mockFeatureFlags.isDataProcessInstanceEntityEnabled()).thenReturn(true);
@Test
public void testBatchLoad() throws Exception {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(mockFeatureFlags.isDataProcessInstanceEntityEnabled()).thenReturn(true);

DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);
DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);

List<DataFetcherResult<DataProcessInstance>> result =
type.batchLoad(ImmutableList.of(TEST_INSTANCE_URN), getMockAllowContext());
List<DataFetcherResult<DataProcessInstance>> result =
type.batchLoad(ImmutableList.of(TEST_INSTANCE_URN), getMockAllowContext());

assertEquals(result.size(), 1);
}
assertEquals(result.size(), 1);
}

@Test
public void testBatchLoadFeatureFlagDisabled() throws Exception {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(mockFeatureFlags.isDataProcessInstanceEntityEnabled()).thenReturn(false);
@Test
public void testBatchLoadFeatureFlagDisabled() throws Exception {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(mockFeatureFlags.isDataProcessInstanceEntityEnabled()).thenReturn(false);

DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);
DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);

List<DataFetcherResult<DataProcessInstance>> result =
type.batchLoad(ImmutableList.of(TEST_INSTANCE_URN), getMockAllowContext());
List<DataFetcherResult<DataProcessInstance>> result =
type.batchLoad(ImmutableList.of(TEST_INSTANCE_URN), getMockAllowContext());

assertEquals(result.size(), 0);
assertEquals(result.size(), 0);

Mockito.verify(mockClient, Mockito.never())
.batchGetV2(
any(),
Mockito.anyString(),
Mockito.anySet(),
Mockito.anySet());
}
Mockito.verify(mockClient, Mockito.never())
.batchGetV2(any(), Mockito.anyString(), Mockito.anySet(), Mockito.anySet());
}

@Test(expectedExceptions = RuntimeException.class)
public void testBatchLoadClientException() throws Exception {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(mockFeatureFlags.isDataProcessInstanceEntityEnabled()).thenReturn(true);
@Test(expectedExceptions = RuntimeException.class)
public void testBatchLoadClientException() throws Exception {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(mockFeatureFlags.isDataProcessInstanceEntityEnabled()).thenReturn(true);

Mockito.doThrow(RemoteInvocationException.class)
.when(mockClient)
.batchGetV2(any(), Mockito.anyString(), Mockito.anySet(), Mockito.anySet());
Mockito.doThrow(RemoteInvocationException.class)
.when(mockClient)
.batchGetV2(any(), Mockito.anyString(), Mockito.anySet(), Mockito.anySet());

DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);
type.batchLoad(ImmutableList.of(TEST_INSTANCE_URN), getMockAllowContext());
}

@Test
public void testGetType() {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);

assertEquals(type.type(), EntityType.DATA_PROCESS_INSTANCE);
}

@Test
public void testObjectClass() {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);

assertEquals(type.objectClass(), DataProcessInstance.class);
}
}
DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);
type.batchLoad(ImmutableList.of(TEST_INSTANCE_URN), getMockAllowContext());
}

@Test
public void testGetType() {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);

assertEquals(type.type(), EntityType.DATA_PROCESS_INSTANCE);
}

@Test
public void testObjectClass() {
EntityClient mockClient = Mockito.mock(EntityClient.class);
FeatureFlags mockFeatureFlags = Mockito.mock(FeatureFlags.class);
DataProcessInstanceType type = new DataProcessInstanceType(mockClient, mockFeatureFlags);

assertEquals(type.objectClass(), DataProcessInstance.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

public class DataProcessInstanceMapperTest {

@Test
public void testMap() throws Exception {
EntityResponse entityResponse = new EntityResponse();
Urn urn = Urn.createFromString("urn:li:dataProcessInstance:(test-workflow,test-instance)");
entityResponse.setUrn(urn);
entityResponse.setAspects(new EnvelopedAspectMap(ImmutableMap.of()));
@Test
public void testMap() throws Exception {
EntityResponse entityResponse = new EntityResponse();
Urn urn = Urn.createFromString("urn:li:dataProcessInstance:(test-workflow,test-instance)");
entityResponse.setUrn(urn);
entityResponse.setAspects(new EnvelopedAspectMap(ImmutableMap.of()));

DataProcessInstance instance = DataProcessInstanceMapper.map(null, entityResponse);
DataProcessInstance instance = DataProcessInstanceMapper.map(null, entityResponse);

assertNotNull(instance);
assertEquals(instance.getUrn(), urn.toString());
assertEquals(instance.getType(), EntityType.DATA_PROCESS_INSTANCE);
}
}
assertNotNull(instance);
assertEquals(instance.getUrn(), urn.toString());
assertEquals(instance.getType(), EntityType.DATA_PROCESS_INSTANCE);
}
}

0 comments on commit f8670cd

Please sign in to comment.