diff --git a/talent/snippets/pom.xml b/talent/snippets/pom.xml new file mode 100644 index 00000000000..684910bb9dd --- /dev/null +++ b/talent/snippets/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + com.google.cloud + talent-snippets + jar + Google Talent Solution Snippets + https://github.com/googleapis/java-talent + + + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + 1.8 + 1.8 + UTF-8 + + + + + + + com.google.cloud + libraries-bom + 26.1.4 + pom + import + + + + + + + com.google.cloud + google-cloud-talent + + + + junit + junit + 4.13.2 + test + + + com.google.truth + truth + 1.1.3 + test + + + diff --git a/talent/snippets/src/main/java/com/example/jobs/CommuteSearchJobs.java b/talent/snippets/src/main/java/com/example/jobs/CommuteSearchJobs.java new file mode 100644 index 00000000000..3218faac986 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/CommuteSearchJobs.java @@ -0,0 +1,95 @@ +/* + * 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.jobs; + +// [START job_search_commute_search] + +import com.google.cloud.talent.v4.CommuteFilter; +import com.google.cloud.talent.v4.CommuteMethod; +import com.google.cloud.talent.v4.Job; +import com.google.cloud.talent.v4.JobQuery; +import com.google.cloud.talent.v4.JobServiceClient; +import com.google.cloud.talent.v4.RequestMetadata; +import com.google.cloud.talent.v4.SearchJobsRequest; +import com.google.cloud.talent.v4.SearchJobsResponse; +import com.google.cloud.talent.v4.TenantName; +import com.google.protobuf.Duration; +import com.google.type.LatLng; +import java.io.IOException; + +public class CommuteSearchJobs { + + public static void searchJobs() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + searchJobs(projectId, tenantId); + } + + // Search Jobs with histogram queries. + public static void searchJobs(String projectId, String tenantId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + String domain = "www.example.com"; + String sessionId = "Hashed session identifier"; + String userId = "Hashed user identifier"; + RequestMetadata requestMetadata = + RequestMetadata.newBuilder() + .setDomain(domain) + .setSessionId(sessionId) + .setUserId(userId) + .build(); + + CommuteMethod commuteMethod = CommuteMethod.DRIVING; + long seconds = 3600L; + Duration travelDuration = Duration.newBuilder().setSeconds(seconds).build(); + + double latitude = 37.422408; + double longitude = -122.084068; + LatLng startCoordinates = + LatLng.newBuilder().setLatitude(latitude).setLongitude(longitude).build(); + + CommuteFilter commuteFilter = + CommuteFilter.newBuilder() + .setCommuteMethod(commuteMethod) + .setTravelDuration(travelDuration) + .setStartCoordinates(startCoordinates) + .build(); + + JobQuery jobQuery = JobQuery.newBuilder().setCommuteFilter(commuteFilter).build(); + SearchJobsRequest request = + SearchJobsRequest.newBuilder() + .setParent(parent.toString()) + .setRequestMetadata(requestMetadata) + .setJobQuery(jobQuery) + .build(); + + for (SearchJobsResponse.MatchingJob responseItem : + jobServiceClient.searchJobs(request).getMatchingJobsList()) { + System.out.format("Job summary: %s%n", responseItem.getJobSummary()); + System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet()); + Job job = responseItem.getJob(); + System.out.format("Job name: %s%n", job.getName()); + System.out.format("Job title: %s%n", job.getTitle()); + } + } + } +} +// [END job_search_commute_search] diff --git a/talent/snippets/src/main/java/com/example/jobs/CustomRankingSearchJobs.java b/talent/snippets/src/main/java/com/example/jobs/CustomRankingSearchJobs.java new file mode 100644 index 00000000000..cf0e95d4448 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/CustomRankingSearchJobs.java @@ -0,0 +1,81 @@ +/* + * 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.jobs; + +// [START job_search_custom_ranking_search] + +import com.google.cloud.talent.v4.Job; +import com.google.cloud.talent.v4.JobServiceClient; +import com.google.cloud.talent.v4.RequestMetadata; +import com.google.cloud.talent.v4.SearchJobsRequest; +import com.google.cloud.talent.v4.SearchJobsResponse; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; + +public class CustomRankingSearchJobs { + + public static void searchCustomRankingJobs() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + searchCustomRankingJobs(projectId, tenantId); + } + + // Search Jobs using custom rankings. + public static void searchCustomRankingJobs(String projectId, String tenantId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + String domain = "www.example.com"; + String sessionId = "Hashed session identifier"; + String userId = "Hashed user identifier"; + RequestMetadata requestMetadata = + RequestMetadata.newBuilder() + .setDomain(domain) + .setSessionId(sessionId) + .setUserId(userId) + .build(); + SearchJobsRequest.CustomRankingInfo.ImportanceLevel importanceLevel = + SearchJobsRequest.CustomRankingInfo.ImportanceLevel.EXTREME; + String rankingExpression = "(someFieldLong + 25) * 0.25"; + SearchJobsRequest.CustomRankingInfo customRankingInfo = + SearchJobsRequest.CustomRankingInfo.newBuilder() + .setImportanceLevel(importanceLevel) + .setRankingExpression(rankingExpression) + .build(); + String orderBy = "custom_ranking desc"; + SearchJobsRequest request = + SearchJobsRequest.newBuilder() + .setParent(parent.toString()) + .setRequestMetadata(requestMetadata) + .setCustomRankingInfo(customRankingInfo) + .setOrderBy(orderBy) + .build(); + for (SearchJobsResponse.MatchingJob responseItem : + jobServiceClient.searchJobs(request).getMatchingJobsList()) { + System.out.format("Job summary: %s%n", responseItem.getJobSummary()); + System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet()); + Job job = responseItem.getJob(); + System.out.format("Job name: %s%n", job.getName()); + System.out.format("Job title: %s%n", job.getTitle()); + } + } + } +} +// [END job_search_custom_ranking_search] diff --git a/talent/snippets/src/main/java/com/example/jobs/HistogramSearchJobs.java b/talent/snippets/src/main/java/com/example/jobs/HistogramSearchJobs.java new file mode 100644 index 00000000000..5f6bde45f11 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/HistogramSearchJobs.java @@ -0,0 +1,78 @@ +/* + * 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.jobs; + +// [START job_search_histogram_search] + +import com.google.cloud.talent.v4.HistogramQuery; +import com.google.cloud.talent.v4.Job; +import com.google.cloud.talent.v4.JobServiceClient; +import com.google.cloud.talent.v4.RequestMetadata; +import com.google.cloud.talent.v4.SearchJobsRequest; +import com.google.cloud.talent.v4.SearchJobsResponse; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; + +public class HistogramSearchJobs { + + public static void searchJobs() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String query = "count(base_compensation, [bucket(12, 20)])"; + searchJobs(projectId, tenantId, query); + } + + // Search Jobs with histogram queries. + public static void searchJobs(String projectId, String tenantId, String query) + 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + + String domain = "http://www.jobUrl.com"; + String sessionId = "Hashed session identifier"; + String userId = "Hashed user identifier"; + RequestMetadata requestMetadata = + RequestMetadata.newBuilder() + .setDomain(domain) + .setSessionId(sessionId) + .setUserId(userId) + .build(); + HistogramQuery histogramQueriesElement = + HistogramQuery.newBuilder().setHistogramQuery(query).build(); + SearchJobsRequest request = + SearchJobsRequest.newBuilder() + .setParent(parent.toString()) + .setRequestMetadata(requestMetadata) + .addHistogramQueries(histogramQueriesElement) + .build(); + + for (SearchJobsResponse.MatchingJob responseItem : + jobServiceClient.searchJobs(request).getMatchingJobsList()) { + System.out.format("Job summary: %s%n", responseItem.getJobSummary()); + System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet()); + Job job = responseItem.getJob(); + System.out.format("Job name: %s%n", job.getName()); + System.out.format("Job title: %s%n", job.getTitle()); + } + } + } +} +// [END job_search_histogram_search] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java new file mode 100644 index 00000000000..321e416d0f9 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchAutoCompleteJobTitle.java @@ -0,0 +1,61 @@ +/* + * 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.jobs; + +// [START job_search_autocomplete_job_title] + +import com.google.cloud.talent.v4.CompleteQueryRequest; +import com.google.cloud.talent.v4.CompleteQueryResponse; +import com.google.cloud.talent.v4.CompletionClient; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; + +public class JobSearchAutoCompleteJobTitle { + + public static void completeQuery() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String query = "your-query-for-job-title"; + completeQuery(projectId, tenantId, query); + } + + // Complete job title given partial text (autocomplete). + public static void completeQuery(String projectId, String tenantId, String query) + 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 (CompletionClient completionClient = CompletionClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + CompleteQueryRequest request = + CompleteQueryRequest.newBuilder() + .setTenant(parent.toString()) + .setQuery(query) + .setPageSize(5) // limit for number of results + .addLanguageCodes("en-US") // language code + .build(); + CompleteQueryResponse response = completionClient.completeQuery(request); + for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) { + System.out.format("Suggested title: %s%n", result.getSuggestion()); + // Suggestion type is JOB_TITLE or COMPANY_TITLE + System.out.format("Suggestion type: %s%n", result.getType()); + } + } + } +} +// [END job_search_autocomplete_job_title] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java new file mode 100644 index 00000000000..5de517e8b21 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateClientEvent.java @@ -0,0 +1,85 @@ +/* + * 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.jobs; + +// [START job_search_create_client_event] + +import com.google.cloud.talent.v4.ClientEvent; +import com.google.cloud.talent.v4.CreateClientEventRequest; +import com.google.cloud.talent.v4.EventServiceClient; +import com.google.cloud.talent.v4.JobEvent; +import com.google.cloud.talent.v4.TenantName; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +public class JobSearchCreateClientEvent { + + public static void createClientEvent() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String requestId = "your-req-id-from-response-metadata"; + String eventId = "your-unique-identifier-id"; + createClientEvent(projectId, tenantId, requestId, eventId); + } + + // Creates a client event. + public static void createClientEvent( + String projectId, String tenantId, String requestId, String eventId) 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 (EventServiceClient eventServiceClient = EventServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + + // The timestamp of the event as seconds of UTC time since Unix epoch + // For more information on how to create google.protobuf.Timestamps + // See: + // https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/timestamp.proto + long seconds = 3L; + Timestamp createTime = Timestamp.newBuilder().setSeconds(seconds).build(); + + // The type of event attributed to the behavior of the end user + JobEvent.JobEventType type = JobEvent.JobEventType.VIEW; + + // List of job names associated with this event + String jobsElement = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]"; + String jobsElement2 = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]"; + + List jobs = Arrays.asList(jobsElement, jobsElement2); + JobEvent jobEvent = JobEvent.newBuilder().setType(type).addAllJobs(jobs).build(); + ClientEvent clientEvent = + ClientEvent.newBuilder() + .setRequestId(requestId) + .setEventId(eventId) + .setCreateTime(createTime) + .setJobEvent(jobEvent) + .build(); + CreateClientEventRequest request = + CreateClientEventRequest.newBuilder() + .setParent(parent.toString()) + .setClientEvent(clientEvent) + .build(); + ClientEvent response = eventServiceClient.createClientEvent(request); + System.out.println("Created client event. "); + System.out.println(response.toString()); + } + } +} +// [END job_search_create_client_event] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateCompany.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateCompany.java new file mode 100644 index 00000000000..587c48e459f --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateCompany.java @@ -0,0 +1,63 @@ +/* + * 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.jobs; + +// [START job_search_create_company_beta] + +import com.google.cloud.talent.v4.Company; +import com.google.cloud.talent.v4.CompanyServiceClient; +import com.google.cloud.talent.v4.CreateCompanyRequest; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; + +public class JobSearchCreateCompany { + + public static void createCompany() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String displayName = "your-company-display-name"; + String externalId = "your-external-id"; + createCompany(projectId, tenantId, displayName, externalId); + } + + // Create a company. + public static void createCompany( + String projectId, String tenantId, String displayName, String externalId) 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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + Company company = + Company.newBuilder().setDisplayName(displayName).setExternalId(externalId).build(); + + CreateCompanyRequest request = + CreateCompanyRequest.newBuilder() + .setParent(parent.toString()) + .setCompany(company) + .build(); + + Company response = companyServiceClient.createCompany(request); + System.out.println("Created Company"); + System.out.format("Name: %s%n", response.getName()); + System.out.format("Display Name: %s%n", response.getDisplayName()); + System.out.format("External ID: %s%n", response.getExternalId()); + } + } +} +// [END job_search_create_company_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateJob.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateJob.java new file mode 100644 index 00000000000..af2dad8e62c --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateJob.java @@ -0,0 +1,88 @@ +/* + * 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.jobs; + +// [START job_search_create_job_beta] + +import com.google.cloud.talent.v4.CreateJobRequest; +import com.google.cloud.talent.v4.Job; +import com.google.cloud.talent.v4.JobServiceClient; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +public class JobSearchCreateJob { + + public static void createJob() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String companyId = "your-company-id"; + String requisitionId = "your-unique-req-id"; + String jobApplicationUrl = "your-job-url"; + // String projectId = "me-qa-1"; + // String tenantId = "8ed97629-27ee-4215-909b-18cfe3b7e8e3"; + // String companyId = "05317758-b30e-4b26-a57d-d9e54e4cccd8"; + // String requisitionId = "test-requisitionid-1"; + // String jobApplicationUrl = "http://job.url"; + createJob(projectId, tenantId, companyId, requisitionId, jobApplicationUrl); + } + + // Create a job. + public static void createJob( + String projectId, + String tenantId, + String companyId, + String requisitionId, + String jobApplicationUrl) + 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + Job.ApplicationInfo applicationInfo = + Job.ApplicationInfo.newBuilder().addUris(jobApplicationUrl).build(); + + List addresses = + Arrays.asList( + "1600 Amphitheatre Parkway, Mountain View, CA 94043", + "111 8th Avenue, New York, NY 10011"); + + // By default, job will expire in 30 days. + // https://cloud.google.com/talent-solution/job-search/docs/jobs + Job job = + Job.newBuilder() + .setCompany(companyId) + .setRequisitionId(requisitionId) + .setTitle("Software Developer") + .setDescription("Develop, maintain the software solutions.") + .setApplicationInfo(applicationInfo) + .addAllAddresses(addresses) + .setLanguageCode("en-US") + .build(); + + CreateJobRequest request = + CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build(); + + Job response = jobServiceClient.createJob(request); + System.out.format("Created job: %s%n", response.getName()); + } + } +} +// [END job_search_create_job_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java new file mode 100644 index 00000000000..7e79d55a0e2 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateJobCustomAttributes.java @@ -0,0 +1,75 @@ +/* + * 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.jobs; + +// [START job_search_create_job_custom_attributes] + +import com.google.cloud.talent.v4.CreateJobRequest; +import com.google.cloud.talent.v4.CustomAttribute; +import com.google.cloud.talent.v4.Job; +import com.google.cloud.talent.v4.JobServiceClient; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; + +public class JobSearchCreateJobCustomAttributes { + + public static void createJob() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String companyId = "your-company-id"; + String requisitionId = "your-unique-req-id"; + createJob(projectId, tenantId, companyId, requisitionId); + } + + // Create Job with Custom Attributes. + public static void createJob( + String projectId, String tenantId, String companyId, String requisitionId) + 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + + // Custom attribute can be string or numeric value, and can be filtered in search queries. + // https://cloud.google.com/talent-solution/job-search/docs/custom-attributes + CustomAttribute customAttribute = + CustomAttribute.newBuilder() + .addStringValues("Internship") + .addStringValues("Apprenticeship") + .setFilterable(true) + .build(); + + Job job = + Job.newBuilder() + .setCompany(companyId) + .setTitle("Software Developer I") + .setDescription("This is a description of this wonderful job!") + .putCustomAttributes("FOR_STUDENTS", customAttribute) + .setRequisitionId(requisitionId) + .setLanguageCode("en-US") + .build(); + + CreateJobRequest request = + CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build(); + Job response = jobServiceClient.createJob(request); + System.out.printf("Created job: %s\n", response.getName()); + } + } +} +// [END job_search_create_job_custom_attributes] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateTenant.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateTenant.java new file mode 100644 index 00000000000..abcab4a9d69 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchCreateTenant.java @@ -0,0 +1,55 @@ +/* + * 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.jobs; + +// [START job_search_create_tenant_beta] + +import com.google.cloud.talent.v4.CreateTenantRequest; +import com.google.cloud.talent.v4.ProjectName; +import com.google.cloud.talent.v4.Tenant; +import com.google.cloud.talent.v4.TenantServiceClient; +import java.io.IOException; + +public class JobSearchCreateTenant { + + public static void createTenant() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String externalId = "your-external-id"; + createTenant(projectId, externalId); + } + + // Create Tenant for scoping resources, e.g. companies and jobs. + public static void createTenant(String projectId, String externalId) 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 (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { + ProjectName parent = ProjectName.of(projectId); + Tenant tenant = Tenant.newBuilder().setExternalId(externalId).build(); + + CreateTenantRequest request = + CreateTenantRequest.newBuilder().setParent(parent.toString()).setTenant(tenant).build(); + + Tenant response = tenantServiceClient.createTenant(request); + System.out.println("Created Tenant"); + System.out.format("Name: %s%n", response.getName()); + System.out.format("External ID: %s%n", response.getExternalId()); + } + } +} +// [END job_search_create_tenant_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteCompany.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteCompany.java new file mode 100644 index 00000000000..5472de65566 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteCompany.java @@ -0,0 +1,53 @@ +/* + * 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.jobs; + +// [START job_search_delete_company_beta] + +import com.google.cloud.talent.v4.CompanyName; +import com.google.cloud.talent.v4.CompanyServiceClient; +import com.google.cloud.talent.v4.DeleteCompanyRequest; +import java.io.IOException; + +public class JobSearchDeleteCompany { + + public static void deleteCompany() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String companyId = "your-company-id"; + deleteCompany(projectId, tenantId, companyId); + } + + // Delete Company. + public static void deleteCompany(String projectId, String tenantId, String companyId) + 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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) { + CompanyName name = CompanyName.of(projectId, tenantId, companyId); + + DeleteCompanyRequest request = + DeleteCompanyRequest.newBuilder().setName(name.toString()).build(); + + companyServiceClient.deleteCompany(request); + System.out.println("Deleted company"); + } + } +} +// [END job_search_delete_company_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteJob.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteJob.java new file mode 100644 index 00000000000..9603f1630c3 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteJob.java @@ -0,0 +1,51 @@ +/* + * 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.jobs; + +// [START job_search_delete_job_beta] + +import com.google.cloud.talent.v4.DeleteJobRequest; +import com.google.cloud.talent.v4.JobName; +import com.google.cloud.talent.v4.JobServiceClient; +import java.io.IOException; + +public class JobSearchDeleteJob { + + public static void deleteJob() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String jobId = "your-job-id"; + deleteJob(projectId, tenantId, jobId); + } + + // Delete Job. + public static void deleteJob(String projectId, String tenantId, String jobId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + JobName name = JobName.of(projectId, tenantId, jobId); + + DeleteJobRequest request = DeleteJobRequest.newBuilder().setName(name.toString()).build(); + + jobServiceClient.deleteJob(request); + System.out.println("Deleted job."); + } + } +} +// [END job_search_delete_job_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteTenant.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteTenant.java new file mode 100644 index 00000000000..d7f949f49cd --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchDeleteTenant.java @@ -0,0 +1,51 @@ +/* + * 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.jobs; + +// [START job_search_delete_tenant_beta] + +import com.google.cloud.talent.v4.DeleteTenantRequest; +import com.google.cloud.talent.v4.TenantName; +import com.google.cloud.talent.v4.TenantServiceClient; +import java.io.IOException; + +public class JobSearchDeleteTenant { + + public static void deleteTenant() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + deleteTenant(projectId, tenantId); + } + + // Delete Tenant. + public static void deleteTenant(String projectId, String tenantId) 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 (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { + TenantName name = TenantName.of(projectId, tenantId); + + DeleteTenantRequest request = + DeleteTenantRequest.newBuilder().setName(name.toString()).build(); + + tenantServiceClient.deleteTenant(request); + System.out.println("Deleted Tenant."); + } + } +} +// [END job_search_delete_tenant_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchGetCompany.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchGetCompany.java new file mode 100644 index 00000000000..9a4da2d076e --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchGetCompany.java @@ -0,0 +1,54 @@ +/* + * 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.jobs; + +// [START job_search_get_company_beta] + +import com.google.cloud.talent.v4.Company; +import com.google.cloud.talent.v4.CompanyName; +import com.google.cloud.talent.v4.CompanyServiceClient; +import com.google.cloud.talent.v4.GetCompanyRequest; +import java.io.IOException; + +public class JobSearchGetCompany { + + public static void getCompany() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String companyId = "your-company-id"; + getCompany(projectId, tenantId, companyId); + } + + // Get Company. + public static void getCompany(String projectId, String tenantId, String companyId) + 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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) { + CompanyName name = CompanyName.of(projectId, tenantId, companyId); + + GetCompanyRequest request = GetCompanyRequest.newBuilder().setName(name.toString()).build(); + + Company response = companyServiceClient.getCompany(request); + System.out.format("Company name: %s%n", response.getName()); + System.out.format("Display name: %s%n", response.getDisplayName()); + } + } +} +// [END job_search_get_company_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchGetJob.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchGetJob.java new file mode 100644 index 00000000000..0314f149406 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchGetJob.java @@ -0,0 +1,65 @@ +/* + * 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.jobs; + +// [START job_search_get_job_beta] + +import com.google.cloud.talent.v4.GetJobRequest; +import com.google.cloud.talent.v4.Job; +import com.google.cloud.talent.v4.JobName; +import com.google.cloud.talent.v4.JobServiceClient; +import java.io.IOException; + +public class JobSearchGetJob { + + public static void getJob() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String jobId = "your-job-id"; + getJob(projectId, tenantId, jobId); + } + + // Get Job. + public static void getJob(String projectId, String tenantId, String jobId) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + JobName name = JobName.of(projectId, tenantId, jobId); + + GetJobRequest request = GetJobRequest.newBuilder().setName(name.toString()).build(); + + Job response = jobServiceClient.getJob(request); + System.out.format("Job name: %s%n", response.getName()); + System.out.format("Requisition ID: %s%n", response.getRequisitionId()); + System.out.format("Title: %s%n", response.getTitle()); + System.out.format("Description: %s%n", response.getDescription()); + System.out.format("Posting language: %s%n", response.getLanguageCode()); + for (String address : response.getAddressesList()) { + System.out.format("Address: %s%n", address); + } + for (String email : response.getApplicationInfo().getEmailsList()) { + System.out.format("Email: %s%n", email); + } + for (String websiteUri : response.getApplicationInfo().getUrisList()) { + System.out.format("Website: %s%n", websiteUri); + } + } + } +} +// [END job_search_get_job_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchGetTenant.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchGetTenant.java new file mode 100644 index 00000000000..c91631046dd --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchGetTenant.java @@ -0,0 +1,52 @@ +/* + * 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.jobs; + +// [START job_search_get_tenant_beta] + +import com.google.cloud.talent.v4.GetTenantRequest; +import com.google.cloud.talent.v4.Tenant; +import com.google.cloud.talent.v4.TenantName; +import com.google.cloud.talent.v4.TenantServiceClient; +import java.io.IOException; + +public class JobSearchGetTenant { + + public static void getTenant() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + getTenant(projectId, tenantId); + } + + // Get Tenant by name. + public static void getTenant(String projectId, String tenantId) 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 (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { + TenantName name = TenantName.of(projectId, tenantId); + + GetTenantRequest request = GetTenantRequest.newBuilder().setName(name.toString()).build(); + + Tenant response = tenantServiceClient.getTenant(request); + System.out.format("Name: %s%n", response.getName()); + System.out.format("External ID: %s%n", response.getExternalId()); + } + } +} +// [END job_search_get_tenant_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchListCompanies.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchListCompanies.java new file mode 100644 index 00000000000..0313045fdb0 --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchListCompanies.java @@ -0,0 +1,55 @@ +/* + * 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.jobs; + +// [START job_search_list_companies_beta] + +import com.google.cloud.talent.v4.Company; +import com.google.cloud.talent.v4.CompanyServiceClient; +import com.google.cloud.talent.v4.ListCompaniesRequest; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; + +public class JobSearchListCompanies { + + public static void listCompanies() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + listCompanies(projectId, tenantId); + } + + // List Companies. + public static void listCompanies(String projectId, String tenantId) 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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + + ListCompaniesRequest request = + ListCompaniesRequest.newBuilder().setParent(parent.toString()).build(); + + for (Company responseItem : companyServiceClient.listCompanies(request).iterateAll()) { + System.out.format("Company Name: %s%n", responseItem.getName()); + System.out.format("Display Name: %s%n", responseItem.getDisplayName()); + System.out.format("External ID: %s%n", responseItem.getExternalId()); + } + } + } +} +// [END job_search_list_companies_beta] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchListJobs.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchListJobs.java new file mode 100644 index 00000000000..9fe1bbc85ab --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchListJobs.java @@ -0,0 +1,55 @@ +/* + * 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.jobs; + +// [START job_search_list_jobs] + +import com.google.cloud.talent.v4.Job; +import com.google.cloud.talent.v4.JobServiceClient; +import com.google.cloud.talent.v4.ListJobsRequest; +import com.google.cloud.talent.v4.TenantName; +import java.io.IOException; + +public class JobSearchListJobs { + + public static void listJobs() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String tenantId = "your-tenant-id"; + String query = "count(base_compensation, [bucket(12, 20)])"; + listJobs(projectId, tenantId, query); + } + + // Search Jobs with histogram queries. + public static void listJobs(String projectId, String tenantId, String filter) 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 (JobServiceClient jobServiceClient = JobServiceClient.create()) { + TenantName parent = TenantName.of(projectId, tenantId); + ListJobsRequest request = + ListJobsRequest.newBuilder().setParent(parent.toString()).setFilter(filter).build(); + for (Job responseItem : jobServiceClient.listJobs(request).iterateAll()) { + System.out.format("Job name: %s%n", responseItem.getName()); + System.out.format("Job requisition ID: %s%n", responseItem.getRequisitionId()); + System.out.format("Job title: %s%n", responseItem.getTitle()); + System.out.format("Job description: %s%n", responseItem.getDescription()); + } + } + } +} +// [END job_search_list_jobs] diff --git a/talent/snippets/src/main/java/com/example/jobs/JobSearchListTenants.java b/talent/snippets/src/main/java/com/example/jobs/JobSearchListTenants.java new file mode 100644 index 00000000000..d71191f08cc --- /dev/null +++ b/talent/snippets/src/main/java/com/example/jobs/JobSearchListTenants.java @@ -0,0 +1,53 @@ +/* + * 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.jobs; + +// [START job_search_list_tenants_beta] + +import com.google.cloud.talent.v4.ListTenantsRequest; +import com.google.cloud.talent.v4.ProjectName; +import com.google.cloud.talent.v4.Tenant; +import com.google.cloud.talent.v4.TenantServiceClient; +import java.io.IOException; + +public class JobSearchListTenants { + + public static void listTenants() throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + listTenants(projectId); + } + + // List Tenants. + public static void listTenants(String projectId) 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 (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { + ProjectName parent = ProjectName.of(projectId); + + ListTenantsRequest request = + ListTenantsRequest.newBuilder().setParent(parent.toString()).build(); + + for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) { + System.out.format("Tenant Name: %s%n", responseItem.getName()); + System.out.format("External ID: %s%n", responseItem.getExternalId()); + } + } + } +} +// [END job_search_list_tenants_beta] diff --git a/talent/snippets/src/test/java/CommuteSearchJobsTest.java b/talent/snippets/src/test/java/CommuteSearchJobsTest.java new file mode 100644 index 00000000000..15836240753 --- /dev/null +++ b/talent/snippets/src/test/java/CommuteSearchJobsTest.java @@ -0,0 +1,55 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.CommuteSearchJobs; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CommuteSearchJobsTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testCommuteSearchJobs() throws IOException { + // retrieve a job. + CommuteSearchJobs.searchJobs(PROJECT_ID, TENANT_ID); + String got = bout.toString(); + + assertThat(got).contains("Job summary:"); + assertThat(got).contains("Job title snippet:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/CustomRankingSearchJobsTest.java b/talent/snippets/src/test/java/CustomRankingSearchJobsTest.java new file mode 100644 index 00000000000..2f5aa257e2b --- /dev/null +++ b/talent/snippets/src/test/java/CustomRankingSearchJobsTest.java @@ -0,0 +1,56 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.CustomRankingSearchJobs; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CustomRankingSearchJobsTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testCustomRankingSearchJobs() throws IOException { + // retrieve a job. + CustomRankingSearchJobs.searchCustomRankingJobs(PROJECT_ID, TENANT_ID); + String got = bout.toString(); + + assertThat(got).contains("Job summary:"); + assertThat(got).contains("Job title snippet:"); + assertThat(got).contains("Job title:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/HistogramSearchJobsTest.java b/talent/snippets/src/test/java/HistogramSearchJobsTest.java new file mode 100644 index 00000000000..8e2b7b043af --- /dev/null +++ b/talent/snippets/src/test/java/HistogramSearchJobsTest.java @@ -0,0 +1,55 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.HistogramSearchJobs; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class HistogramSearchJobsTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testHistogramSearch() throws IOException { + // retrieve a job. + HistogramSearchJobs.searchJobs( + PROJECT_ID, TENANT_ID, "count(base_compensation, [bucket(12, 20)])"); + String got = bout.toString(); + assertThat(got).contains("Job summary:"); + assertThat(got).contains("Job title snippet:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchAutoCompleteJobTitleTest.java b/talent/snippets/src/test/java/JobSearchAutoCompleteJobTitleTest.java new file mode 100644 index 00000000000..61b36650278 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchAutoCompleteJobTitleTest.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchAutoCompleteJobTitle; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchAutoCompleteJobTitleTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testAutoCompleteJobTitle() throws IOException { + // retrieve a tenant. + JobSearchAutoCompleteJobTitle.completeQuery(PROJECT_ID, TENANT_ID, "Developer Program"); + String got = bout.toString(); + assertThat(got).contains("Suggested title:"); + assertThat(got).contains("Suggestion type:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchCreateCompanyTest.java b/talent/snippets/src/test/java/JobSearchCreateCompanyTest.java new file mode 100644 index 00000000000..325e1af44ca --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchCreateCompanyTest.java @@ -0,0 +1,64 @@ +/* + * 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. + */ +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchCreateCompany; +import com.example.jobs.JobSearchDeleteCompany; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchCreateCompanyTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private static final String COMPANY_EXT_ID = + String.format("COMP_EXT_ID_%s", UUID.randomUUID().toString().substring(0, 20)); + private static final String COMPANY_DISPLAY_NAME = "DO_NOT_DELETE_COMPANY"; + + private String companyId; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testCreateCompany() throws IOException { + // retrieve a tenant. + JobSearchCreateCompany.createCompany( + PROJECT_ID, TENANT_ID, COMPANY_DISPLAY_NAME, COMPANY_EXT_ID); + String got = bout.toString(); + assertThat(got).contains("Created Company"); + + companyId = JobSearchGetJobTest.extractLastId(got.split("\n")[1]); + } + + @After + public void tearDown() throws IOException { + // delete that job. + JobSearchDeleteCompany.deleteCompany(PROJECT_ID, TENANT_ID, companyId); + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchCreateJobTest.java b/talent/snippets/src/test/java/JobSearchCreateJobTest.java new file mode 100644 index 00000000000..c53cf1b55a8 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchCreateJobTest.java @@ -0,0 +1,72 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchCreateJob; +import com.example.jobs.JobSearchDeleteJob; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchCreateJobTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + private static final String COMPANY_ID = System.getenv("CTS_COMPANY_ID"); + private static final String POST_UNIQUE_ID = + String.format( + "TEST_POST_ID_%s", + UUID.randomUUID().toString().substring(0, 20)); // Posting ID. Unique per job. + + private String jobId; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testCreateJob() throws IOException { + // create a job. + JobSearchCreateJob.createJob( + PROJECT_ID, TENANT_ID, COMPANY_ID, POST_UNIQUE_ID, "http://www.jobUrl.com"); + String got = bout.toString(); + + assertThat(got).contains("Created job:"); + jobId = JobSearchGetJobTest.extractLastId(got.split("\n")[0].trim()); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // delete that job. + JobSearchDeleteJob.deleteJob(PROJECT_ID, TENANT_ID, jobId); + String got = bout.toString(); + assertThat(got).contains("Deleted job"); + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchCreateJobWithCustomAttrTest.java b/talent/snippets/src/test/java/JobSearchCreateJobWithCustomAttrTest.java new file mode 100644 index 00000000000..0671921b78e --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchCreateJobWithCustomAttrTest.java @@ -0,0 +1,71 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchCreateJobCustomAttributes; +import com.example.jobs.JobSearchDeleteJob; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchCreateJobWithCustomAttrTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + private static final String COMPANY_ID = System.getenv("CTS_COMPANY_ID"); + private static final String POST_UNIQUE_ID = + String.format( + "TEST_POST_ID_%s", + UUID.randomUUID().toString().substring(0, 20)); // Posting ID. Unique per job. + + private String jobId; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testCreateJob() throws IOException { + // create a job with custom attributes. + JobSearchCreateJobCustomAttributes.createJob(PROJECT_ID, TENANT_ID, COMPANY_ID, POST_UNIQUE_ID); + String got = bout.toString(); + + assertThat(got).contains("Created job:"); + jobId = JobSearchGetJobTest.extractLastId(got.split("\n")[0].trim()); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // delete that job. + JobSearchDeleteJob.deleteJob(PROJECT_ID, TENANT_ID, jobId); + String got = bout.toString(); + assertThat(got).contains("Deleted job"); + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchCreateTenantTest.java b/talent/snippets/src/test/java/JobSearchCreateTenantTest.java new file mode 100644 index 00000000000..fdbe993233f --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchCreateTenantTest.java @@ -0,0 +1,63 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchCreateTenant; +import com.example.jobs.JobSearchDeleteTenant; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchCreateTenantTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_EXT_ID = + String.format("EXTERNAL_TEMP_TENANT_ID_%s", UUID.randomUUID().toString().substring(0, 20)); + + private String tenantId; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testCreateTenant() throws IOException { + // create a tenant. + JobSearchCreateTenant.createTenant(PROJECT_ID, TENANT_EXT_ID); + + String got = bout.toString(); + assertThat(got).contains("Created Tenant"); + + tenantId = JobSearchGetJobTest.extractLastId(got.split("\n")[1]); + } + + @After + public void tearDown() throws IOException { + + // clean up. + JobSearchDeleteTenant.deleteTenant(PROJECT_ID, tenantId); + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchDeleteCompanyTest.java b/talent/snippets/src/test/java/JobSearchDeleteCompanyTest.java new file mode 100644 index 00000000000..a321d80e0e6 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchDeleteCompanyTest.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchCreateCompany; +import com.example.jobs.JobSearchDeleteCompany; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchDeleteCompanyTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private static final String COMPANY_EXT_ID = + String.format("COMP_EXT_ID_%s", UUID.randomUUID().toString().substring(0, 20)); + private static final String COMPANY_DISPLAY_NAME = "DO_NOT_DELETE_COMPANY"; + + private String companyId; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() throws IOException { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + + // create a company + JobSearchCreateCompany.createCompany( + PROJECT_ID, TENANT_ID, COMPANY_DISPLAY_NAME, COMPANY_EXT_ID); + String got = bout.toString(); + assertThat(got).contains("Created Company"); + + companyId = JobSearchGetJobTest.extractLastId(got.split("\n")[1]); + } + + @Test + public void testDeleteCompany() throws IOException { + // retrieve a tenant. + JobSearchDeleteCompany.deleteCompany(PROJECT_ID, TENANT_ID, companyId); + String got = bout.toString(); + assertThat(got).contains("Deleted company"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchDeleteJobTest.java b/talent/snippets/src/test/java/JobSearchDeleteJobTest.java new file mode 100644 index 00000000000..7896a43d808 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchDeleteJobTest.java @@ -0,0 +1,73 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchCreateJob; +import com.example.jobs.JobSearchDeleteJob; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchDeleteJobTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + private static final String COMPANY_ID = System.getenv("CTS_COMPANY_ID"); + private static final String POST_UNIQUE_ID = + String.format( + "TEST_POST_ID_%s", + UUID.randomUUID().toString().substring(0, 20)); // Posting ID. Unique per job. + + private String jobId; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() throws IOException { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + + JobSearchCreateJob.createJob( + PROJECT_ID, TENANT_ID, COMPANY_ID, POST_UNIQUE_ID, "http://www.jobUrl.com"); + + String got = bout.toString(); + assertThat(got).contains("Created job:"); + jobId = JobSearchGetJobTest.extractLastId(got.split("\n")[0].trim()); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @Test + public void testDeleteJob() throws IOException { + // delete a job. + JobSearchDeleteJob.deleteJob(PROJECT_ID, TENANT_ID, jobId); + String got = bout.toString(); + + assertThat(got).contains("Deleted job"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchDeleteTenantTest.java b/talent/snippets/src/test/java/JobSearchDeleteTenantTest.java new file mode 100644 index 00000000000..5f2b1867572 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchDeleteTenantTest.java @@ -0,0 +1,65 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchCreateTenant; +import com.example.jobs.JobSearchDeleteTenant; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchDeleteTenantTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_EXT_ID = + String.format("EXTERNAL_TEMP_TENANT_ID_%s", UUID.randomUUID().toString().substring(0, 20)); + private String tenantId; + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() throws IOException { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + + // create a tenant for job and company + JobSearchCreateTenant.createTenant(PROJECT_ID, TENANT_EXT_ID); + + String got = bout.toString(); + assertThat(got).contains("Created Tenant"); + + tenantId = JobSearchGetJobTest.extractLastId(got.split("\n")[1]); + } + + @Test + public void testDeleteTenantTest() throws IOException { + // delete a tenant. + JobSearchDeleteTenant.deleteTenant(PROJECT_ID, tenantId); + String got = bout.toString(); + assertThat(got).contains("Deleted Tenant."); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchGetCompanyTest.java b/talent/snippets/src/test/java/JobSearchGetCompanyTest.java new file mode 100644 index 00000000000..95d915bd7d1 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchGetCompanyTest.java @@ -0,0 +1,55 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchGetCompany; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchGetCompanyTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + private static final String COMPANY_ID = System.getenv("CTS_COMPANY_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testGetCompany() throws IOException { + // retrieve a tenant. + JobSearchGetCompany.getCompany(PROJECT_ID, TENANT_ID, COMPANY_ID); + String got = bout.toString(); + assertThat(got).contains("Company name:"); + assertThat(got).contains("Display name:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchGetJobTest.java b/talent/snippets/src/test/java/JobSearchGetJobTest.java new file mode 100644 index 00000000000..ad1b9501653 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchGetJobTest.java @@ -0,0 +1,63 @@ +/* + * 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. + */ +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchGetJob; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchGetJobTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + private static final String JOB_ID = System.getenv("CTS_GET_JOB_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() throws IOException { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testGetJob() throws IOException { + // retrieve a job. + JobSearchGetJob.getJob(PROJECT_ID, TENANT_ID, JOB_ID); + String got = bout.toString(); + assertThat(got).contains("Job name: "); + assertThat(got).contains("Website:"); + } + + @After + public void tearDown() { + System.setOut(out); + } + + // Helper method for getting the last id from the full path. + public static String extractLastId(String fullPath) { + if (fullPath == null || fullPath.length() < 1 || !fullPath.contains("/")) { + throw new IllegalArgumentException("Not valid path"); + } + String[] parts = fullPath.split("/"); + return parts[parts.length - 1]; + } +} diff --git a/talent/snippets/src/test/java/JobSearchGetTenantTest.java b/talent/snippets/src/test/java/JobSearchGetTenantTest.java new file mode 100644 index 00000000000..ccd1d1b5e46 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchGetTenantTest.java @@ -0,0 +1,53 @@ +/* + * 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. + */ +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchGetTenant; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchGetTenantTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testGetTenant() throws IOException { + // retrieve a tenant. + JobSearchGetTenant.getTenant(PROJECT_ID, TENANT_ID); + String got = bout.toString(); + assertThat(got).contains("Name:"); + assertThat(got).contains("External ID:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchListCompaniesTest.java b/talent/snippets/src/test/java/JobSearchListCompaniesTest.java new file mode 100644 index 00000000000..4138c6bdfca --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchListCompaniesTest.java @@ -0,0 +1,55 @@ +/* + * 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. + */ +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchListCompanies; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchListCompaniesTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testListCompanies() throws IOException { + // retrieve a tenant. + JobSearchListCompanies.listCompanies(PROJECT_ID, TENANT_ID); + String got = bout.toString(); + assertThat(got).contains("Company Name:"); + assertThat(got).contains("Display Name:"); + assertThat(got).contains("External ID:"); + } + + @After + public void tearDown() { + // delete that job. + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchListJobsTest.java b/talent/snippets/src/test/java/JobSearchListJobsTest.java new file mode 100644 index 00000000000..c3070fccb09 --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchListJobsTest.java @@ -0,0 +1,59 @@ +/* + * 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. + */ + +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchListJobs; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchListJobsTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String TENANT_ID = System.getenv("CTS_TENANT_ID"); + private static final String COMPANY_ID = System.getenv("CTS_COMPANY_ID"); + + private static final String FILTER = "companyName=\"projects/%s/companies/%s\""; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testListJobs() throws IOException { + // retrieve a job. + JobSearchListJobs.listJobs( + PROJECT_ID, TENANT_ID, String.format(FILTER, PROJECT_ID, COMPANY_ID)); + String got = bout.toString(); + + assertThat(got).contains("Job name:"); + assertThat(got).contains("Job requisition ID:"); + assertThat(got).contains("Job title:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +} diff --git a/talent/snippets/src/test/java/JobSearchListTenantsTest.java b/talent/snippets/src/test/java/JobSearchListTenantsTest.java new file mode 100644 index 00000000000..d615bebf30c --- /dev/null +++ b/talent/snippets/src/test/java/JobSearchListTenantsTest.java @@ -0,0 +1,52 @@ +/* + * 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. + */ +import static com.google.common.truth.Truth.assertThat; + +import com.example.jobs.JobSearchListTenants; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class JobSearchListTenantsTest { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = System.out; + System.setOut(new PrintStream(bout)); + } + + @Test + public void testListTenants() throws IOException { + // retrieve a tenant. + JobSearchListTenants.listTenants(PROJECT_ID); + String got = bout.toString(); + assertThat(got).contains("Tenant Name:"); + assertThat(got).contains("External ID:"); + } + + @After + public void tearDown() { + System.setOut(out); + } +}