Skip to content

Commit c07417c

Browse files
authored
Refactor tests jobs v3 (GoogleCloudPlatform#3503)
Fixes GoogleCloudPlatform#3455 - [X] Please **merge** this PR for me once it is approved.
1 parent 1b091f1 commit c07417c

8 files changed

+79
-73
lines changed

jobs/v3/src/main/java/com/google/samples/CommuteSearchSample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static void commuteSearch(String companyName) throws IOException, Interru
8080
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
8181
.execute();
8282
Thread.sleep(1000);
83-
System.out.println(response);
83+
System.out.printf("Search jobs for commute results: %s\n", response);
8484
}
8585
// [END commute_search]
8686

jobs/v3/src/main/java/com/google/samples/CustomAttributeSample.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static void filtersOnStringValueCustomAttribute()
108108
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
109109
.execute();
110110
Thread.sleep(1000);
111-
System.out.println(response);
111+
System.out.printf("Custom search job results (String value): %s\n", response);
112112
}
113113
// [END custom_attribute_filter_string_value]
114114

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

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

jobs/v3/src/main/java/com/google/samples/EmailAlertSearchSample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static void searchForAlerts(String companyName) throws IOException, Inter
6363
.searchForAlert(DEFAULT_PROJECT_ID, request)
6464
.execute();
6565
Thread.sleep(1000);
66-
System.out.println(response);
66+
System.out.printf("Search jobs for alert results: %s\n", response);
6767
}
6868
// [END search_for_alerts]
6969

jobs/v3/src/main/java/com/google/samples/FeaturedJobsSearchSample.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ public static void searchFeaturedJobs(String companyName)
9999
.jobs()
100100
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
101101
.execute();
102+
102103
Thread.sleep(1000);
103-
System.out.println(response);
104+
System.out.printf("Featured jobs results: %s\n", response);
104105
}
105106
// [END search_featured_job]
106107

jobs/v3/src/main/java/com/google/samples/GeneralSearchSample.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public static void basicSearcJobs(String companyName, String query)
9292
.search(DEFAULT_PROJECT_ID, searchJobsRequest)
9393
.execute();
9494
Thread.sleep(1000);
95-
96-
System.out.println(searchJobsResponse);
95+
System.out.printf("Simple search jobs results: %s\n", searchJobsResponse);
9796
}
9897
// [END basic_keyword_search]
9998

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

134-
System.out.println(searchJobsResponse);
133+
System.out.printf("Category search jobs results: %s\n", searchJobsResponse);
135134
}
136135
// [END category_filter]
137136

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

172-
System.out.println(searchJobsResponse);
171+
System.out.printf("Employee type search jobs results: %s\n", searchJobsResponse);
173172
}
174173
// [END employment_types_filter]
175174

@@ -216,7 +215,7 @@ public static void dateRangeSearch(String companyName, String startTime, String
216215
.execute();
217216
Thread.sleep(1000);
218217

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

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

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

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

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

@@ -344,7 +343,7 @@ public static void compensationSearch(String companyName)
344343
.execute();
345344
Thread.sleep(1000);
346345

347-
System.out.println(searchJobsResponse);
346+
System.out.printf("Search results by compensation: %s\n", searchJobsResponse);
348347
}
349348
// [END compensation_filter]
350349

jobs/v3/src/main/java/com/google/samples/HistogramSample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void histogramSearch(String companyName) throws IOException, Inter
7878
.execute();
7979
Thread.sleep(1000);
8080

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

jobs/v3/src/main/java/com/google/samples/LocationSearchSample.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public static void basicLocationSearch(String companyName, String location, doub
7676
SearchJobsResponse response =
7777
talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
7878
Thread.sleep(1000);
79-
System.out.println(response);
79+
System.out.printf("Basic location search results: %s", response);
80+
8081
}
8182
// [END basic_location_search]
8283

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

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

@@ -177,7 +178,8 @@ public static void multiLocationsSearch(
177178
SearchJobsResponse response =
178179
talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, request).execute();
179180
Thread.sleep(1000);
180-
System.out.println(response);
181+
System.out.printf("Multiple locations search results: %s", response);
182+
181183
}
182184
// [END multi_locations_search]
183185

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

