newDoc().setTags(newArrayList("finance", "offshore")),
newDoc().setTags(newArrayList("offshore")));
- List<String> result = underTest.searchTags("off", 10);
+ List<String> result = underTest.searchTags("off", 1,10);
assertThat(result).containsOnly("offshore", "official", "Madhoff");
}
newDoc().setTags(newArrayList("finance", "offshore")),
newDoc().setTags(newArrayList("offshore")));
- List<String> result = underTest.searchTags(null, 10);
+ List<String> result = underTest.searchTags(null, 1, 10);
assertThat(result).containsOnly("offshore", "official", "Madhoff", "finance", "marketing", "java", "javascript");
}
newDoc().setTags(newArrayList("finance", "offshore")),
newDoc().setTags(newArrayList("offshore")));
- List<String> result = underTest.searchTags(null, 10);
+ List<String> result = underTest.searchTags(null, 1,10);
assertThat(result).containsExactly("Madhoff", "finance", "java", "javascript", "marketing", "official", "offshore");
}
+ @Test
+ public void search_tags_follows_paging() {
+ index(
+ newDoc().setTags(newArrayList("finance", "offshore", "java")),
+ newDoc().setTags(newArrayList("official", "javascript")),
+ newDoc().setTags(newArrayList("marketing", "official")),
+ newDoc().setTags(newArrayList("marketing", "Madhoff")),
+ newDoc().setTags(newArrayList("finance", "offshore")),
+ newDoc().setTags(newArrayList("offshore")));
+
+ List<String> result = underTest.searchTags(null, 1,3);
+ assertThat(result).containsExactly("Madhoff", "finance", "java");
+
+ result = underTest.searchTags(null, 2,3);
+ assertThat(result).containsExactly("javascript", "marketing", "official");
+
+ result = underTest.searchTags(null, 3,3);
+ assertThat(result).containsExactly("offshore");
+
+ result = underTest.searchTags(null, 3,4);
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ public void search_tags_returns_nothing_if_page_too_large() {
+ index(
+ newDoc().setTags(newArrayList("finance", "offshore", "java")),
+ newDoc().setTags(newArrayList("official", "javascript")),
+ newDoc().setTags(newArrayList("marketing", "official")),
+ newDoc().setTags(newArrayList("marketing", "Madhoff")),
+ newDoc().setTags(newArrayList("finance", "offshore")),
+ newDoc().setTags(newArrayList("offshore")));
+
+ List<String> result = underTest.searchTags(null, 10,2);
+
+ assertThat(result).isEmpty();
+ }
+
@Test
public void search_tags_only_of_authorized_projects() {
indexForUser(USER1,
userSession.logIn(USER1);
- List<String> result = underTest.searchTags(null, 10);
+ List<String> result = underTest.searchTags(null, 1,10);
assertThat(result).containsOnly("finance", "marketing");
}
@Test
public void search_tags_with_no_tags() {
- List<String> result = underTest.searchTags("whatever", 10);
+ List<String> result = underTest.searchTags("whatever", 1,10);
assertThat(result).isEmpty();
}
public void search_tags_with_page_size_at_0() {
index(newDoc().setTags(newArrayList("offshore")));
- List<String> result = underTest.searchTags(null, 0);
+ List<String> result = underTest.searchTags(null, 1,0);
assertThat(result).isEmpty();
}
@Test
public void fail_if_page_size_greater_than_500() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Page size must be lower than or equals to 500");
+ expectedException.expectMessage("Page size must be lower than or equals to 100");
+
+ underTest.searchTags("whatever", 1, 101);
+ }
+
+ @Test
+ public void fail_if_page_greater_than_20() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Page must be between 0 and 20");
- underTest.searchTags("whatever", 501);
+ underTest.searchTags("whatever", 21, 100);
}
private void index(ProjectMeasuresDoc... docs) {
package org.sonar.server.projecttag.ws;
import java.util.List;
+import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.measure.index.ProjectMeasuresIndex;
import org.sonarqube.ws.ProjectTags;
+import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
.setDescription("Search tags")
.setSince("6.4")
.setResponseExample(getClass().getResource("search-example.json"))
+ .setChangelog(new Change("9.2", "Parameter 'page' added"))
.setHandler(this);
action.addSearchQuery("off", "tags");
- action.createPageSize(10, 100);
+ action.addPagingParams(10, 100);
}
@Override
}
private ProjectTags.SearchResponse doHandle(Request request) {
- List<String> tags = index.searchTags(request.param(TEXT_QUERY), request.mandatoryParamAsInt(PAGE_SIZE));
+ List<String> tags = index.searchTags(request.param(TEXT_QUERY), request.mandatoryParamAsInt(PAGE), request.mandatoryParamAsInt(PAGE_SIZE));
return ProjectTags.SearchResponse.newBuilder().addAllTags(tags).build();
}
}