Skip to content

Commit

Permalink
Refactor tests jobs v3 (#3503)
Browse files Browse the repository at this point in the history
Fixes #3455 


- [X] Please **merge** this PR for me once it is approved.
  • Loading branch information
munkhuushmgl authored Aug 12, 2020
1 parent 1b091f1 commit c07417c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void commuteSearch(String companyName) throws IOException, Interru
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
.execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Search jobs for commute results: %s\n", response);
}
// [END commute_search]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void filtersOnStringValueCustomAttribute()
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
.execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Custom search job results (String value): %s\n", response);
}
// [END custom_attribute_filter_string_value]

Expand Down Expand Up @@ -142,7 +142,7 @@ public static void filtersOnLongValueCustomAttribute() throws IOException, Inter
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
.execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Custom search job results (Long value): %s\n", response);
}
// [END custom_attribute_filter_long_value]

Expand Down Expand Up @@ -177,7 +177,7 @@ public static void filtersOnMultiCustomAttributes() throws IOException, Interrup
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
.execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Custom search job results (multiple value): %s\n", response);
}
// [END custom_attribute_filter_multi_attributes]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void searchForAlerts(String companyName) throws IOException, Inter
.searchForAlert(DEFAULT_PROJECT_ID, request)
.execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Search jobs for alert results: %s\n", response);
}
// [END search_for_alerts]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public static void searchFeaturedJobs(String companyName)
.jobs()
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
.execute();

Thread.sleep(1000);
System.out.println(response);
System.out.printf("Featured jobs results: %s\n", response);
}
// [END search_featured_job]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public static void basicSearcJobs(String companyName, String query)
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Simple search jobs results: %s\n", searchJobsResponse);
}
// [END basic_keyword_search]

Expand Down Expand Up @@ -131,7 +130,7 @@ public static void categoryFilterSearch(String companyName, List<String> categor
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Category search jobs results: %s\n", searchJobsResponse);
}
// [END category_filter]

Expand Down Expand Up @@ -169,7 +168,7 @@ public static void employmentTypesSearch(String companyName, List<String> employ
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Employee type search jobs results: %s\n", searchJobsResponse);
}
// [END employment_types_filter]

Expand Down Expand Up @@ -216,7 +215,7 @@ public static void dateRangeSearch(String companyName, String startTime, String
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Search results on jobs with a date range: %s\n", searchJobsResponse);
}
// [END date_range_filter]

Expand Down Expand Up @@ -254,7 +253,7 @@ public static void languageCodeSearch(String companyName, List<String> languageC
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Search results on jobs with a language code: %s\n", searchJobsResponse);
}
// [END language_code_filter]

Expand Down Expand Up @@ -292,7 +291,7 @@ public static void companyDisplayNameSearch(String companyName, List<String> com
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Search results by display name of company: %s\n", searchJobsResponse);
}
// [END company_display_name_filter]

Expand Down Expand Up @@ -344,7 +343,7 @@ public static void compensationSearch(String companyName)
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Search results by compensation: %s\n", searchJobsResponse);
}
// [END compensation_filter]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static void histogramSearch(String companyName) throws IOException, Inter
.execute();
Thread.sleep(1000);

System.out.println(searchJobsResponse);
System.out.printf("Histogram search results: %s\n", searchJobsResponse);
}
// [END histogram_search]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public static void basicLocationSearch(String companyName, String location, doub
SearchJobsResponse response =
talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Basic location search results: %s", response);

}
// [END basic_location_search]

Expand Down Expand Up @@ -110,7 +111,7 @@ public static void keywordLocationSearch(
SearchJobsResponse response =
talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Keyword location search results: %s", response);
}
// [END keyword_location_search]

Expand Down Expand Up @@ -141,7 +142,7 @@ public static void cityLocationSearch(String companyName, String location)
SearchJobsResponse response =
talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("City locations search results: %s", response);
}
// [END city_location_search]

Expand Down Expand Up @@ -177,7 +178,8 @@ public static void multiLocationsSearch(
SearchJobsResponse response =
talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Multiple locations search results: %s", response);

}
// [END multi_locations_search]

Expand Down Expand Up @@ -209,7 +211,7 @@ public static void broadeningLocationsSearch(String companyName, String location
SearchJobsResponse response =
talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
Thread.sleep(1000);
System.out.println(response);
System.out.printf("Broadening locations search results: %s", response);
}
// [END broadening_location_search]

