5
5
import static org .junit .jupiter .api .Assertions .assertNotNull ;
6
6
import static org .junit .jupiter .api .Assertions .assertTrue ;
7
7
import static org .junit .jupiter .api .Assertions .fail ;
8
- import static org .junit .jupiter .api .Assumptions .assumeTrue ;
9
8
10
9
import java .util .List ;
11
10
import java .util .Map ;
14
13
15
14
import org .gitlab4j .api .models .Project ;
16
15
import org .gitlab4j .api .models .Visibility ;
17
- import org .junit .jupiter .api .AfterAll ;
18
- import org .junit .jupiter .api .BeforeAll ;
19
- import org .junit .jupiter .api .BeforeEach ;
20
- import org .junit .jupiter .api .Tag ;
21
16
import org .junit .jupiter .api .Test ;
22
- import org .junit .jupiter .api .extension .ExtendWith ;
23
-
24
- /**
25
- * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties
26
- *
27
- * TEST_NAMESPACE
28
- * TEST_HOST_URL
29
- * TEST_PRIVATE_TOKEN
30
- *
31
- * If any of the above are NULL, all tests in this class will be skipped.
32
- */
33
- @ Tag ("integration" )
34
- @ ExtendWith (SetupIntegrationTestExtension .class )
35
- @ org .junit .jupiter .api .Disabled (
36
- "Integration tests are disabled, see https://github.com/gitlab4j/gitlab4j-api/issues/1165" )
37
- public class TestGitLabApiException extends AbstractIntegrationTest {
17
+
18
+ public class TestGitLabApiException {
38
19
39
20
private static final String TEST_PROJECT_NAME_DUPLICATE = "test-gitlab4j-create-project-duplicate" ;
40
21
private static final String TEST_ERROR_MESSAGE =
@@ -45,39 +26,42 @@ public class TestGitLabApiException extends AbstractIntegrationTest {
45
26
46
27
private static GitLabApi gitLabApi ;
47
28
48
- public TestGitLabApiException () {
49
- super ();
50
- }
51
-
52
- @ BeforeAll
53
- public static void setup () {
54
- // Must setup the connection to the GitLab test server
55
- gitLabApi = baseTestSetup ();
56
-
57
- deleteAllTestProjects ();
58
- }
59
-
60
- @ AfterAll
61
- public static void teardown () throws GitLabApiException {
62
- deleteAllTestProjects ();
63
- }
64
-
65
- private static void deleteAllTestProjects () {
66
- if (gitLabApi != null ) {
67
- try {
68
- Project project = gitLabApi .getProjectApi ().getProject (TEST_NAMESPACE , TEST_PROJECT_NAME_DUPLICATE );
69
- gitLabApi .getProjectApi ().deleteProject (project );
70
- } catch (GitLabApiException ignore ) {
71
- }
72
- }
73
- }
74
-
75
- @ BeforeEach
76
- public void beforeMethod () {
77
- assumeTrue (gitLabApi != null );
78
- }
29
+ // public TestGitLabApiException() {
30
+ // super();
31
+ // }
32
+ //
33
+ // @BeforeAll
34
+ // public static void setup() {
35
+ // // Must setup the connection to the GitLab test server
36
+ // gitLabApi = baseTestSetup();
37
+ //
38
+ // deleteAllTestProjects();
39
+ // }
40
+ //
41
+ // @AfterAll
42
+ // public static void teardown() throws GitLabApiException {
43
+ // deleteAllTestProjects();
44
+ // }
45
+ //
46
+ // private static void deleteAllTestProjects() {
47
+ // if (gitLabApi != null) {
48
+ // try {
49
+ // Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE,
50
+ // TEST_PROJECT_NAME_DUPLICATE);
51
+ // gitLabApi.getProjectApi().deleteProject(project);
52
+ // } catch (GitLabApiException ignore) {
53
+ // }
54
+ // }
55
+ // }
56
+ //
57
+ // @BeforeEach
58
+ // public void beforeMethod() {
59
+ // assumeTrue(gitLabApi != null);
60
+ // }
79
61
80
62
@ Test
63
+ @ org .junit .jupiter .api .Disabled (
64
+ "Integration tests are disabled, see https://github.com/gitlab4j/gitlab4j-api/issues/1165" )
81
65
public void testNotFoundError () throws GitLabApiException {
82
66
83
67
try {
@@ -96,6 +80,8 @@ public void testNotFoundError() throws GitLabApiException {
96
80
}
97
81
98
82
@ Test
83
+ @ org .junit .jupiter .api .Disabled (
84
+ "Integration tests are disabled, see https://github.com/gitlab4j/gitlab4j-api/issues/1165" )
99
85
public void testValidationErrors () throws GitLabApiException {
100
86
101
87
Project project = new Project ()
@@ -125,6 +111,68 @@ public void testStringMessage() throws GitLabApiException {
125
111
assertEquals (TEST_ERROR_MESSAGE , glae .getMessage ());
126
112
}
127
113
114
+ @ Test
115
+ public void testObjectMessage () throws GitLabApiException {
116
+ String expectedMessage = ""
117
+ + "The following fields have validation errors: project_namespace.name, name\n "
118
+ + "* project_namespace.name\n "
119
+ + " - has already been taken\n "
120
+ + "* name\n "
121
+ + " - has already been taken" ;
122
+ final MockResponse response = new MockResponse (
123
+ Status .BAD_REQUEST ,
124
+ "{\" message\" :{\" project_namespace.name\" :[\" has already been taken\" ],\" name\" :[\" has already been taken\" ]}}" );
125
+ GitLabApiException glae = new GitLabApiException (response );
126
+ assertEquals (Status .BAD_REQUEST .getStatusCode (), glae .getHttpStatus ());
127
+ assertEquals (expectedMessage , glae .getMessage ());
128
+ assertEquals (2 , glae .getValidationErrors ().size ());
129
+ assertEquals (1 , glae .getValidationErrors ().get ("project_namespace.name" ).size ());
130
+ assertEquals (
131
+ "has already been taken" ,
132
+ glae .getValidationErrors ().get ("project_namespace.name" ).get (0 ));
133
+ assertEquals (1 , glae .getValidationErrors ().get ("name" ).size ());
134
+ assertEquals (
135
+ "has already been taken" , glae .getValidationErrors ().get ("name" ).get (0 ));
136
+ }
137
+
138
+ @ Test
139
+ public void testObjectMessage1 () throws GitLabApiException {
140
+ String message = "{\n "
141
+ + " \" message\" :{\n "
142
+ + " \" f1\" :[\n "
143
+ + " \" m1\" ,\n "
144
+ + " \" m2\" \n "
145
+ + " ],\n "
146
+ + " \" f2\" :[\n "
147
+ + " \" n1\" ,\n "
148
+ + " \" n2\" ,\n "
149
+ + " \" n3\" \n "
150
+ + " ]\n "
151
+ + " }\n "
152
+ + "}" ;
153
+ String expectedMessage = ""
154
+ + "The following fields have validation errors: f1, f2\n "
155
+ + "* f1\n "
156
+ + " - m1\n "
157
+ + " - m2\n "
158
+ + "* f2\n "
159
+ + " - n1\n "
160
+ + " - n2\n "
161
+ + " - n3" ;
162
+ final MockResponse response = new MockResponse (Status .BAD_REQUEST , message );
163
+ GitLabApiException glae = new GitLabApiException (response );
164
+ assertEquals (Status .BAD_REQUEST .getStatusCode (), glae .getHttpStatus ());
165
+ assertEquals (expectedMessage , glae .getMessage ());
166
+ assertEquals (2 , glae .getValidationErrors ().size ());
167
+ assertEquals (2 , glae .getValidationErrors ().get ("f1" ).size ());
168
+ assertEquals ("m1" , glae .getValidationErrors ().get ("f1" ).get (0 ));
169
+ assertEquals ("m2" , glae .getValidationErrors ().get ("f1" ).get (1 ));
170
+ assertEquals (3 , glae .getValidationErrors ().get ("f2" ).size ());
171
+ assertEquals ("n1" , glae .getValidationErrors ().get ("f2" ).get (0 ));
172
+ assertEquals ("n2" , glae .getValidationErrors ().get ("f2" ).get (1 ));
173
+ assertEquals ("n3" , glae .getValidationErrors ().get ("f2" ).get (2 ));
174
+ }
175
+
128
176
@ Test
129
177
public void testArrayMessage () throws GitLabApiException {
130
178
final MockResponse response = new MockResponse (Status .BAD_REQUEST , TEST_RESPONSE_JSON_ARRAY );
0 commit comments