@@ -105,6 +105,40 @@ public void testSearchByProjectName() throws Exception {
105
105
assertTrue (contents .contains (String .format ("<title>%s [Jenkins]</title>" , projectName )));
106
106
}
107
107
108
+ @ Issue ("JENKINS-24433" )
109
+ @ Test
110
+ public void testSearchByProjectNameBehindAFolder () throws Exception {
111
+ final String projectName = "testSearchByProjectName" ;
112
+ j .createFreeStyleProject (projectName );
113
+ j .createFolder ("my-folder-1" ).createProject (FreeStyleProject .class , "my-job-1" );
114
+
115
+ Page result = j .createWebClient ().goTo ("job/my-folder-1/search?q=" + projectName );
116
+
117
+ assertNotNull (result );
118
+ j .assertGoodStatus (result );
119
+
120
+ // make sure we've fetched the testSearchByDisplayName project page
121
+ String contents = result .getWebResponse ().getContentAsString ();
122
+ assertTrue (contents .contains (String .format ("<title>%s [Jenkins]</title>" , projectName )));
123
+ }
124
+
125
+ @ Issue ("JENKINS-24433" )
126
+ @ Test
127
+ public void testSearchByProjectNameInAFolder () throws Exception {
128
+ final String projectName = "testSearchByProjectName" ;
129
+ j .createFreeStyleProject (projectName );
130
+ j .createFolder ("my-folder-1" ).createProject (FreeStyleProject .class , "my-job-1" );
131
+
132
+ Page result = j .createWebClient ().goTo ("job/my-folder-1/search?q=" + "my-folder-1/my-job-1" );
133
+
134
+ assertNotNull (result );
135
+ j .assertGoodStatus (result );
136
+
137
+ // make sure we've fetched the testSearchByDisplayName project page
138
+ String contents = result .getWebResponse ().getContentAsString ();
139
+ assertTrue (contents .contains (String .format ("<title>%s [Jenkins]</title>" , "my-job-1 [my-folder-1]" )));
140
+ }
141
+
108
142
@ Test
109
143
public void testSearchByDisplayName () throws Exception {
110
144
final String displayName = "displayName9999999" ;
@@ -225,6 +259,95 @@ else if(displayName.equals(name)) {
225
259
assertTrue (foundDispayName );
226
260
}
227
261
262
+ @ Issue ("JENKINS-24433" )
263
+ @ Test
264
+ public void testProjectNameBehindAFolderDisplayName () throws Exception {
265
+ final String projectName1 = "job-1" ;
266
+ final String displayName1 = "job-1" ;
267
+
268
+ final String projectName2 = "job-2" ;
269
+ final String displayName2 = "job-2" ;
270
+
271
+ FreeStyleProject project1 = j .createFreeStyleProject (projectName1 );
272
+ project1 .setDisplayName (displayName1 );
273
+
274
+ FreeStyleProject project2 = j .createFolder ("my-folder-1" ).createProject (FreeStyleProject .class , projectName2 );
275
+ project2 .setDisplayName (displayName2 );
276
+
277
+ WebClient wc = j .createWebClient ();
278
+ Page result = wc .goTo ("job/my-folder-1/search/suggest?query=" + projectName1 , "application/json" );
279
+ assertNotNull (result );
280
+ j .assertGoodStatus (result );
281
+
282
+ String content = result .getWebResponse ().getContentAsString ();
283
+ JSONObject jsonContent = (JSONObject )JSONSerializer .toJSON (content );
284
+ assertNotNull (jsonContent );
285
+ JSONArray jsonArray = jsonContent .getJSONArray ("suggestions" );
286
+ assertNotNull (jsonArray );
287
+
288
+ assertEquals (1 , jsonArray .size ());
289
+
290
+ boolean foundProjectName = false ;
291
+ boolean foundDisplayName = false ;
292
+ for (Object suggestion : jsonArray ) {
293
+ JSONObject jsonSuggestion = (JSONObject )suggestion ;
294
+
295
+ String name = (String )jsonSuggestion .get ("name" );
296
+ if (projectName1 .equals (name )) {
297
+ foundProjectName = true ;
298
+ }
299
+ if (displayName1 .equals (name )) {
300
+ foundDisplayName = true ;
301
+ }
302
+ }
303
+
304
+ assertTrue (foundProjectName );
305
+ assertTrue (foundDisplayName );
306
+ }
307
+
308
+ @ Issue ("JENKINS-24433" )
309
+ @ Test
310
+ public void testProjectNameInAFolderDisplayName () throws Exception {
311
+ final String projectName1 = "job-1" ;
312
+ final String displayName1 = "job-1" ;
313
+
314
+ final String projectName2 = "job-2" ;
315
+ final String displayName2 = "my-folder-1 job-2" ;
316
+
317
+ FreeStyleProject project1 = j .createFreeStyleProject (projectName1 );
318
+ project1 .setDisplayName (displayName1 );
319
+
320
+ FreeStyleProject project2 = j .createFolder ("my-folder-1" ).createProject (FreeStyleProject .class , projectName2 );
321
+ project2 .setDisplayName (displayName2 );
322
+
323
+
324
+ WebClient wc = j .createWebClient ();
325
+ Page result = wc .goTo ("job/my-folder-1/search/suggest?query=" + projectName2 , "application/json" );
326
+ assertNotNull (result );
327
+ j .assertGoodStatus (result );
328
+
329
+ String content = result .getWebResponse ().getContentAsString ();
330
+ JSONObject jsonContent = (JSONObject )JSONSerializer .toJSON (content );
331
+ assertNotNull (jsonContent );
332
+ JSONArray jsonArray = jsonContent .getJSONArray ("suggestions" );
333
+ assertNotNull (jsonArray );
334
+
335
+ assertEquals (1 , jsonArray .size ());
336
+
337
+ boolean foundDisplayName = false ;
338
+ for (Object suggestion : jsonArray ) {
339
+ JSONObject jsonSuggestion = (JSONObject )suggestion ;
340
+
341
+ String name = (String )jsonSuggestion .get ("name" );
342
+
343
+ if (displayName2 .equals (name )) {
344
+ foundDisplayName = true ;
345
+ }
346
+ }
347
+
348
+ assertTrue (foundDisplayName );
349
+ }
350
+
228
351
/**
229
352
* Disable/enable status shouldn't affect the search
230
353
*/
0 commit comments