Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 28f8d37

Browse files
authored
FF-158 fixed tests. (#31)
1 parent 5bb2d7a commit 28f8d37

File tree

5 files changed

+40
-47
lines changed

5 files changed

+40
-47
lines changed

.run/AllJUnitTests.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Run All Tests" type="JUnit" factoryName="JUnit">
3-
<module name="RestApi" />
3+
<module name="restapi" />
44
<useClassPathOnly />
55
<option name="PACKAGE_NAME" value="" />
66
<option name="MAIN_CLASS_NAME" value="" />

src/test/java/de/filefighter/rest/RestApplicationIntegrationTest.java

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,20 @@ void contextLoads() {
6060
protected void executeRestApiCall(HttpMethod httpMethod, String url) {
6161
final Map<String, String> headers = new HashMap<>();
6262
headers.put("Accept", "application/json");
63-
executeRequest(httpMethod, url, headers,null);
63+
executeRequest(httpMethod, url, headers, null);
6464
}
6565

6666
protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers) {
67-
executeRequest(httpMethod, url, headers,null);
67+
executeRequest(httpMethod, url, headers, null);
6868
}
69-
protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers,String postBody) {
69+
70+
protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers, String postBody) {
7071
executeRequest(httpMethod, url, headers, postBody);
7172
}
7273

73-
private void executeRequest(HttpMethod httpMethod, String url, Map<String, String> headers,String postBody) {
74+
private void executeRequest(HttpMethod httpMethod, String url, Map<String, String> headers, String postBody) {
7475
final HeaderSettingRequestCallback requestCallback = new HeaderSettingRequestCallback(headers);
75-
if (postBody!=null){
76+
if (postBody != null) {
7677
requestCallback.setBody(postBody);
7778
}
7879
final ResponseResultErrorHandler errorHandler = new ResponseResultErrorHandler();
@@ -109,29 +110,4 @@ public void handleError(@NotNull ClientHttpResponse response) throws IOException
109110
results = new ResponseResults(response);
110111
}
111112
}
112-
113-
protected static String serializeUser(String confirmationPassword,int[] groupIds, String password, String username){
114-
StringBuilder jsonString=new StringBuilder("{");
115-
116-
if (confirmationPassword != null){
117-
jsonString.append("\"confirmationPassword\": \"").append(confirmationPassword).append("\",");
118-
}
119-
if (groupIds!=null && groupIds.length>0){
120-
jsonString.append("\"groupIds\": ").append(Arrays.toString(groupIds)).append(",");
121-
}
122-
if (password != null){
123-
jsonString.append("\"password\": \"").append(password).append("\",");
124-
}
125-
if (username != null){
126-
jsonString.append("\"username\": \"").append(username).append("\",");
127-
}
128-
129-
jsonString.append("}");
130-
131-
return jsonString.toString();
132-
}
133-
134-
135-
136-
137113
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.filefighter.rest;
2+
3+
import java.util.Arrays;
4+
5+
public class TestUtils {
6+
7+
public static String serializeUserRequest(String confirmationPassword, int[] groupIds, String password, String username) {
8+
StringBuilder jsonString = new StringBuilder("{");
9+
10+
if (confirmationPassword != null) {
11+
jsonString.append("\"confirmationPassword\": \"").append(confirmationPassword).append("\",");
12+
}
13+
if (groupIds != null && groupIds.length > 0) {
14+
jsonString.append("\"groupIds\": ").append(Arrays.toString(groupIds)).append(",");
15+
}
16+
if (password != null) {
17+
jsonString.append("\"password\": \"").append(password).append(username != null?"\",":"");
18+
}
19+
if (username != null) {
20+
jsonString.append("\"username\": \"").append(username).append("\"");
21+
}
22+
23+
jsonString.append("}");
24+
25+
return jsonString.toString();
26+
}
27+
}

src/test/java/de/filefighter/rest/cucumber/UserEditInformationSteps.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package de.filefighter.rest.cucumber;
22

33
import de.filefighter.rest.RestApplicationIntegrationTest;
4+
import de.filefighter.rest.TestUtils;
45
import io.cucumber.java.en.When;
56
import org.springframework.http.HttpMethod;
67

78
import java.util.HashMap;
89

10+
import static de.filefighter.rest.TestUtils.serializeUserRequest;
911
import static de.filefighter.rest.configuration.RestConfiguration.*;
1012

1113
public class UserEditInformationSteps extends RestApplicationIntegrationTest {
@@ -14,16 +16,10 @@ public void userRequestsChangeOfUsernameWithValueAndAccessTokenAndId(String newU
1416
String authHeaderString = AUTHORIZATION_BEARER_PREFIX + accessToken;
1517
String url = BASE_API_URI + USER_BASE_URI + "edit";
1618

17-
1819
HashMap<String, String> authHeader = new HashMap<>();
1920
authHeader.put("Authorization", authHeaderString);
2021

21-
22-
23-
24-
String postBody=serializeUser(null,null,null,newUsername);
25-
26-
22+
String postBody= serializeUserRequest(null,null,null,newUsername);
2723
executeRestApiCall(HttpMethod.PUT, url, authHeader,postBody);
2824
}
2925

@@ -36,7 +32,7 @@ public void userRequestsChangeOfPasswordWithValueAndAccessTokenAndId(String newP
3632
authHeader.put("Authorization", authHeaderString);
3733

3834

39-
String postBody=serializeUser(newPassword,null,newPassword,null);
35+
String postBody=serializeUserRequest(newPassword,null,newPassword,null);
4036

4137

4238
executeRestApiCall(HttpMethod.GET, url, authHeader,postBody);
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.filefighter.rest.cucumber;
22

33
import de.filefighter.rest.RestApplicationIntegrationTest;
4+
import de.filefighter.rest.TestUtils;
45
import io.cucumber.java.en.When;
56
import org.springframework.http.HttpMethod;
67

@@ -15,17 +16,10 @@ public void userRequestsRegistrationWithUsernamePasswordAndPasswordConfirmationW
1516
String authHeaderString = AUTHORIZATION_BEARER_PREFIX + accessToken;
1617
String url = BASE_API_URI + USER_BASE_URI + "register";
1718

18-
1919
HashMap<String, String> authHeader = new HashMap<>();
2020
authHeader.put("Authorization", authHeaderString);
2121

22-
23-
24-
25-
String postBody=serializeUser(password,null,password,username);
26-
22+
String postBody= TestUtils.serializeUserRequest(password,null,password,username);
2723
executeRestApiCall(HttpMethod.POST, url, authHeader,postBody);
28-
29-
3024
}
3125
}

0 commit comments

Comments
 (0)