Skip to content

Commit b2f22cb

Browse files
committed
Initial commit (#425).
1 parent d1af461 commit b2f22cb

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
package org.gitlab4j.api;
2+
3+
import static org.junit.Assert.assertNotNull;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import java.util.List;
7+
8+
import org.gitlab4j.api.Constants.GroupSearchScope;
9+
import org.gitlab4j.api.Constants.ProjectSearchScope;
10+
import org.gitlab4j.api.Constants.SearchScope;
11+
import org.gitlab4j.api.models.Group;
12+
import org.gitlab4j.api.models.Issue;
13+
import org.gitlab4j.api.models.MergeRequest;
14+
import org.gitlab4j.api.models.Milestone;
15+
import org.gitlab4j.api.models.Note;
16+
import org.gitlab4j.api.models.Project;
17+
import org.gitlab4j.api.models.SearchBlob;
18+
import org.gitlab4j.api.models.Snippet;
19+
import org.gitlab4j.api.models.User;
20+
import org.junit.BeforeClass;
21+
import org.junit.Test;
22+
import org.junit.experimental.categories.Category;
23+
24+
@Category(IntegrationTest.class)
25+
public class TestSearchApi extends AbstractIntegrationTest {
26+
27+
private static final String TEST_GROUP = HelperUtils.getProperty(GROUP_KEY);
28+
29+
private static GitLabApi gitLabApi;
30+
private static Project testProject;
31+
private static Group testGroup;
32+
33+
public TestSearchApi() {
34+
super();
35+
}
36+
37+
@BeforeClass
38+
public static void testSetup() {
39+
40+
// Must setup the connection to the GitLab test server and get the test Project
41+
// instance
42+
gitLabApi = baseTestSetup();
43+
testProject = getTestProject();
44+
45+
if (gitLabApi != null) {
46+
try {
47+
List<Group> groups = gitLabApi.getGroupApi().getGroups(TEST_GROUP);
48+
testGroup = groups.get(0);
49+
} catch (GitLabApiException gle) {
50+
System.err.println("Problem fetching test group, error=" + gle.getMessage());
51+
}
52+
}
53+
}
54+
55+
@Test
56+
public void testGlobalProjectSearch() throws GitLabApiException {
57+
List<?> results = (List<?>) gitLabApi.getSearchApi().globalSearch(SearchScope.PROJECTS, TEST_PROJECT_NAME);
58+
assertNotNull(results);
59+
assertTrue(results.get(0).getClass() == Project.class);
60+
}
61+
62+
@Test
63+
public void testGlobalIssuesSearch() throws GitLabApiException {
64+
List<?> results = (List<?>) gitLabApi.getSearchApi().globalSearch(SearchScope.ISSUES, TEST_PROJECT_NAME);
65+
assertNotNull(results);
66+
if (results.size() > 0) {
67+
assertTrue(results.get(0).getClass() == Issue.class);
68+
}
69+
}
70+
71+
@Test
72+
public void testGlobalMergeRequestsSearch() throws GitLabApiException {
73+
List<?> results = (List<?>) gitLabApi.getSearchApi().globalSearch(SearchScope.MERGE_REQUESTS, TEST_PROJECT_NAME);
74+
assertNotNull(results);
75+
if (results.size() > 0) {
76+
assertTrue(results.get(0).getClass() == MergeRequest.class);
77+
}
78+
}
79+
80+
@Test
81+
public void testGlobalMilestonesSearch() throws GitLabApiException {
82+
List<?> results = (List<?>) gitLabApi.getSearchApi().globalSearch(SearchScope.MILESTONES, TEST_PROJECT_NAME);
83+
assertNotNull(results);
84+
if (results.size() > 0) {
85+
assertTrue(results.get(0).getClass() == Milestone.class);
86+
}
87+
}
88+
89+
@Test
90+
public void testGlobalSnippetTitlesSearch() throws GitLabApiException {
91+
List<?> results = (List<?>) gitLabApi.getSearchApi().globalSearch(SearchScope.SNIPPET_TITLES, TEST_PROJECT_NAME);
92+
assertNotNull(results);
93+
if (results.size() > 0) {
94+
assertTrue(results.get(0).getClass() == Snippet.class);
95+
}
96+
}
97+
98+
@Test
99+
public void testGlobalSnippetBlobsSearch() throws GitLabApiException {
100+
List<?> results = (List<?>) gitLabApi.getSearchApi().globalSearch(SearchScope.SNIPPET_BLOBS, TEST_PROJECT_NAME);
101+
assertNotNull(results);
102+
if (results.size() > 0) {
103+
assertTrue(results.get(0).getClass() == Snippet.class);
104+
}
105+
}
106+
107+
@Test
108+
public void testGlobalUsersSearch() throws GitLabApiException {
109+
List<?> results = (List<?>) gitLabApi.getSearchApi().globalSearch(SearchScope.USERS, TEST_LOGIN_USERNAME);
110+
assertNotNull(results);
111+
assertTrue(results.get(0).getClass() == User.class);
112+
}
113+
114+
@Test
115+
public void testGroupProjectSearch() throws GitLabApiException {
116+
List<?> results = (List<?>) gitLabApi.getSearchApi().groupSearch(testGroup, GroupSearchScope.PROJECTS, TEST_GROUP_PROJECT_NAME);
117+
assertNotNull(results);
118+
assertTrue(results.get(0).getClass() == Project.class);
119+
}
120+
121+
@Test
122+
public void testGroupIssuesSearch() throws GitLabApiException {
123+
List<?> results = (List<?>) gitLabApi.getSearchApi().groupSearch(testGroup, GroupSearchScope.ISSUES, TEST_GROUP_PROJECT_NAME);
124+
assertNotNull(results);
125+
if (results.size() > 0) {
126+
assertTrue(results.get(0).getClass() == Issue.class);
127+
}
128+
}
129+
130+
@Test
131+
public void testGrouplMergeRequestsSearch() throws GitLabApiException {
132+
List<?> results = (List<?>) gitLabApi.getSearchApi().groupSearch(testGroup, GroupSearchScope.MERGE_REQUESTS, TEST_GROUP_PROJECT_NAME);
133+
assertNotNull(results);
134+
if (results.size() > 0) {
135+
assertTrue(results.get(0).getClass() == MergeRequest.class);
136+
}
137+
}
138+
139+
@Test
140+
public void testGroupMilestonesSearch() throws GitLabApiException {
141+
List<?> results = (List<?>) gitLabApi.getSearchApi().groupSearch(testGroup, GroupSearchScope.MILESTONES, TEST_GROUP_PROJECT_NAME);
142+
assertNotNull(results);
143+
if (results.size() > 0) {
144+
assertTrue(results.get(0).getClass() == Milestone.class);
145+
}
146+
}
147+
148+
@Test
149+
public void testGrouplUsersSearch() throws GitLabApiException {
150+
List<?> results = (List<?>) gitLabApi.getSearchApi().groupSearch(testGroup, GroupSearchScope.USERS, TEST_LOGIN_USERNAME);
151+
assertNotNull(results);
152+
assertTrue(results.get(0).getClass() == User.class);
153+
}
154+
155+
@Test
156+
public void testProjectIssuesSearch() throws GitLabApiException {
157+
List<?> results = (List<?>) gitLabApi.getSearchApi().projectSearch(
158+
testProject, ProjectSearchScope.ISSUES, TEST_PROJECT_NAME);
159+
assertNotNull(results);
160+
if (results.size() > 0) {
161+
assertTrue(results.get(0).getClass() == Issue.class);
162+
}
163+
}
164+
165+
@Test
166+
public void testProjectlMergeRequestsSearch() throws GitLabApiException {
167+
List<?> results = (List<?>) gitLabApi.getSearchApi().projectSearch(
168+
testProject, ProjectSearchScope.MERGE_REQUESTS, TEST_PROJECT_NAME);
169+
assertNotNull(results);
170+
if (results.size() > 0) {
171+
assertTrue(results.get(0).getClass() == MergeRequest.class);
172+
}
173+
}
174+
175+
@Test
176+
public void testProjectMilestonesSearch() throws GitLabApiException {
177+
List<?> results = (List<?>) gitLabApi.getSearchApi().projectSearch(
178+
testProject, ProjectSearchScope.MILESTONES, TEST_PROJECT_NAME);
179+
assertNotNull(results);
180+
if (results.size() > 0) {
181+
assertTrue(results.get(0).getClass() == Milestone.class);
182+
}
183+
}
184+
185+
@Test
186+
public void testProjectNotesSearch() throws GitLabApiException {
187+
List<?> results = (List<?>) gitLabApi.getSearchApi().projectSearch(
188+
testProject, ProjectSearchScope.NOTES, TEST_PROJECT_NAME);
189+
assertNotNull(results);
190+
if (results.size() > 0) {
191+
assertTrue(results.get(0).getClass() == Note.class);
192+
}
193+
}
194+
195+
@Test
196+
public void testProjectWikiBlobsSearch() throws GitLabApiException {
197+
List<?> results = (List<?>) gitLabApi.getSearchApi().projectSearch(
198+
testProject, ProjectSearchScope.WIKI_BLOBS, TEST_PROJECT_NAME);
199+
assertNotNull(results);
200+
if (results.size() > 0) {
201+
assertTrue(results.get(0).getClass() == SearchBlob.class);
202+
}
203+
}
204+
205+
@Test
206+
public void testProjectlUsersSearch() throws GitLabApiException {
207+
List<?> results = (List<?>) gitLabApi.getSearchApi().projectSearch(
208+
testProject, ProjectSearchScope.USERS, TEST_LOGIN_USERNAME);
209+
assertNotNull(results);
210+
assertTrue(results.get(0).getClass() == User.class);
211+
}
212+
}

0 commit comments

Comments
 (0)