diff --git a/java-datacatalog/README.md b/java-datacatalog/README.md index 5cb3bd26635a..9b14a99d18e0 100644 --- a/java-datacatalog/README.md +++ b/java-datacatalog/README.md @@ -56,20 +56,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.1.4') +implementation platform('com.google.cloud:libraries-bom:26.1.5') implementation 'com.google.cloud:google-cloud-datacatalog' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-datacatalog:1.11.0' +implementation 'com.google.cloud:google-cloud-datacatalog:1.12.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-datacatalog" % "1.11.0" +libraryDependencies += "com.google.cloud" % "google-cloud-datacatalog" % "1.12.0" ``` ## Authentication @@ -107,36 +107,6 @@ use this Data Catalog Client Library. -## Samples - -Samples are in the [`samples/`](https://github.com/googleapis/java-datacatalog/tree/main/samples) directory. - -| Sample | Source Code | Try it | -| --------------------------- | --------------------------------- | ------ | -| Create Custom Entry | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/CreateCustomEntry.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/CreateCustomEntry.java) | -| Create Entry | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/CreateEntry.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/CreateEntry.java) | -| Create Entry Group | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/CreateEntryGroup.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/CreateEntryGroup.java) | -| Create Fileset Entry | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/CreateFilesetEntry.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/CreateFilesetEntry.java) | -| Create Tag Template | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/CreateTagTemplate.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/CreateTagTemplate.java) | -| Delete Entry | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntry.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/DeleteEntry.java) | -| Delete Entry Group | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntryGroup.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/DeleteEntryGroup.java) | -| Delete Tag Template | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/DeleteTagTemplate.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/DeleteTagTemplate.java) | -| Get Entry | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/GetEntry.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/GetEntry.java) | -| Get Entry Group | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/GetEntryGroup.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/GetEntryGroup.java) | -| Get Tag Template | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/GetTagTemplate.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/GetTagTemplate.java) | -| Grant Tag Template User Role | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/GrantTagTemplateUserRole.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/GrantTagTemplateUserRole.java) | -| List Entries | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/ListEntries.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/ListEntries.java) | -| List Entry Groups | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/ListEntryGroups.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/ListEntryGroups.java) | -| Lookup Entry Big Query Dataset | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryDataset.java) | -| Lookup Entry Big Query Table | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryTable.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryTable.java) | -| Lookup Entry Pub Sub Topic | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryPubSubTopic.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/LookupEntryPubSubTopic.java) | -| Quickstart | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/Quickstart.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/Quickstart.java) | -| Search Assets | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/SearchAssets.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/SearchAssets.java) | -| Update Entry | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntry.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/UpdateEntry.java) | -| Update Entry Group | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntryGroup.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/UpdateEntryGroup.java) | -| Update Tag Template | [source code](https://github.com/googleapis/java-datacatalog/blob/main/samples/snippets/src/main/java/com/example/datacatalog/UpdateTagTemplate.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datacatalog&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datacatalog/UpdateTagTemplate.java) | - - ## Troubleshooting diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateCustomEntry.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateCustomEntry.java deleted file mode 100644 index 57a57c91b54e..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateCustomEntry.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_create_custom_entry] -import com.google.cloud.datacatalog.v1.ColumnSchema; -import com.google.cloud.datacatalog.v1.CreateEntryGroupRequest; -import com.google.cloud.datacatalog.v1.CreateEntryRequest; -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroup; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.Schema; -import java.io.IOException; - -// Sample to create custom entry -public class CreateCustomEntry { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "my-project"; - String entryGroupId = "onprem_entry_group"; - String entryId = "onprem_entry_id"; - createCustomEntry(projectId, entryGroupId, entryId); - } - - public static void createCustomEntry(String projectId, String entryGroupId, String entryId) - throws IOException { - // Currently, Data Catalog stores metadata in the us-central1 region. - String location = "us-central1"; - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - // Construct the EntryGroup for the EntryGroup request. - EntryGroup entryGroup = - EntryGroup.newBuilder() - .setDisplayName("My awesome Entry Group") - .setDescription("This Entry Group represents an external system") - .build(); - - // Construct the EntryGroup request to be sent by the client. - CreateEntryGroupRequest entryGroupRequest = - CreateEntryGroupRequest.newBuilder() - .setParent(LocationName.of(projectId, location).toString()) - .setEntryGroupId(entryGroupId) - .setEntryGroup(entryGroup) - .build(); - - // Use the client to send the API request. - EntryGroup createdEntryGroup = dataCatalogClient.createEntryGroup(entryGroupRequest); - - // Construct the Entry for the Entry request. - Entry entry = - Entry.newBuilder() - .setUserSpecifiedSystem("onprem_data_system") - .setUserSpecifiedType("onprem_data_asset") - .setDisplayName("My awesome data asset") - .setDescription("This data asset is managed by an external system.") - .setLinkedResource("//my-onprem-server.com/dataAssets/my-awesome-data-asset") - .setSchema( - Schema.newBuilder() - .addColumns( - ColumnSchema.newBuilder() - .setColumn("first_column") - .setDescription("This columns consists of ....") - .setMode("NULLABLE") - .setType("DOUBLE") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("second_column") - .setDescription("This columns consists of ....") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .build()) - .build(); - - // Construct the Entry request to be sent by the client. - CreateEntryRequest entryRequest = - CreateEntryRequest.newBuilder() - .setParent(createdEntryGroup.getName()) - .setEntryId(entryId) - .setEntry(entry) - .build(); - - // Use the client to send the API request. - Entry createdEntry = dataCatalogClient.createEntry(entryRequest); - System.out.printf("Custom entry created with name: %s", createdEntry.getName()); - } - } -} -// [END data_catalog_create_custom_entry] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateEntry.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateEntry.java deleted file mode 100644 index 2cbc7e40a016..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateEntry.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_create_entry] -import com.google.cloud.datacatalog.v1.CreateEntryRequest; -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.IOException; - -// Sample to create an entry -public class CreateEntry { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - String entryId = "MY_ENTRY_ID"; - EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId); - Entry entry = Entry.newBuilder().build(); - createEntry(entryGroupName, entryId, entry); - } - - public static void createEntry(EntryGroupName entryGroupName, String entryId, Entry entry) - throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - CreateEntryRequest request = - CreateEntryRequest.newBuilder() - .setParent(entryGroupName.toString()) - .setEntryId(entryId) - .setEntry(entry) - .build(); - client.createEntry(request); - System.out.println("Entry created successfully"); - } - } -} -// [END data_catalog_create_entry] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateEntryGroup.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateEntryGroup.java deleted file mode 100644 index 64133657f8a3..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateEntryGroup.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_create_entry_group] -import com.google.cloud.datacatalog.v1.CreateEntryGroupRequest; -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.EntryGroup; -import com.google.cloud.datacatalog.v1.LocationName; -import java.io.IOException; - -// Sample to create an entry group -public class CreateEntryGroup { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "us-central1"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - createEntryGroup(projectId, location, entryGroupId); - } - - // Create Entry Group. - public static void createEntryGroup(String projectId, String location, String entryGroupId) - throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - EntryGroup entryGroup = - EntryGroup.newBuilder() - .setDisplayName("MY Entry Group") - .setDescription("This Entry Group consists of ....") - .build(); - - CreateEntryGroupRequest entryGroupRequest = - CreateEntryGroupRequest.newBuilder() - .setParent(LocationName.of(projectId, location).toString()) - .setEntryGroupId(entryGroupId) - .setEntryGroup(entryGroup) - .build(); - - dataCatalogClient.createEntryGroup(entryGroupRequest); - System.out.println("Entry Group created successfully"); - } - } -} -// [END data_catalog_create_entry_group] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateFilesetEntry.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateFilesetEntry.java deleted file mode 100644 index c6e157711bbc..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateFilesetEntry.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_create_fileset] -import com.google.cloud.datacatalog.v1.ColumnSchema; -import com.google.cloud.datacatalog.v1.CreateEntryRequest; -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryType; -import com.google.cloud.datacatalog.v1.GcsFilesetSpec; -import com.google.cloud.datacatalog.v1.Schema; -import java.io.IOException; - -// Sample to create file set entry -public class CreateFilesetEntry { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "my-project-id"; - String entryGroupId = "fileset_entry_group"; - String entryId = "fileset_entry_id"; - createFilesetEntry(projectId, entryGroupId, entryId); - } - - // Create Fileset Entry. - public static void createFilesetEntry(String projectId, String entryGroupId, String entryId) - throws IOException { - // Currently, Data Catalog stores metadata in the us-central1 region. - String location = "us-central1"; - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - // Construct the Entry for the Entry request. - Entry entry = - Entry.newBuilder() - .setDisplayName("My Fileset") - .setDescription("This fileset consists of ....") - .setGcsFilesetSpec( - GcsFilesetSpec.newBuilder().addFilePatterns("gs://cloud-samples-data/*").build()) - .setSchema( - Schema.newBuilder() - .addColumns( - ColumnSchema.newBuilder() - .setColumn("first_name") - .setDescription("First name") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("last_name") - .setDescription("Last name") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("addresses") - .setDescription("Addresses") - .setMode("REPEATED") - .setType("RECORD") - .addSubcolumns( - ColumnSchema.newBuilder() - .setColumn("city") - .setDescription("City") - .setMode("NULLABLE") - .setType("STRING") - .build()) - .addSubcolumns( - ColumnSchema.newBuilder() - .setColumn("state") - .setDescription("State") - .setMode("NULLABLE") - .setType("STRING") - .build()) - .build()) - .build()) - .setType(EntryType.FILESET) - .build(); - - // Construct the Entry request to be sent by the client. - CreateEntryRequest entryRequest = - CreateEntryRequest.newBuilder() - .setParent(EntryGroupName.of(projectId, location, entryGroupId).toString()) - .setEntryId(entryId) - .setEntry(entry) - .build(); - - // Use the client to send the API request. - Entry entryCreated = dataCatalogClient.createEntry(entryRequest); - System.out.printf("Entry created with name: %s", entryCreated.getName()); - } - } -} -// [END data_catalog_create_fileset] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateTagTemplate.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateTagTemplate.java deleted file mode 100644 index 8528185c8b55..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/CreateTagTemplate.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_create_tag_template] -import com.google.cloud.datacatalog.v1.CreateTagTemplateRequest; -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.FieldType; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateField; -import java.io.IOException; - -// Sample to create tag template -public class CreateTagTemplate { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - LocationName locationName = LocationName.of(projectId, location); - String tagTemplateId = "MY_TAG_TEMPLATE_ID"; - TagTemplateField sourceField = - TagTemplateField.newBuilder() - .setDisplayName("Your display name") - .setType( - FieldType.newBuilder().setPrimitiveType(FieldType.PrimitiveType.STRING).build()) - .build(); - TagTemplate tagTemplate = - TagTemplate.newBuilder() - .setDisplayName("Your display name") - .putFields("sourceField", sourceField) - .build(); - createTagTemplate(locationName, tagTemplateId, tagTemplate); - } - - public static void createTagTemplate( - LocationName name, String tagTemplateId, TagTemplate template) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - CreateTagTemplateRequest request = - CreateTagTemplateRequest.newBuilder() - .setParent(name.toString()) - .setTagTemplateId(tagTemplateId) - .setTagTemplate(template) - .build(); - client.createTagTemplate(request); - System.out.println("Tag template created successfully"); - } - } -} -// [END data_catalog_create_tag_template] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntry.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntry.java deleted file mode 100644 index 8658f7f9ceee..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntry.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_delete_entry] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteEntryRequest; -import com.google.cloud.datacatalog.v1.EntryName; -import java.io.IOException; - -// Sample to delete a entry -public class DeleteEntry { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - String entryId = "MY_ENTRY_ID"; - EntryName entryName = EntryName.of(projectId, location, entryGroupId, entryId); - deleteEntry(entryName); - } - - public static void deleteEntry(EntryName entryName) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - DeleteEntryRequest request = - DeleteEntryRequest.newBuilder().setName(entryName.toString()).build(); - client.deleteEntry(request); - System.out.println("Entry deleted successfully"); - } - } -} -// [END data_catalog_delete_entry] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntryGroup.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntryGroup.java deleted file mode 100644 index 07460d3f8cec..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteEntryGroup.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_delete_entry_group] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteEntryGroupRequest; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.IOException; - -// Sample to delete a entry group -public class DeleteEntryGroup { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId); - deleteEntryGroup(entryGroupName); - } - - public static void deleteEntryGroup(EntryGroupName entryGroupName) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - DeleteEntryGroupRequest request = - DeleteEntryGroupRequest.newBuilder().setName(entryGroupName.toString()).build(); - client.deleteEntryGroup(request); - System.out.println("Entry group deleted successfully"); - } - } -} -// [END data_catalog_delete_entry_group] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteTagTemplate.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteTagTemplate.java deleted file mode 100644 index fc1a2a04871c..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/DeleteTagTemplate.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_delete_tag_template] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteTagTemplateRequest; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.IOException; - -// Sample to delete tag template -public class DeleteTagTemplate { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String tagTemplateId = "MY_TAG_TEMPLATE_ID"; - TagTemplateName tagTemplate = TagTemplateName.of(projectId, location, tagTemplateId); - deleteTagTemplate(tagTemplate); - } - - public static void deleteTagTemplate(TagTemplateName template) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - DeleteTagTemplateRequest request = - DeleteTagTemplateRequest.newBuilder().setName(template.toString()).setForce(true).build(); - client.deleteTagTemplate(request); - System.out.println("Tag template deleted successfully"); - } - } -} -// [END data_catalog_delete_tag_template] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetEntry.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetEntry.java deleted file mode 100644 index 572af94e5d5c..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetEntry.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_get_entry] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryName; -import java.io.IOException; - -// Sample to get an entity -public class GetEntry { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - String entryId = "MY_ENTRY_ID"; - EntryName entryName = EntryName.of(projectId, location, entryGroupId, entryId); - getEntry(entryName); - } - - public static void getEntry(EntryName entryName) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - Entry entry = client.getEntry(entryName); - System.out.println("Entry retrieved successfully: " + entry.getName()); - } - } -} -// [END data_catalog_get_entry] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetEntryGroup.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetEntryGroup.java deleted file mode 100644 index ee73efff8aec..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetEntryGroup.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_get_entry_group] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.EntryGroup; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.IOException; - -// Sample to get an entity group -public class GetEntryGroup { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId); - getEntryGroup(entryGroupName); - } - - public static void getEntryGroup(EntryGroupName entryGroupName) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - EntryGroup entryGroup = client.getEntryGroup(entryGroupName); - System.out.println("Entry group retrieved successfully: " + entryGroup.getName()); - } - } -} -// [END data_catalog_get_entry_group] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetTagTemplate.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetTagTemplate.java deleted file mode 100644 index 8d7e76caa462..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GetTagTemplate.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_get_tag_template] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.GetTagTemplateRequest; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.IOException; - -// Sample to get tag template -public class GetTagTemplate { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String tagTemplateId = "MY_TAG_TEMPLATE_ID"; - TagTemplateName tagTemplate = TagTemplateName.of(projectId, location, tagTemplateId); - getTagTemplate(tagTemplate); - } - - public static void getTagTemplate(TagTemplateName template) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - GetTagTemplateRequest request = - GetTagTemplateRequest.newBuilder().setName(template.toString()).build(); - TagTemplate tagTemplate = client.getTagTemplate(request); - System.out.println("Tag template retrieved successfully :" + tagTemplate.getName()); - } - } -} -// [END data_catalog_get_tag_template] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GrantTagTemplateUserRole.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GrantTagTemplateUserRole.java deleted file mode 100644 index 72af7d79bb78..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/GrantTagTemplateUserRole.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_grant_tag_template_user_role] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import com.google.iam.v1.Binding; -import com.google.iam.v1.Policy; -import com.google.iam.v1.SetIamPolicyRequest; -import java.io.IOException; - -// Sample to grant tag access on template -public class GrantTagTemplateUserRole { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "my-project"; - String tagTemplateId = "my_tag_template"; - grantTagTemplateUserRole(projectId, tagTemplateId); - } - - public static void grantTagTemplateUserRole(String projectId, String templateId) - throws IOException { - // Currently, Data Catalog stores metadata in the us-central1 region. - String location = "us-central1"; - - // Format the Template name. - String templateName = - TagTemplateName.newBuilder() - .setProject(projectId) - .setLocation(location) - .setTagTemplate(templateId) - .build() - .toString(); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - - // Create a Binding to add the Tag Template User role and member to the policy. - Binding binding = - Binding.newBuilder() - .setRole("roles/datacatalog.tagTemplateUser") - .addMembers("group:example-analyst-group@google.com") - .build(); - - // Create a Policy object to update Template's IAM policy by adding the new binding. - Policy policyUpdate = Policy.newBuilder().addBindings(binding).build(); - - SetIamPolicyRequest request = - SetIamPolicyRequest.newBuilder() - .setPolicy(policyUpdate) - .setResource(templateName) - .build(); - - // Update Template's policy. - dataCatalogClient.setIamPolicy(request); - System.out.println("Role successfully granted"); - } - } -} -// [END data_catalog_grant_tag_template_user_role] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/ListEntries.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/ListEntries.java deleted file mode 100644 index c635e5917e18..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/ListEntries.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_list_entries] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.IOException; - -// Sample to get list of entries -public class ListEntries { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId); - listEntries(entryGroupName); - } - - public static void listEntries(EntryGroupName entryGroupName) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - DataCatalogClient.ListEntriesPagedResponse listEntries = client.listEntries(entryGroupName); - listEntries - .iterateAll() - .forEach( - entry -> { - System.out.println("Entry name : " + entry.getName()); - }); - } - } -} -// [END data_catalog_list_entries] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/ListEntryGroups.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/ListEntryGroups.java deleted file mode 100644 index aa6194e52687..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/ListEntryGroups.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_list_entry_groups] - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.ListEntryGroupsRequest; -import com.google.cloud.datacatalog.v1.LocationName; -import java.io.IOException; - -// Sample to get list of entry group -public class ListEntryGroups { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - LocationName name = LocationName.of(projectId, location); - listEntryGroups(name); - } - - public static void listEntryGroups(LocationName name) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - ListEntryGroupsRequest request = - ListEntryGroupsRequest.newBuilder().setParent(name.toString()).build(); - DataCatalogClient.ListEntryGroupsPagedResponse listEntryGroups = - client.listEntryGroups(request); - listEntryGroups - .iterateAll() - .forEach( - entryGroup -> { - System.out.println("Entry group name : " + entryGroup.getName()); - }); - } - } -} -// [END data_catalog_list_entry_groups] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryDataset.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryDataset.java deleted file mode 100644 index 95482148c20a..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryDataset.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START datacatalog_bigquery_lookup_dataset] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.LookupEntryRequest; - -public class LookupEntryBigQueryDataset { - - /** - * Lookup the Data Catalog entry referring to a BigQuery Dataset - * - * @param projectId The project ID to which the Dataset belongs, e.g. 'my-project' - * @param datasetId The dataset ID to which the Catalog Entry refers, e.g. 'my_dataset' - */ - public static void lookupEntry(String projectId, String datasetId) { - // String projectId = "my-project" - // String datasetId = "my_dataset" - - // Get an entry by the resource name from the source Google Cloud Platform service. - String linkedResource = - String.format("//bigquery.googleapis.com/projects/%s/datasets/%s", projectId, datasetId); - LookupEntryRequest request = - LookupEntryRequest.newBuilder().setLinkedResource(linkedResource).build(); - - // Alternatively, lookup by the SQL name of the entry would have the same result: - // String sqlResource = String.format("bigquery.dataset.`%s`.`%s`", projectId, datasetId); - // LookupEntryRequest request = - // LookupEntryRequest.newBuilder().setSqlResource(sqlResource).build(); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - Entry entry = dataCatalogClient.lookupEntry(request); - System.out.printf("Entry name: %s\n", entry.getName()); - } catch (Exception e) { - System.out.print("Error during lookupEntryBigQueryDataset:\n" + e.toString()); - } - } -} -// [END datacatalog_bigquery_lookup_dataset] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryTable.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryTable.java deleted file mode 100644 index 0cf8b2ff740c..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryBigQueryTable.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.LookupEntryRequest; - -public class LookupEntryBigQueryTable { - - /** - * Lookup the Data Catalog entry referring to a BigQuery Table - * - * @param projectId The project ID to which the Dataset belongs, e.g. 'my-project' - * @param datasetId The dataset ID to which the Table belongs, e.g. 'my_dataset' - * @param tableId The table ID to which the Catalog Entry refers, e.g. 'my_table' - */ - public static void lookupEntry(String projectId, String datasetId, String tableId) { - // String projectId = "my-project" - // String datasetId = "my_dataset" - // String tableId = "my_table" - - // Get an entry by the resource name from the source Google Cloud Platform service. - String linkedResource = - String.format( - "//bigquery.googleapis.com/projects/%s/datasets/%s/tables/%s", - projectId, datasetId, tableId); - LookupEntryRequest request = - LookupEntryRequest.newBuilder().setLinkedResource(linkedResource).build(); - - // Alternatively, lookup by the SQL name of the entry would have the same result: - // String sqlResource = String.format("bigquery.table.`%s`.`%s`.`%s`", projectId, datasetId, - // tableId); - // LookupEntryRequest request = - // LookupEntryRequest.newBuilder().setSqlResource(sqlResource).build(); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - Entry entry = dataCatalogClient.lookupEntry(request); - System.out.printf("Entry name: %s\n", entry.getName()); - } catch (Exception e) { - System.out.print("Error during lookupEntryBigQueryTable:\n" + e.toString()); - } - } -} diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryPubSubTopic.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryPubSubTopic.java deleted file mode 100644 index 9db4c4c53c44..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/LookupEntryPubSubTopic.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.LookupEntryRequest; - -public class LookupEntryPubSubTopic { - - /** - * Lookup the Data Catalog entry referring to a BigQuery Dataset - * - * @param projectId The project ID to which the Dataset belongs, e.g. 'my-project' - * @param topicId The topic ID to which the Catalog Entry refers, e.g. 'my-topic' - */ - public static void lookupEntry(String projectId, String topicId) { - // String projectId = "my-project" - // String topicId = "my-topic" - - // Get an entry by the resource name from the source Google Cloud Platform service. - String linkedResource = - String.format("//pubsub.googleapis.com/projects/%s/topics/%s", projectId, topicId); - LookupEntryRequest request = - LookupEntryRequest.newBuilder().setLinkedResource(linkedResource).build(); - - // Alternatively, lookup by the SQL name of the entry would have the same result: - // String sqlResource = String.format("pubsub.topic.`%s`.`%s`", projectId, topicId); - // LookupEntryRequest request = - // LookupEntryRequest.newBuilder().setSqlResource(sqlResource).build(); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - Entry entry = dataCatalogClient.lookupEntry(request); - System.out.printf("Entry name: %s\n", entry.getName()); - } catch (Exception e) { - System.out.print("Error during lookupEntryPubSubTopic:\n" + e.toString()); - } - } -} diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/Quickstart.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/Quickstart.java deleted file mode 100644 index fcd8ff4854f7..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/Quickstart.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_quickstart] -import com.google.cloud.datacatalog.v1.CreateTagRequest; -import com.google.cloud.datacatalog.v1.CreateTagTemplateRequest; -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.FieldType; -import com.google.cloud.datacatalog.v1.FieldType.EnumType; -import com.google.cloud.datacatalog.v1.FieldType.EnumType.EnumValue; -import com.google.cloud.datacatalog.v1.FieldType.PrimitiveType; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.LookupEntryRequest; -import com.google.cloud.datacatalog.v1.Tag; -import com.google.cloud.datacatalog.v1.TagField; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateField; -import java.io.IOException; - -public class Quickstart { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "my-project"; - String tagTemplateId = "my_tag_template"; - createTags(projectId, tagTemplateId); - } - - public static void createTags(String projectId, String tagTemplateId) throws IOException { - // Currently, Data Catalog stores metadata in the us-central1 region. - String location = "us-central1"; - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - - // ------------------------------- - // Create a Tag Template. - // ------------------------------- - TagTemplateField sourceField = - TagTemplateField.newBuilder() - .setDisplayName("Source of data asset") - .setType(FieldType.newBuilder().setPrimitiveType(PrimitiveType.STRING).build()) - .build(); - - TagTemplateField numRowsField = - TagTemplateField.newBuilder() - .setDisplayName("Number of rows in data asset") - .setType(FieldType.newBuilder().setPrimitiveType(PrimitiveType.DOUBLE).build()) - .build(); - - TagTemplateField hasPiiField = - TagTemplateField.newBuilder() - .setDisplayName("Has PII") - .setType(FieldType.newBuilder().setPrimitiveType(PrimitiveType.BOOL).build()) - .build(); - - TagTemplateField piiTypeField = - TagTemplateField.newBuilder() - .setDisplayName("PII type") - .setType( - FieldType.newBuilder() - .setEnumType( - EnumType.newBuilder() - .addAllowedValues( - EnumValue.newBuilder().setDisplayName("EMAIL").build()) - .addAllowedValues( - EnumValue.newBuilder() - .setDisplayName("SOCIAL SECURITY NUMBER") - .build()) - .addAllowedValues( - EnumValue.newBuilder().setDisplayName("NONE").build()) - .build()) - .build()) - .build(); - - TagTemplate tagTemplate = - TagTemplate.newBuilder() - .setDisplayName("Demo Tag Template") - .putFields("source", sourceField) - .putFields("num_rows", numRowsField) - .putFields("has_pii", hasPiiField) - .putFields("pii_type", piiTypeField) - .build(); - - CreateTagTemplateRequest createTagTemplateRequest = - CreateTagTemplateRequest.newBuilder() - .setParent( - LocationName.newBuilder() - .setProject(projectId) - .setLocation(location) - .build() - .toString()) - .setTagTemplateId(tagTemplateId) - .setTagTemplate(tagTemplate) - .build(); - - // Create the Tag Template. - tagTemplate = dataCatalogClient.createTagTemplate(createTagTemplateRequest); - - // ------------------------------- - // Lookup Data Catalog's Entry referring to the table. - // ------------------------------- - String linkedResource = - String.format( - "//bigquery.googleapis.com/projects/%s/datasets/test_dataset/tables/test_table", - projectId); - LookupEntryRequest lookupEntryRequest = - LookupEntryRequest.newBuilder().setLinkedResource(linkedResource).build(); - Entry tableEntry = dataCatalogClient.lookupEntry(lookupEntryRequest); - - // ------------------------------- - // Attach a Tag to the table. - // ------------------------------- - TagField sourceValue = - TagField.newBuilder().setStringValue("Copied from tlc_yellow_trips_2017").build(); - TagField numRowsValue = TagField.newBuilder().setDoubleValue(113496874).build(); - TagField hasPiiValue = TagField.newBuilder().setBoolValue(false).build(); - TagField piiTypeValue = - TagField.newBuilder() - .setEnumValue(TagField.EnumValue.newBuilder().setDisplayName("NONE").build()) - .build(); - - Tag tag = - Tag.newBuilder() - .setTemplate(tagTemplate.getName()) - .putFields("source", sourceValue) - .putFields("num_rows", numRowsValue) - .putFields("has_pii", hasPiiValue) - .putFields("pii_type", piiTypeValue) - .build(); - - CreateTagRequest createTagRequest = - CreateTagRequest.newBuilder().setParent(tableEntry.getName()).setTag(tag).build(); - - dataCatalogClient.createTag(createTagRequest); - System.out.printf("Tag created successfully"); - } - } -} -// [END data_catalog_quickstart] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/SearchAssets.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/SearchAssets.java deleted file mode 100644 index 98d8d247d2f5..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/SearchAssets.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_search_assets] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DataCatalogClient.SearchCatalogPagedResponse; -import com.google.cloud.datacatalog.v1.SearchCatalogRequest; -import com.google.cloud.datacatalog.v1.SearchCatalogRequest.Scope; -import com.google.cloud.datacatalog.v1.SearchCatalogResult; -import java.io.IOException; - -// Sample to search catalog -public class SearchAssets { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "my-project-id"; - String query = "type=dataset"; - searchCatalog(projectId, query); - } - - public static void searchCatalog(String projectId, String query) throws IOException { - // Create a scope object setting search boundaries to the given organization. - // Scope scope = Scope.newBuilder().addIncludeOrgIds(orgId).build(); - - // Alternatively, search using project scopes. - Scope scope = Scope.newBuilder().addIncludeProjectIds(projectId).build(); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - // Search the catalog. - SearchCatalogRequest searchCatalogRequest = - SearchCatalogRequest.newBuilder().setScope(scope).setQuery(query).build(); - SearchCatalogPagedResponse response = dataCatalogClient.searchCatalog(searchCatalogRequest); - - System.out.println("Search results:"); - for (SearchCatalogResult result : response.iterateAll()) { - System.out.println(result); - } - } - } -} -// [END data_catalog_search_assets] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntry.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntry.java deleted file mode 100644 index ea965215b7fd..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntry.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_update_entry] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryName; -import com.google.cloud.datacatalog.v1.UpdateEntryRequest; -import com.google.protobuf.FieldMask; -import com.google.protobuf.util.FieldMaskUtil; -import java.io.IOException; - -// Sample to update an entity -public class UpdateEntry { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - String entryId = "MY_ENTRY_ID"; - String description = "MY_DESCRIPTION"; - EntryName entryName = EntryName.of(projectId, location, entryGroupId, entryId); - Entry entry = - Entry.newBuilder().setName(entryName.toString()).setDescription(description).build(); - updateEntry(entry); - } - - public static void updateEntry(Entry entry) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - FieldMask fieldMask = FieldMaskUtil.fromString("description"); - UpdateEntryRequest request = - UpdateEntryRequest.newBuilder().setEntry(entry).setUpdateMask(fieldMask).build(); - Entry entryUpdate = client.updateEntry(request); - System.out.println("Entry updated successfully : " + entryUpdate.getDescription()); - } - } -} -// [END data_catalog_update_entry] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntryGroup.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntryGroup.java deleted file mode 100644 index 5c8bf3f3eb96..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateEntryGroup.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_update_entry_group] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.EntryGroup; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.UpdateEntryGroupRequest; -import com.google.protobuf.FieldMask; -import com.google.protobuf.util.FieldMaskUtil; -import java.io.IOException; - -// Sample to update an entity group -public class UpdateEntryGroup { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String entryGroupId = "MY_ENTRY_GROUP_ID"; - String description = "MY_DESCRIPTION"; - EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId); - EntryGroup entryGroup = - EntryGroup.newBuilder() - .setName(entryGroupName.toString()) - .setDescription(description) - .build(); - updateEntryGroup(entryGroup); - } - - public static void updateEntryGroup(EntryGroup entryGroup) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - FieldMask fieldMask = FieldMaskUtil.fromString("description"); - UpdateEntryGroupRequest request = - UpdateEntryGroupRequest.newBuilder() - .setEntryGroup(entryGroup) - .setUpdateMask(fieldMask) - .build(); - EntryGroup entryGroupUpdate = client.updateEntryGroup(request); - System.out.println("Entry group updated successfully : " + entryGroupUpdate.getDescription()); - } - } -} -// [END data_catalog_update_entry_group] diff --git a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateTagTemplate.java b/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateTagTemplate.java deleted file mode 100644 index ebef7ea1df94..000000000000 --- a/java-datacatalog/samples/snippets/src/main/java/com/example/datacatalog/UpdateTagTemplate.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -// [START data_catalog_update_tag_template] -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import com.google.cloud.datacatalog.v1.UpdateTagTemplateRequest; -import com.google.protobuf.FieldMask; -import com.google.protobuf.util.FieldMaskUtil; -import java.io.IOException; - -// Sample to update tag template -public class UpdateTagTemplate { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "MY_PROJECT_ID"; - String location = "MY_LOCATION"; - String tagTemplateId = "MY_TAG_TEMPLATE_ID"; - String displayName = "MY_DISPLAY_NAME"; - TagTemplateName tagTemplate = TagTemplateName.of(projectId, location, tagTemplateId); - TagTemplate template = - TagTemplate.newBuilder() - .setName(tagTemplate.toString()) - .setDisplayName(displayName) - .build(); - updateTagTemplate(template); - } - - public static void updateTagTemplate(TagTemplate template) throws IOException { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (DataCatalogClient client = DataCatalogClient.create()) { - FieldMask fieldMask = FieldMaskUtil.fromString("display_name"); - UpdateTagTemplateRequest request = - UpdateTagTemplateRequest.newBuilder() - .setTagTemplate(template) - .setUpdateMask(fieldMask) - .build(); - TagTemplate tagTemplateUpdate = client.updateTagTemplate(request); - System.out.println( - "Tag template updated successfully : " + tagTemplateUpdate.getDisplayName()); - } - } -} -// [END data_catalog_update_tag_template] diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateCustomEntryIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateCustomEntryIT.java deleted file mode 100644 index 5a81d7e540eb..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateCustomEntryIT.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteEntryGroupRequest; -import com.google.cloud.datacatalog.v1.DeleteEntryRequest; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateCustomEntryIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entry; - private String entryGroup; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - entry = "CREATE_CUSTOM_ENTRY_TEST_" + ID; - entryGroup = "CREATE_CUSTOME_ENTRY_GROUP_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws IOException { - // Clean up - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroup, entry); - DeleteEntryRequest entryRequest = - DeleteEntryRequest.newBuilder().setName(entryName.toString()).build(); - dataCatalogClient.deleteEntry(entryRequest); - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - DeleteEntryGroupRequest request = - DeleteEntryGroupRequest.newBuilder().setName(name.toString()).build(); - dataCatalogClient.deleteEntryGroup(request); - } - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateCustomEntry() throws IOException { - CreateCustomEntry.createCustomEntry(PROJECT_ID, entryGroup, entry); - assertThat(bout.toString()).contains("Custom entry created with name:"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryGroupIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryGroupIT.java deleted file mode 100644 index af023f3f8ede..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryGroupIT.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteEntryGroupRequest; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateEntryGroupIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryGroup; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - entryGroup = "CREATE_ENTRY_GROUP_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws IOException { - // Clean up - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - DeleteEntryGroupRequest request = - DeleteEntryGroupRequest.newBuilder().setName(name.toString()).build(); - dataCatalogClient.deleteEntryGroup(request); - } - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateEntryGroup() throws IOException { - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroup); - assertThat(bout.toString()).contains("Entry Group created"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryIT.java deleted file mode 100644 index 9260584e64a0..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryIT.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.ColumnSchema; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import com.google.cloud.datacatalog.v1.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateEntryIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryId; - private String entryGroupId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - entryId = "CREATE_ENTRY_TEST_" + ID; - entryGroupId = "CREATE_ENTRY_GROUP_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId); - } - - @After - public void tearDown() throws IOException { - // Clean up - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId); - DeleteEntry.deleteEntry(entryName); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - DeleteEntryGroup.deleteEntryGroup(entryGroupName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateEntry() throws IOException { - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - Entry entry = - Entry.newBuilder() - .setUserSpecifiedSystem("onprem_data_system") - .setUserSpecifiedType("onprem_data_asset") - .setDisplayName("My awesome data asset") - .setDescription("This data asset is managed by an external system.") - .setLinkedResource("//my-onprem-server.com/dataAssets/my-awesome-data-asset") - .setSchema( - Schema.newBuilder() - .addColumns( - ColumnSchema.newBuilder() - .setColumn("first_column") - .setDescription("This columns consists of ....") - .setMode("NULLABLE") - .setType("DOUBLE") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("second_column") - .setDescription("This columns consists of ....") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .build()) - .build(); - CreateEntry.createEntry(entryGroupName, entryId, entry); - assertThat(bout.toString()).contains("Entry created successfully"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryTests.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryTests.java deleted file mode 100644 index ede7e254c826..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateEntryTests.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.fail; - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import org.hamcrest.CoreMatchers; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Integration (system) tests for {@link CreateFilesetEntry} and {@link CreateEntryGroup}. */ -@RunWith(JUnit4.class) -public class CreateEntryTests { - - private ByteArrayOutputStream bout; - - private static String LOCATION = "us-central1"; - private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT"); - - private static List entryGroupsPendingDeletion = new ArrayList<>(); - private static List entriesPendingDeletion = new ArrayList<>(); - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - } - - @After - public void tearDown() { - System.setOut(null); - bout.reset(); - } - - @AfterClass - public static void tearDownClass() { - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - // Must delete Entries before deleting the Entry Group. - if (entriesPendingDeletion.isEmpty() || entryGroupsPendingDeletion.isEmpty()) { - fail("Something went wrong, no entries were generated"); - } - - for (String entryName : entriesPendingDeletion) { - dataCatalogClient.deleteEntry(entryName); - } - - for (String entryGroupName : entryGroupsPendingDeletion) { - dataCatalogClient.deleteEntryGroup(entryGroupName); - } - } catch (Exception e) { - System.out.println("Error in cleaning up test data:\n" + e.toString()); - } - } - - @Test - public void testCreateFilesetEntry() throws IOException { - String entryGroupId = "fileset_entry_group_parent_" + getUuid8Chars(); - String entryId = "fileset_entry_id_" + getUuid8Chars(); - - // Must create a Entry Group before creating the entry. - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId); - CreateFilesetEntry.createFilesetEntry(PROJECT_ID, entryGroupId, entryId); - - // Store names for clean up on teardown - String expectedEntryGroupName = - EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId).toString(); - entryGroupsPendingDeletion.add(expectedEntryGroupName); - - String expectedEntryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId).toString(); - entriesPendingDeletion.add(expectedEntryName); - - String output = bout.toString(); - - String entryTemplate = "Entry created with name: %s"; - assertThat( - output, CoreMatchers.containsString(String.format(entryTemplate, expectedEntryName))); - } - - @Test - public void testCreateEntryGroup() throws IOException { - String entryGroupId = "entry_group_no_children_" + getUuid8Chars(); - - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId); - - // Store names for clean up on teardown - String expectedEntryGroupName = - EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId).toString(); - entryGroupsPendingDeletion.add(expectedEntryGroupName); - - String output = bout.toString(); - - String entryGroupTemplate = "Entry Group created successfully"; - assertThat( - output, - CoreMatchers.containsString(String.format(entryGroupTemplate, expectedEntryGroupName))); - } - - private String getUuid8Chars() { - return UUID.randomUUID().toString().substring(0, 8); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateFilesetEntryIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateFilesetEntryIT.java deleted file mode 100644 index 2b8147f67cb3..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateFilesetEntryIT.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteEntryGroupRequest; -import com.google.cloud.datacatalog.v1.DeleteEntryRequest; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateFilesetEntryIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryGroup; - private String entry; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - entryGroup = "CREATE_ENTRY_GROUP_TEST_" + ID; - entry = "CREATE_ENTRY_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroup); - } - - @After - public void tearDown() throws IOException { - // Clean up - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroup, entry); - DeleteEntryRequest entryRequest = - DeleteEntryRequest.newBuilder().setName(entryName.toString()).build(); - dataCatalogClient.deleteEntry(entryRequest); - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - DeleteEntryGroupRequest request = - DeleteEntryGroupRequest.newBuilder().setName(name.toString()).build(); - dataCatalogClient.deleteEntryGroup(request); - } - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateFilesetEntry() throws IOException { - CreateFilesetEntry.createFilesetEntry(PROJECT_ID, entryGroup, entry); - assertThat(bout.toString()).contains("Entry created with name:"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateTagTemplateIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateTagTemplateIT.java deleted file mode 100644 index 037440d1cfa2..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/CreateTagTemplateIT.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.FieldType; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateField; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CreateTagTemplateIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tagTemplateId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - tagTemplateId = "create_tag_template_test_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws IOException { - // Clean up - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - DeleteTagTemplate.deleteTagTemplate(name); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testCreateTagTemplate() throws IOException { - LocationName locationName = LocationName.of(PROJECT_ID, LOCATION); - TagTemplateField sourceField = - TagTemplateField.newBuilder() - .setDisplayName("Your display name") - .setType( - FieldType.newBuilder().setPrimitiveType(FieldType.PrimitiveType.STRING).build()) - .build(); - TagTemplate tagTemplate = - TagTemplate.newBuilder() - .setDisplayName("Your display name") - .putFields("sourceField", sourceField) - .build(); - CreateTagTemplate.createTagTemplate(locationName, tagTemplateId, tagTemplate); - assertThat(bout.toString()).contains("Tag template created successfully"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryGroupIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryGroupIT.java deleted file mode 100644 index 6f5fac2ce750..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryGroupIT.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteEntryGroupIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryGroup; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - entryGroup = "DELETE_ENTRY_GROUP_TEST_" + ID; - // create temporary entry group - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroup); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testDeleteEntryGroup() throws IOException { - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - DeleteEntryGroup.deleteEntryGroup(name); - assertThat(bout.toString()).contains("Entry group deleted successfully"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryIT.java deleted file mode 100644 index 124c298927e2..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryIT.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.ColumnSchema; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import com.google.cloud.datacatalog.v1.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteEntryIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryId; - private String entryGroupId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - entryId = "DELETE_ENTRY_TEST_" + ID; - entryGroupId = "DELETE_ENTRY_GROUP_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a temporary entry group and entry - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - Entry entry = - Entry.newBuilder() - .setUserSpecifiedSystem("onprem_data_system") - .setUserSpecifiedType("onprem_data_asset") - .setDisplayName("My awesome data asset") - .setDescription("This data asset is managed by an external system.") - .setLinkedResource("//my-onprem-server.com/dataAssets/my-awesome-data-asset") - .setSchema( - Schema.newBuilder() - .addColumns( - ColumnSchema.newBuilder() - .setColumn("first_column") - .setDescription("This columns consists of ....") - .setMode("NULLABLE") - .setType("DOUBLE") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("second_column") - .setDescription("This columns consists of ....") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .build()) - .build(); - CreateEntry.createEntry(entryGroupName, entryId, entry); - } - - @After - public void tearDown() throws IOException { - // Clean up - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - DeleteEntryGroup.deleteEntryGroup(entryGroupName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testDeleteEntry() throws IOException { - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId); - DeleteEntry.deleteEntry(entryName); - assertThat(bout.toString()).contains("Entry deleted successfully"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteTagTemplateIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteTagTemplateIT.java deleted file mode 100644 index d979845fa219..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/DeleteTagTemplateIT.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.FieldType; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateField; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeleteTagTemplateIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tagTemplateId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - tagTemplateId = "delete_tag_template_test_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a tempory tag template - LocationName locationName = LocationName.of(PROJECT_ID, LOCATION); - TagTemplateField sourceField = - TagTemplateField.newBuilder() - .setDisplayName("Your display name") - .setType( - FieldType.newBuilder().setPrimitiveType(FieldType.PrimitiveType.STRING).build()) - .build(); - TagTemplate tagTemplate = - TagTemplate.newBuilder() - .setDisplayName("Your display name") - .putFields("sourceField", sourceField) - .build(); - CreateTagTemplate.createTagTemplate(locationName, tagTemplateId, tagTemplate); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testDeleteTagTemplate() throws IOException { - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - DeleteTagTemplate.deleteTagTemplate(name); - assertThat(bout.toString()).contains("Tag template deleted successfully"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetEntryGroupIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetEntryGroupIT.java deleted file mode 100644 index 0034e00aae32..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetEntryGroupIT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetEntryGroupIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryGroup; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - entryGroup = "GET_ENTRY_GROUP_TEST_" + ID; - // create temporary entry group - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroup); - } - - @After - public void tearDown() throws IOException { - // clean up - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - DeleteEntryGroup.deleteEntryGroup(name); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testGetEntryGroup() throws IOException { - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - GetEntryGroup.getEntryGroup(name); - assertThat(bout.toString()).contains("Entry group retrieved successfully:"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetEntryIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetEntryIT.java deleted file mode 100644 index 7693ade9db29..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetEntryIT.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.ColumnSchema; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import com.google.cloud.datacatalog.v1.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetEntryIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryId; - private String entryGroupId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - entryId = "GET_ENTRY_TEST_" + ID; - entryGroupId = "GET_ENTRY_GROUP_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - Entry entry = - Entry.newBuilder() - .setUserSpecifiedSystem("onprem_data_system") - .setUserSpecifiedType("onprem_data_asset") - .setDisplayName("My awesome data asset") - .setDescription("This data asset is managed by an external system.") - .setLinkedResource("//my-onprem-server.com/dataAssets/my-awesome-data-asset") - .setSchema( - Schema.newBuilder() - .addColumns( - ColumnSchema.newBuilder() - .setColumn("first_column") - .setDescription("This columns consists of ....") - .setMode("NULLABLE") - .setType("DOUBLE") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("second_column") - .setDescription("This columns consists of ....") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .build()) - .build(); - CreateEntry.createEntry(entryGroupName, entryId, entry); - } - - @After - public void tearDown() throws IOException { - // Clean up - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId); - DeleteEntry.deleteEntry(entryName); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - DeleteEntryGroup.deleteEntryGroup(entryGroupName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testGetEntry() throws IOException { - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId); - GetEntry.getEntry(entryName); - assertThat(bout.toString()).contains("Entry retrieved successfully:"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetTagTemplateIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetTagTemplateIT.java deleted file mode 100644 index 374b896f2555..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GetTagTemplateIT.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.FieldType; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateField; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GetTagTemplateIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tagTemplateId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - tagTemplateId = "get_tag_template_test_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a tempory tag template - LocationName locationName = LocationName.of(PROJECT_ID, LOCATION); - TagTemplateField sourceField = - TagTemplateField.newBuilder() - .setDisplayName("Your display name") - .setType( - FieldType.newBuilder().setPrimitiveType(FieldType.PrimitiveType.STRING).build()) - .build(); - TagTemplate tagTemplate = - TagTemplate.newBuilder() - .setDisplayName("Your display name") - .putFields("sourceField", sourceField) - .build(); - CreateTagTemplate.createTagTemplate(locationName, tagTemplateId, tagTemplate); - } - - @After - public void tearDown() throws IOException { - // clean up - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - DeleteTagTemplate.deleteTagTemplate(name); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testGetTagTemplate() throws IOException { - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - GetTagTemplate.getTagTemplate(name); - assertThat(bout.toString()).contains("Tag template retrieved successfully"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GrantTagTemplateUserRoleIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GrantTagTemplateUserRoleIT.java deleted file mode 100644 index 0837ab16fb65..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/GrantTagTemplateUserRoleIT.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.CreateTagTemplateRequest; -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteTagTemplateRequest; -import com.google.cloud.datacatalog.v1.FieldType; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateField; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class GrantTagTemplateUserRoleIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tagTemplateId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - tagTemplateId = "create_tag_template_id_test_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - LocationName parent = LocationName.of(PROJECT_ID, LOCATION); - TagTemplateField sourceField = - TagTemplateField.newBuilder() - .setDisplayName("Source of data asset") - .setType( - FieldType.newBuilder().setPrimitiveType(FieldType.PrimitiveType.STRING).build()) - .build(); - TagTemplate tagTemplate = - TagTemplate.newBuilder() - .setDisplayName("Demo Tag Template") - .putFields("source", sourceField) - .build(); - CreateTagTemplateRequest request = - CreateTagTemplateRequest.newBuilder() - .setParent(parent.toString()) - .setTagTemplateId(tagTemplateId) - .setTagTemplate(tagTemplate) - .build(); - dataCatalogClient.createTagTemplate(request); - } - } - - @After - public void tearDown() throws IOException { - // Clean up - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - boolean force = true; - DeleteTagTemplateRequest request = - DeleteTagTemplateRequest.newBuilder().setName(name.toString()).setForce(force).build(); - dataCatalogClient.deleteTagTemplate(request); - } - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testGrantTagTemplateUserRole() throws IOException { - GrantTagTemplateUserRole.grantTagTemplateUserRole(PROJECT_ID, tagTemplateId); - assertThat(bout.toString()).contains("Role successfully granted"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/ListEntriesIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/ListEntriesIT.java deleted file mode 100644 index 1e85fee21318..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/ListEntriesIT.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.ColumnSchema; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import com.google.cloud.datacatalog.v1.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ListEntriesIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryId; - private String entryGroupId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - entryId = "LIST_ENTRIES_TEST_" + ID; - entryGroupId = "LIST_ENTRIES_GROUP_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - Entry entry = - Entry.newBuilder() - .setUserSpecifiedSystem("onprem_data_system") - .setUserSpecifiedType("onprem_data_asset") - .setDisplayName("My awesome data asset") - .setDescription("This data asset is managed by an external system.") - .setLinkedResource("//my-onprem-server.com/dataAssets/my-awesome-data-asset") - .setSchema( - Schema.newBuilder() - .addColumns( - ColumnSchema.newBuilder() - .setColumn("first_column") - .setDescription("This columns consists of ....") - .setMode("NULLABLE") - .setType("DOUBLE") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("second_column") - .setDescription("This columns consists of ....") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .build()) - .build(); - CreateEntry.createEntry(entryGroupName, entryId, entry); - } - - @After - public void tearDown() throws IOException { - // Clean up - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId); - DeleteEntry.deleteEntry(entryName); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - DeleteEntryGroup.deleteEntryGroup(entryGroupName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testListEntries() throws IOException { - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - ListEntries.listEntries(entryGroupName); - assertThat(bout.toString()).contains("Entry name :"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/ListEntryGroupsIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/ListEntryGroupsIT.java deleted file mode 100644 index 9426878a4aaa..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/ListEntryGroupsIT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.LocationName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ListEntryGroupsIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryGroup; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - entryGroup = "LIST_ENTRY_GROUPS_TEST_" + ID; - // create temporary entry group - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroup); - } - - @After - public void tearDown() throws IOException { - // clean up - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - DeleteEntryGroup.deleteEntryGroup(name); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testListEntryGroups() throws IOException { - ListEntryGroups.listEntryGroups(LocationName.of(PROJECT_ID, LOCATION)); - assertThat(bout.toString()).contains("Entry group name :"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/LookupEntryTests.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/LookupEntryTests.java deleted file mode 100644 index bf254fec42e6..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/LookupEntryTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class LookupEntryTests { - - private static final String BIGQUERY_PROJECT = "bigquery-public-data"; - private static final String BIGQUERY_DATASET = "new_york_taxi_trips"; - private static final String BIGQUERY_TABLE = "taxi_zone_geom"; - - private static final String PUBSUB_PROJECT = "pubsub-public-data"; - private static final String PUBSUB_TOPIC = "taxirides-realtime"; - - private ByteArrayOutputStream bout; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(bout); - System.setOut(out); - } - - @After - public void tearDown() throws IOException { - bout.close(); - System.setOut(null); - } - - @Test - public void testLookupEntryBigQueryDataset() { - LookupEntryBigQueryDataset.lookupEntry(BIGQUERY_PROJECT, BIGQUERY_DATASET); - String got = bout.toString(); - assertThat(got) - .containsMatch( - "projects/" + BIGQUERY_PROJECT + "/locations/.+?/entryGroups/@bigquery/entries/.+?$"); - } - - @Test - public void testLookupEntryBigQueryTable() { - LookupEntryBigQueryTable.lookupEntry(BIGQUERY_PROJECT, BIGQUERY_DATASET, BIGQUERY_TABLE); - String got = bout.toString(); - assertThat(got) - .containsMatch( - "projects/" + BIGQUERY_PROJECT + "/locations/.+?/entryGroups/@bigquery/entries/.+?$"); - } - - @Test - public void testLookupPubSubTopic() { - LookupEntryPubSubTopic.lookupEntry(PUBSUB_PROJECT, PUBSUB_TOPIC); - String got = bout.toString(); - assertThat(got) - .containsMatch( - "projects/" + PUBSUB_PROJECT + "/locations/.+?/entryGroups/@pubsub/entries/.+?$"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/QuickstartIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/QuickstartIT.java deleted file mode 100644 index e48d3e410776..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/QuickstartIT.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.DataCatalogClient; -import com.google.cloud.datacatalog.v1.DeleteTagTemplateRequest; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class QuickstartIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tagTemplateId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - tagTemplateId = "quickstart_tag_template_id_test_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws IOException { - // Clean up - try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - boolean force = true; - DeleteTagTemplateRequest request = - DeleteTagTemplateRequest.newBuilder().setName(name.toString()).setForce(force).build(); - dataCatalogClient.deleteTagTemplate(request); - } - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testQuickstart() throws IOException { - Quickstart.createTags(PROJECT_ID, tagTemplateId); - assertThat(bout.toString()).contains("Tag created successfully"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/SearchAssetsIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/SearchAssetsIT.java deleted file mode 100644 index d0090243fddb..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/SearchAssetsIT.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SearchAssetsIT { - - private final Logger log = Logger.getLogger(this.getClass().getName()); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testSearchAssets() throws IOException { - SearchAssets.searchCatalog(PROJECT_ID, "type=dataset"); - assertThat(bout.toString()).contains("Search results:"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryGroupIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryGroupIT.java deleted file mode 100644 index aac12d51017f..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryGroupIT.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.EntryGroup; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateEntryGroupIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryGroup; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - entryGroup = "UPDATE_ENTRY_GROUP_TEST_" + ID; - // create temporary entry group - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroup); - } - - @After - public void tearDown() throws IOException { - // clean up - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - DeleteEntryGroup.deleteEntryGroup(name); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testUpdateEntryGroup() throws IOException { - EntryGroupName name = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroup); - EntryGroup entryGroup = - EntryGroup.newBuilder().setName(name.toString()).setDescription("test-description").build(); - UpdateEntryGroup.updateEntryGroup(entryGroup); - assertThat(bout.toString()).contains("Entry group updated successfully :"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryIT.java deleted file mode 100644 index cc289bb219b5..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryIT.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2020 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.ColumnSchema; -import com.google.cloud.datacatalog.v1.Entry; -import com.google.cloud.datacatalog.v1.EntryGroupName; -import com.google.cloud.datacatalog.v1.EntryName; -import com.google.cloud.datacatalog.v1.Schema; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateEntryIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String entryId; - private String entryGroupId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - entryId = "UPDATE_ENTRY_TEST_" + ID; - entryGroupId = "UPDATE_ENTRY_GROUP_TEST_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - Entry entry = - Entry.newBuilder() - .setUserSpecifiedSystem("onprem_data_system") - .setUserSpecifiedType("onprem_data_asset") - .setDisplayName("My awesome data asset") - .setDescription("This data asset is managed by an external system.") - .setLinkedResource("//my-onprem-server.com/dataAssets/my-awesome-data-asset") - .setSchema( - Schema.newBuilder() - .addColumns( - ColumnSchema.newBuilder() - .setColumn("first_column") - .setDescription("This columns consists of ....") - .setMode("NULLABLE") - .setType("DOUBLE") - .build()) - .addColumns( - ColumnSchema.newBuilder() - .setColumn("second_column") - .setDescription("This columns consists of ....") - .setMode("REQUIRED") - .setType("STRING") - .build()) - .build()) - .build(); - CreateEntry.createEntry(entryGroupName, entryId, entry); - } - - @After - public void tearDown() throws IOException { - // Clean up - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId); - DeleteEntry.deleteEntry(entryName); - EntryGroupName entryGroupName = EntryGroupName.of(PROJECT_ID, LOCATION, entryGroupId); - DeleteEntryGroup.deleteEntryGroup(entryGroupName); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testUpdateEntry() throws IOException { - EntryName entryName = EntryName.of(PROJECT_ID, LOCATION, entryGroupId, entryId); - Entry entry = - Entry.newBuilder().setName(entryName.toString()).setDescription("test_description").build(); - UpdateEntry.updateEntry(entry); - assertThat(bout.toString()).contains("Entry updated successfully :"); - } -} diff --git a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateTagTemplateIT.java b/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateTagTemplateIT.java deleted file mode 100644 index 5f351ac16730..000000000000 --- a/java-datacatalog/samples/snippets/src/test/java/com/example/datacatalog/UpdateTagTemplateIT.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.datacatalog; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.datacatalog.v1.FieldType; -import com.google.cloud.datacatalog.v1.LocationName; -import com.google.cloud.datacatalog.v1.TagTemplate; -import com.google.cloud.datacatalog.v1.TagTemplateField; -import com.google.cloud.datacatalog.v1.TagTemplateName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UpdateTagTemplateIT { - - private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String LOCATION = "us-central1"; - private final Logger log = Logger.getLogger(this.getClass().getName()); - private String tagTemplateId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() throws IOException { - tagTemplateId = "update_tag_template_test_" + ID; - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - // create a tempory tag template - LocationName locationName = LocationName.of(PROJECT_ID, LOCATION); - TagTemplateField sourceField = - TagTemplateField.newBuilder() - .setDisplayName("Your display name") - .setType( - FieldType.newBuilder().setPrimitiveType(FieldType.PrimitiveType.STRING).build()) - .build(); - TagTemplate tagTemplate = - TagTemplate.newBuilder() - .setDisplayName("Your display name") - .putFields("sourceField", sourceField) - .build(); - CreateTagTemplate.createTagTemplate(locationName, tagTemplateId, tagTemplate); - } - - @After - public void tearDown() throws IOException { - // clean up - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - DeleteTagTemplate.deleteTagTemplate(name); - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - log.log(Level.INFO, bout.toString()); - } - - @Test - public void testUpdateTagTemplate() throws IOException { - TagTemplateName name = TagTemplateName.of(PROJECT_ID, LOCATION, tagTemplateId); - TagTemplate template = - TagTemplate.newBuilder() - .setName(name.toString()) - .setDisplayName("test_display_name") - .build(); - UpdateTagTemplate.updateTagTemplate(template); - assertThat(bout.toString()).contains("Tag template updated successfully :"); - } -}