jobs/v3/src/test/java/SampleTests.java

+57-53
Original file line numberDiff line numberDiff line change
@@ -51,60 +51,65 @@ public static void setUp() {
5151
@Test
5252
public void autoCompleteSampleTest() throws Exception {
5353
AutoCompleteSample.main();
54-
assertThat(bout.toString()).containsMatch(
55-
".*completionResults.*\"suggestion\":\"Google\",\"type\":\"COMPANY_NAME\"}.*\n"
56-
+ ".*completionResults.*\"suggestion\":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n"
57-
+ ".*completionResults.*\"suggestion\":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n"
58-
);
54+
assertThat(bout.toString())
55+
.containsMatch(
56+
".*completionResults.*\"suggestion\":"
57+
+ "\"Google\",\"type\":\"COMPANY_NAME\"}.*\n"
58+
+ ".*completionResults.*\"suggestion\""
59+
+ ":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n"
60+
+ ".*completionResults.*\"suggestion\""
61+
+ ":\"Software Engineer\",\"type\":\"JOB_TITLE\".*\n");
5962
bout.reset();
6063
}
6164

6265
@Test
6366
public void basicCompanySampleTest() throws Exception {
6467
BasicCompanySample.main();
65-
assertThat(bout.toString()).containsMatch(
66-
".*Company generated:.*\n"
67-
+ ".*Company created:.*\n"
68-
+ ".*Company existed:.*\n"
69-
+ ".*Company updated:.*elgoog.*\n"
70-
+ ".*Company updated:.*changedTitle.*\n"
71-
+ ".*Company deleted.*\n"
72-
);
68+
assertThat(bout.toString())
69+
.containsMatch(
70+
".*Company generated:.*\n"
71+
+ ".*Company created:.*\n"
72+
+ ".*Company existed:.*\n"
73+
+ ".*Company updated:.*elgoog.*\n"
74+
+ ".*Company updated:.*changedTitle.*\n"
75+
+ ".*Company deleted.*\n");
7376
bout.reset();
7477
}
7578

7679
@Test
7780
public void basicJobSampleTest() throws Exception {
7881
BasicJobSample.main();
79-
assertThat(bout.toString()).containsMatch(
80-
".*Job generated:.*\n"
81-
+ ".*Job created:.*\n"
82-
+ ".*Job existed:.*\n"
83-
+ ".*Job updated:.*changedDescription.*\n"
84-
+ ".*Job updated:.*changedJobTitle.*\n"
85-
+ ".*Job deleted.*\n"
86-
);
82+
assertThat(bout.toString())
83+
.containsMatch(
84+
".*Job generated:.*\n"
85+
+ ".*Job created:.*\n"
86+
+ ".*Job existed:.*\n"
87+
+ ".*Job updated:.*changedDescription.*\n"
88+
+ ".*Job updated:.*changedJobTitle.*\n"
89+
+ ".*Job deleted.*\n");
8790
bout.reset();
8891
}
8992

9093
@Test
9194
public void batchOperationSampleTest() throws Exception {
9295
BatchOperationSample.main();
93-
assertThat(bout.toString()).containsMatch(".*"
94-
+ "Company generated:.*\nCompany created:.*\n"
95-
+ "Create Job:.*\nCreate Job:.*\n"
96-
+ "Update Job:.*Engineer in Mountain View.*\nUpdate Job:.*Engineer in Mountain View.*\n"
97-
+ "Job deleted.*\nJob deleted.*\n"
98-
+ "Company deleted.*\n"
99-
);
96+
assertThat(bout.toString())
97+
.containsMatch(
98+
".*"
99+
+ "Company generated:.*\nCompany created:.*\n"
100+
+ "Create Job:.*\nCreate Job:.*\n"
101+
+ "Update Job:.*Engineer in Mountain View.*\n"
102+
+ "Update Job:.*Engineer in Mountain View.*\n"
103+
+ "Job deleted.*\nJob deleted.*\n"
104+
+ "Company deleted.*\n");
100105
bout.reset();
101106
}
102107

103108
@Test
104109
public void commuteSearchSampleTest() throws Exception {
105110
CommuteSearchSample.main();
106111
String result = bout.toString();
107-
assertThat(result).containsMatch(".*matchingJobs.*1600 Amphitheatre Pkwy.*");
112+
assertThat(result).contains("Search jobs for commute results:");
108113
bout.reset();
109114
}
110115

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

121-
assertThat(bout.toString())
122-
.containsMatch(
123-
".*Job created:.*jobWithACustomAttribute.*\n"
124-
+ ".*matchingJobs.*jobWithACustomAttribute.*\n");
126+
assertThat(bout.toString()).contains("Job created:");
127+
assertThat(bout.toString()).contains("Custom search job results (String value):");
128+
assertThat(bout.toString()).contains("Custom search job results (Long value):");
129+
assertThat(bout.toString()).contains("Custom search job results (multiple value):");
125130
bout.reset();
126131
}
127132

