Search in sources :

Example 6 with GoogleCloudDataplexV1Entity

use of com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClientTest method testGetGetCloudStorageEntitiesByAssetName.

@Test
public void testGetGetCloudStorageEntitiesByAssetName() throws IOException {
    CloudDataplex cloudDataplexClient = mock(CloudDataplex.class, Answers.RETURNS_DEEP_STUBS);
    Entities.List entitiesListRequest = mock(Entities.List.class, Answers.RETURNS_DEEP_STUBS);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().list(ZONE_NAME)).thenReturn(entitiesListRequest);
    GoogleCloudDataplexV1Entity entity1 = new GoogleCloudDataplexV1Entity().setName("entity1").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1Entity entity2 = new GoogleCloudDataplexV1Entity().setName("entity2").setAsset(ASSET_NAME1).setSystem(// storage mismatch
    "BIGQUERY");
    GoogleCloudDataplexV1Entity entity3 = new GoogleCloudDataplexV1Entity().setName("entity3").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1Entity entity4 = new GoogleCloudDataplexV1Entity().setName("entity4").setAsset(ASSET_NAME2).setSystem(// asset mismatch
    StorageSystem.CLOUD_STORAGE.name());
    // an entity with a short asset name
    GoogleCloudDataplexV1Entity entity5 = new GoogleCloudDataplexV1Entity().setName("entity5").setAsset(SHORT_ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1ListEntitiesResponse response1 = new GoogleCloudDataplexV1ListEntitiesResponse();
    response1.setEntities(ImmutableList.of(entity1, entity2, entity3));
    response1.setNextPageToken(PAGE_TOKEN);
    GoogleCloudDataplexV1ListEntitiesResponse response2 = new GoogleCloudDataplexV1ListEntitiesResponse();
    response2.setEntities(ImmutableList.of(entity4, entity5));
    when(entitiesListRequest.setPageToken(any())).thenReturn(entitiesListRequest);
    when(entitiesListRequest.execute()).thenReturn(response1, response2);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity1").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity1);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity3").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity3);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity5").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity5);
    assertEquals(ImmutableList.of(entity1, entity3, entity5), DefaultDataplexClient.withClient(cloudDataplexClient).getCloudStorageEntities(ASSET_NAME1));
}
Also used : CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) GoogleCloudDataplexV1ListEntitiesResponse(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse) GoogleCloudDataplexV1Entity(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity) Entities(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities) Test(org.junit.Test)

Example 7 with GoogleCloudDataplexV1Entity

use of com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClientTest method testGetEntitiesByEntityNames.

@Test
public void testGetEntitiesByEntityNames() throws IOException {
    CloudDataplex cloudDataplexClient = mock(CloudDataplex.class, Answers.RETURNS_DEEP_STUBS);
    GoogleCloudDataplexV1Entity entity1 = new GoogleCloudDataplexV1Entity().setName("entity1").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1Entity entity2 = new GoogleCloudDataplexV1Entity().setName("entity2").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1Entity entity3 = new GoogleCloudDataplexV1Entity().setName("entity3").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity1").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity1);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity2").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity2);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity3").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity3);
    assertEquals(ImmutableList.of(entity1, entity2, entity3), DefaultDataplexClient.withClient(cloudDataplexClient).getEntities(ImmutableList.of("entity1", "entity2", "entity3")));
}
Also used : CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) GoogleCloudDataplexV1Entity(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity) Test(org.junit.Test)

Aggregations

GoogleCloudDataplexV1Entity (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity)7 Entities (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities)3 CloudDataplex (com.google.api.services.dataplex.v1.CloudDataplex)2 GoogleCloudDataplexV1ListEntitiesResponse (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse)2 EntityMetadata (com.google.cloud.teleport.v2.values.EntityMetadata)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 GoogleCloudDataplexV1Asset (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Asset)1 GoogleCloudDataplexV1Partition (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition)1 NoopTransform (com.google.cloud.teleport.v2.transforms.NoopTransform)1 WriteDispositionException (com.google.cloud.teleport.v2.utils.WriteDisposition.WriteDispositionException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Collectors.toMap (java.util.stream.Collectors.toMap)1