Skip to content
Permalink
Browse files
JENKINS-24433 Improving tests
  • Loading branch information
fbelzunc committed Mar 17, 2015
1 parent 44db6ae commit cb174607b348636eeaf27c6b0eab502ec1f2f3a6
Showing with 13 additions and 18 deletions.
  1. +13 −18 test/src/test/java/hudson/search/SearchTest.java
@@ -32,6 +32,8 @@
import hudson.model.FreeStyleProject;
import hudson.model.ListView;

import java.net.URL;

import java.util.ArrayList;
import java.util.List;

@@ -108,35 +110,32 @@ public void testSearchByProjectName() throws Exception {
@Issue("JENKINS-24433")
@Test
public void testSearchByProjectNameBehindAFolder() throws Exception {
final String projectName = "testSearchByProjectName";
j.createFreeStyleProject(projectName);
j.createFolder("my-folder-1").createProject(FreeStyleProject.class, "my-job-1");
FreeStyleProject myFreeStyleProject = j.createFreeStyleProject("testSearchByProjectName");
MockFolder myMockFolder = j.createFolder("my-folder-1");

Page result = j.createWebClient().goTo("job/my-folder-1/search?q="+ projectName);
Page result = j.createWebClient().goTo(myMockFolder.getUrl() + "search?q="+ myFreeStyleProject.getName());

assertNotNull(result);
j.assertGoodStatus(result);

// make sure we've fetched the testSearchByDisplayName project page
String contents = result.getWebResponse().getContentAsString();
assertTrue(contents.contains(String.format("<title>%s [Jenkins]</title>", projectName)));
URL resultUrl = result.getWebResponse().getUrl();
assertTrue(resultUrl.toString().equals(j.getInstance().getRootUrl() + myFreeStyleProject.getUrl()));
}

@Issue("JENKINS-24433")
@Test
public void testSearchByProjectNameInAFolder() throws Exception {
final String projectName = "testSearchByProjectName";
j.createFreeStyleProject(projectName);
j.createFolder("my-folder-1").createProject(FreeStyleProject.class, "my-job-1");

Page result = j.createWebClient().goTo("job/my-folder-1/search?q="+ "my-folder-1/my-job-1");
MockFolder myMockFolder = j.createFolder("my-folder-1");
FreeStyleProject myFreeStyleProject = myMockFolder.createProject(FreeStyleProject.class, "my-job-1");

Page result = j.createWebClient().goTo(myMockFolder.getUrl() + "search?q=" + myFreeStyleProject.getFullName());

assertNotNull(result);
j.assertGoodStatus(result);

// make sure we've fetched the testSearchByDisplayName project page
String contents = result.getWebResponse().getContentAsString();
assertTrue(contents.contains(String.format("<title>%s [Jenkins]</title>", "my-job-1 [my-folder-1]")));
URL resultUrl = result.getWebResponse().getUrl();
assertTrue(resultUrl.toString().equals(j.getInstance().getRootUrl() + myFreeStyleProject.getUrl()));
}

@Test
@@ -293,15 +292,11 @@ public void testProjectNameBehindAFolderDisplayName() throws Exception {
JSONObject jsonSuggestion = (JSONObject)suggestion;

String name = (String)jsonSuggestion.get("name");
if(projectName1.equals(name)) {
foundProjectName = true;
}
if(displayName1.equals(name)) {
foundDisplayName = true;
}
}

assertTrue(foundProjectName);
assertTrue(foundDisplayName);
}

0 comments on commit cb17460

Please sign in to comment.