diff --git a/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateCustomEntryIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateCustomEntryIT.java deleted file mode 100644 index 5a81d7e540e..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateEntryGroupIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateEntryGroupIT.java deleted file mode 100644 index af023f3f8ed..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateEntryIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateEntryIT.java deleted file mode 100644 index 9260584e64a..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateEntryTests.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateEntryTests.java deleted file mode 100644 index ede7e254c82..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateFilesetEntryIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateFilesetEntryIT.java deleted file mode 100644 index 2b8147f67cb..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateTagTemplateIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/CreateTagTemplateIT.java deleted file mode 100644 index 037440d1cfa..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/DeleteEntryGroupIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/DeleteEntryGroupIT.java deleted file mode 100644 index 6f5fac2ce75..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/DeleteEntryIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/DeleteEntryIT.java deleted file mode 100644 index 124c298927e..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/DeleteTagTemplateIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/DeleteTagTemplateIT.java deleted file mode 100644 index d979845fa21..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/GetEntryGroupIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/GetEntryGroupIT.java deleted file mode 100644 index 0034e00aae3..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/GetEntryIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/GetEntryIT.java deleted file mode 100644 index 7693ade9db2..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/GetTagTemplateIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/GetTagTemplateIT.java deleted file mode 100644 index 374b896f255..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/GrantTagTemplateUserRoleIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/GrantTagTemplateUserRoleIT.java deleted file mode 100644 index 0837ab16fb6..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/ListEntriesIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/ListEntriesIT.java deleted file mode 100644 index 1e85fee2131..00000000000 --- a/datacatalog/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/datacatalog/snippets/src/test/java/com/example/datacatalog/SearchAssetsIT.java b/datacatalog/snippets/src/test/java/com/example/datacatalog/SearchAssetsIT.java index 1a5a1f941e4..8c8db074a1d 100644 --- a/datacatalog/snippets/src/test/java/com/example/datacatalog/SearchAssetsIT.java +++ b/datacatalog/snippets/src/test/java/com/example/datacatalog/SearchAssetsIT.java @@ -19,12 +19,12 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertNotNull; +import io.grpc.StatusRuntimeException; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.logging.Level; import java.util.logging.Logger; -import io.grpc.StatusRuntimeException; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -81,7 +81,7 @@ public void testSearchAssets() throws IOException { } catch (StatusRuntimeException e) { // sleep for 1 minute try { - Thread.sleep(60000); + Thread.sleep(80000); } catch (InterruptedException ie) { // stop sleep earlier }