diff --git a/google-cloud-core/src/main/java/com/google/cloud/testing/SmokeTest.java b/google-cloud-core/src/main/java/com/google/cloud/testing/SmokeTest.java new file mode 100644 index 000000000000..2ac1706665c4 --- /dev/null +++ b/google-cloud-core/src/main/java/com/google/cloud/testing/SmokeTest.java @@ -0,0 +1,21 @@ +/* + * Copyright 2016 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.google.cloud.testing; + +public interface SmokeTest {} + diff --git a/google-cloud-dlp/pom.xml b/google-cloud-dlp/pom.xml index d41f6e404f9c..4cce45431955 100644 --- a/google-cloud-dlp/pom.xml +++ b/google-cloud-dlp/pom.xml @@ -53,6 +53,11 @@ junit test + + commons-lang + commons-lang + test + org.easymock easymock diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceSmokeTest.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceSmokeTest.java new file mode 100644 index 000000000000..fb699c2cc442 --- /dev/null +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceSmokeTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2018 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 + * + * https://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.google.cloud.dlp.v2beta1; + +import com.google.privacy.dlp.v2beta1.ContentItem; +import com.google.privacy.dlp.v2beta1.InspectConfig; +import com.google.privacy.dlp.v2beta1.InspectContentResponse; +import com.google.privacy.dlp.v2beta1.Likelihood; +import com.google.cloud.testing.SmokeTest; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.junit.Test; +import org.junit.experimental.categories.Category; + + +@Category(SmokeTest.class) +@javax.annotation.Generated("by GAPIC") +public class DlpServiceSmokeTest { + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (DlpServiceClient client = DlpServiceClient.create()) { + Likelihood minLikelihood = Likelihood.POSSIBLE; + InspectConfig inspectConfig = + InspectConfig.newBuilder().setMinLikelihood(minLikelihood).build(); + String type = "text/plain"; + String value = "my phone number is 215-512-1212"; + ContentItem itemsElement = ContentItem.newBuilder().setType(type).setValue(value).build(); + List items = Arrays.asList(itemsElement); + + InspectContentResponse response = client.inspectContent(inspectConfig, items); + System.out.println( + ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE)); + } + } +} diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml index 7192a1de3063..d39081a5fa7b 100644 --- a/google-cloud-pubsub/pom.xml +++ b/google-cloud-pubsub/pom.xml @@ -62,6 +62,16 @@ junit test + + commons-lang + commons-lang + test + + + commons-cli + commons-cli + test + org.easymock easymock diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminSmokeTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminSmokeTest.java new file mode 100644 index 000000000000..3aa0b91e8a1f --- /dev/null +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminSmokeTest.java @@ -0,0 +1,115 @@ +/* + * Copyright 2018 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 + * + * https://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.google.cloud.pubsub.v1; + +import static com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse; + +import com.google.common.base.Preconditions; +import com.google.pubsub.v1.ProjectName; +import java.util.logging.Level; +import java.util.logging.Logger; +import com.google.cloud.testing.SmokeTest; +import org.junit.experimental.categories.Category; +import org.junit.Test; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.lang.builder.ReflectionToStringBuilder; + + + +@Category(SmokeTest.class) +@javax.annotation.Generated("by GAPIC") +public class TopicAdminSmokeTest { + @Test + public void run() { + Logger.getLogger("").setLevel(Level.WARNING); + try { + String projectId = getProjectId(); + executeNoCatch(projectId); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + String projectId = getProjectId(); + if (projectId == null) { + projectId = tryParseProjectIdFromCmdline(args); + } + executeNoCatch(projectId); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + Preconditions.checkArgument(projectId != null, "A project ID is required."); + try (TopicAdminClient client = TopicAdminClient.create()) { + ProjectName project = ProjectName.of(projectId); + + ListTopicsPagedResponse pagedResponse = client.listTopics(project); + System.out.println(pagedResponse.toString()); + } + } + + private static String tryParseProjectIdFromCmdline(String args[]) { + try { + Options options = new Options(); + options.addOption("h", "help", false, "show usage"); + options.addOption( + Option.builder() + .longOpt("project_id") + .desc("Project id") + .hasArg() + .argName("PROJECT-ID") + .required(true) + .build()); + CommandLine cl = (new DefaultParser()).parse(options, args); + if (cl.hasOption("help")) { + HelpFormatter formater = new HelpFormatter(); + formater.printHelp("TopicAdminSmokeTest", options); + } + return cl.getOptionValue("project_id"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + return ""; + } + + private static String getProjectId() { + final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + return projectId; + } +} diff --git a/pom.xml b/pom.xml index 36fe10fbc298..c8e211272860 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ - + 4.0.0 com.google.cloud @@ -355,6 +355,16 @@ junit 4.12 + + commons-lang + commons-lang + 2.6 + + + commons-cli + commons-cli + 1.4 + org.hamcrest hamcrest-core @@ -429,12 +439,6 @@ google-cloud-util google-cloud - - - @@ -865,5 +869,44 @@ + + + + smoke-test + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.19.1 + + + + integration-test + verify + + + + + + **/*SmokeTest.java + + + **/*IT.java + + com.google.cloud.testing.SmokeTest + + + + org.apache.maven.plugins + maven-surefire-plugin + + + true + + + + +