128133
@Test
129134
public void emailAlertSearchSampleTest() throws Exception {
130135
EmailAlertSearchSample.main();
131-
assertThat(bout.toString()).contains("matchingJobs");
136+
assertThat(bout.toString()).contains("Search jobs for alert results:");
132137
bout.reset();
133138
}
134139

135140
@Test
136141
public void featuredJobSearchSampleTest() throws Exception {
137142
FeaturedJobsSearchSample.main();
138-
assertThat(bout.toString()).contains("matchingJobs");
143+
assertThat(bout.toString()).contains("Featured jobs results:");
139144
bout.reset();
140145
}
141146

142147
@Test
143148
public void generalSearchSampleTest() throws Exception {
144149
GeneralSearchSample.main();
145-
assertThat(bout.toString())
146-
.containsMatch(
147-
".*matchingJobs.*\n"
148-
+ ".*matchingJobs.*\n"
149-
+ ".*matchingJobs.*\n"
150-
+ ".*matchingJobs.*\n"
151-
+ ".*matchingJobs.*\n"
152-
+ ".*matchingJobs.*\n"
153-
+ ".*matchingJobs.*\n");
150+
assertThat(bout.toString()).contains("Simple search jobs results:");
151+
assertThat(bout.toString()).contains("Category search jobs results:");
152+
assertThat(bout.toString()).contains("Employee type search jobs results:");
153+
assertThat(bout.toString()).contains("Search results on jobs with a date range:");
154+
assertThat(bout.toString()).contains("Search results on jobs with a language code:");
155+
assertThat(bout.toString()).contains("Search results by display name of company:");
156+
assertThat(bout.toString()).contains("Search results by compensation:");
154157
bout.reset();
155158
}
156159

157160
@Test
158161
public void histogramSampleTest() throws Exception {
159162
HistogramSample.main();
160-
assertThat(bout.toString()).contains("COMPANY_ID");
161-
assertThat(bout.toString()).contains("someFieldName1");
163+
assertThat(bout.toString()).contains("Histogram search results:");
162164
bout.reset();
163165
}
164166

@@ -172,13 +174,15 @@ public void jobServiceQuickStartTest() throws Exception {
172174
@Test
173175
public void locationSearchSampleTest() throws Exception {
174176
LocationSearchSample.main();
175-
assertThat(bout.toString()).containsMatch(
176-
".*locationFilters.*matchingJobs.*\n"
177-
+ ".*locationFilters.*matchingJobs.*\n"
178-
+ ".*locationFilters.*matchingJobs.*\n"
179-
+ ".*locationFilters.*matchingJobs.*\n"
180-
+ ".*locationFilters.*matchingJobs.*\n"
181-
);
177+
assertThat(bout.toString()).contains("Basic location search results:");
178+
179+
assertThat(bout.toString()).contains("Keyword location search results:");
180+
181+
assertThat(bout.toString()).contains("City locations search results:");
182+
183+
assertThat(bout.toString()).contains("Multiple locations search results:");
184+
185+
assertThat(bout.toString()).contains("Broadening locations search results:");
182186
bout.reset();
183187
}
184188
}

0 commit comments

Comments
 (0)