Expand Down
110 changes: 57 additions & 53 deletions jobs/v3/src/test/java/SampleTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,60 +51,65 @@ public static void setUp() {
@Test
public void autoCompleteSampleTest() throws Exception {
AutoCompleteSample.main();
assertThat(bout.toString()).containsMatch(
".*completionResults.*\"suggestion\":\"Google\",\"type\":\"COMPANY_NAME\"}.*\n"
+ ".*completionResults.*\"suggestion\":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n"
+ ".*completionResults.*\"suggestion\":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n"
);
assertThat(bout.toString())
.containsMatch(
".*completionResults.*\"suggestion\":"
+ "\"Google\",\"type\":\"COMPANY_NAME\"}.*\n"
+ ".*completionResults.*\"suggestion\""
+ ":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n"
+ ".*completionResults.*\"suggestion\""
+ ":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n");
bout.reset();
}

@Test
public void basicCompanySampleTest() throws Exception {
BasicCompanySample.main();
assertThat(bout.toString()).containsMatch(
".*Company generated:.*\n"
+ ".*Company created:.*\n"
+ ".*Company existed:.*\n"
+ ".*Company updated:.*elgoog.*\n"
+ ".*Company updated:.*changedTitle.*\n"
+ ".*Company deleted.*\n"
);
assertThat(bout.toString())
.containsMatch(
".*Company generated:.*\n"
+ ".*Company created:.*\n"
+ ".*Company existed:.*\n"
+ ".*Company updated:.*elgoog.*\n"
+ ".*Company updated:.*changedTitle.*\n"
+ ".*Company deleted.*\n");
bout.reset();
}

@Test
public void basicJobSampleTest() throws Exception {
BasicJobSample.main();
assertThat(bout.toString()).containsMatch(
".*Job generated:.*\n"
+ ".*Job created:.*\n"
+ ".*Job existed:.*\n"
+ ".*Job updated:.*changedDescription.*\n"
+ ".*Job updated:.*changedJobTitle.*\n"
+ ".*Job deleted.*\n"
);
assertThat(bout.toString())
.containsMatch(
".*Job generated:.*\n"
+ ".*Job created:.*\n"
+ ".*Job existed:.*\n"
+ ".*Job updated:.*changedDescription.*\n"
+ ".*Job updated:.*changedJobTitle.*\n"
+ ".*Job deleted.*\n");
bout.reset();
}

@Test
public void batchOperationSampleTest() throws Exception {
BatchOperationSample.main();
assertThat(bout.toString()).containsMatch(".*"
+ "Company generated:.*\nCompany created:.*\n"
+ "Create Job:.*\nCreate Job:.*\n"
+ "Update Job:.*Engineer in Mountain View.*\nUpdate Job:.*Engineer in Mountain View.*\n"
+ "Job deleted.*\nJob deleted.*\n"
+ "Company deleted.*\n"
);
assertThat(bout.toString())
.containsMatch(
".*"
+ "Company generated:.*\nCompany created:.*\n"
+ "Create Job:.*\nCreate Job:.*\n"
+ "Update Job:.*Engineer in Mountain View.*\n"
+ "Update Job:.*Engineer in Mountain View.*\n"
+ "Job deleted.*\nJob deleted.*\n"
+ "Company deleted.*\n");
bout.reset();
}

@Test
public void commuteSearchSampleTest() throws Exception {
CommuteSearchSample.main();
String result = bout.toString();
assertThat(result).containsMatch(".*matchingJobs.*1600 Amphitheatre Pkwy.*");
assertThat(result).contains("Search jobs for commute results:");
bout.reset();
}

Expand All @@ -118,47 +123,44 @@ public void customAttributeSampleTest() throws Exception {
Thread.sleep(1000);
}

assertThat(bout.toString())
.containsMatch(
".*Job created:.*jobWithACustomAttribute.*\n"
+ ".*matchingJobs.*jobWithACustomAttribute.*\n");
assertThat(bout.toString()).contains("Job created:");
assertThat(bout.toString()).contains("Custom search job results (String value):");
assertThat(bout.toString()).contains("Custom search job results (Long value):");
assertThat(bout.toString()).contains("Custom search job results (multiple value):");
bout.reset();
}

@Test
public void emailAlertSearchSampleTest() throws Exception {
EmailAlertSearchSample.main();
assertThat(bout.toString()).contains("matchingJobs");
assertThat(bout.toString()).contains("Search jobs for alert results:");
bout.reset();
}

@Test
public void featuredJobSearchSampleTest() throws Exception {
FeaturedJobsSearchSample.main();
assertThat(bout.toString()).contains("matchingJobs");
assertThat(bout.toString()).contains("Featured jobs results:");
bout.reset();
}

@Test
public void generalSearchSampleTest() throws Exception {
GeneralSearchSample.main();
assertThat(bout.toString())
.containsMatch(
".*matchingJobs.*\n"
+ ".*matchingJobs.*\n"
+ ".*matchingJobs.*\n"
+ ".*matchingJobs.*\n"
+ ".*matchingJobs.*\n"
+ ".*matchingJobs.*\n"
+ ".*matchingJobs.*\n");
assertThat(bout.toString()).contains("Simple search jobs results:");
assertThat(bout.toString()).contains("Category search jobs results:");
assertThat(bout.toString()).contains("Employee type search jobs results:");
assertThat(bout.toString()).contains("Search results on jobs with a date range:");
assertThat(bout.toString()).contains("Search results on jobs with a language code:");
assertThat(bout.toString()).contains("Search results by display name of company:");
assertThat(bout.toString()).contains("Search results by compensation:");
bout.reset();
}

@Test
public void histogramSampleTest() throws Exception {
HistogramSample.main();
assertThat(bout.toString()).contains("COMPANY_ID");
assertThat(bout.toString()).contains("someFieldName1");
assertThat(bout.toString()).contains("Histogram search results:");
bout.reset();
}

Expand All @@ -172,13 +174,15 @@ public void jobServiceQuickStartTest() throws Exception {
@Test
public void locationSearchSampleTest() throws Exception {
LocationSearchSample.main();
assertThat(bout.toString()).containsMatch(
".*locationFilters.*matchingJobs.*\n"
+ ".*locationFilters.*matchingJobs.*\n"
+ ".*locationFilters.*matchingJobs.*\n"
+ ".*locationFilters.*matchingJobs.*\n"
+ ".*locationFilters.*matchingJobs.*\n"
);
assertThat(bout.toString()).contains("Basic location search results:");

assertThat(bout.toString()).contains("Keyword location search results:");

assertThat(bout.toString()).contains("City locations search results:");

assertThat(bout.toString()).contains("Multiple locations search results:");

assertThat(bout.toString()).contains("Broadening locations search results:");
bout.reset();
}
}

0 comments on commit c07417c

Please sign in to comment.