Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .run/AllJUnitTests.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run All Tests" type="JUnit" factoryName="JUnit">
<module name="RestApi" />
<module name="restapi" />
<useClassPathOnly />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ void contextLoads() {
protected void executeRestApiCall(HttpMethod httpMethod, String url) {
final Map<String, String> headers = new HashMap<>();
headers.put("Accept", "application/json");
executeRequest(httpMethod, url, headers,null);
executeRequest(httpMethod, url, headers, null);
}

protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers) {
executeRequest(httpMethod, url, headers,null);
executeRequest(httpMethod, url, headers, null);
}
protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers,String postBody) {

protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers, String postBody) {
executeRequest(httpMethod, url, headers, postBody);
}

private void executeRequest(HttpMethod httpMethod, String url, Map<String, String> headers,String postBody) {
private void executeRequest(HttpMethod httpMethod, String url, Map<String, String> headers, String postBody) {
final HeaderSettingRequestCallback requestCallback = new HeaderSettingRequestCallback(headers);
if (postBody!=null){
if (postBody != null) {
requestCallback.setBody(postBody);
}
final ResponseResultErrorHandler errorHandler = new ResponseResultErrorHandler();
Expand Down Expand Up @@ -109,29 +110,4 @@ public void handleError(@NotNull ClientHttpResponse response) throws IOException
results = new ResponseResults(response);
}
}

protected static String serializeUser(String confirmationPassword,int[] groupIds, String password, String username){
StringBuilder jsonString=new StringBuilder("{");

if (confirmationPassword != null){
jsonString.append("\"confirmationPassword\": \"").append(confirmationPassword).append("\",");
}
if (groupIds!=null && groupIds.length>0){
jsonString.append("\"groupIds\": ").append(Arrays.toString(groupIds)).append(",");
}
if (password != null){
jsonString.append("\"password\": \"").append(password).append("\",");
}
if (username != null){
jsonString.append("\"username\": \"").append(username).append("\",");
}

jsonString.append("}");

return jsonString.toString();
}




}
27 changes: 27 additions & 0 deletions src/test/java/de/filefighter/rest/TestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.filefighter.rest;

import java.util.Arrays;

public class TestUtils {

public static String serializeUserRequest(String confirmationPassword, int[] groupIds, String password, String username) {
StringBuilder jsonString = new StringBuilder("{");

if (confirmationPassword != null) {
jsonString.append("\"confirmationPassword\": \"").append(confirmationPassword).append("\",");
}
if (groupIds != null && groupIds.length > 0) {
jsonString.append("\"groupIds\": ").append(Arrays.toString(groupIds)).append(",");
}
if (password != null) {
jsonString.append("\"password\": \"").append(password).append(username != null?"\",":"");
}
if (username != null) {
jsonString.append("\"username\": \"").append(username).append("\"");
}

jsonString.append("}");

return jsonString.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package de.filefighter.rest.cucumber;

import de.filefighter.rest.RestApplicationIntegrationTest;
import de.filefighter.rest.TestUtils;
import io.cucumber.java.en.When;
import org.springframework.http.HttpMethod;

import java.util.HashMap;

import static de.filefighter.rest.TestUtils.serializeUserRequest;
import static de.filefighter.rest.configuration.RestConfiguration.*;

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


HashMap<String, String> authHeader = new HashMap<>();
authHeader.put("Authorization", authHeaderString);




String postBody=serializeUser(null,null,null,newUsername);


String postBody= serializeUserRequest(null,null,null,newUsername);
executeRestApiCall(HttpMethod.PUT, url, authHeader,postBody);
}

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


String postBody=serializeUser(newPassword,null,newPassword,null);
String postBody=serializeUserRequest(newPassword,null,newPassword,null);


executeRestApiCall(HttpMethod.GET, url, authHeader,postBody);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.filefighter.rest.cucumber;

import de.filefighter.rest.RestApplicationIntegrationTest;
import de.filefighter.rest.TestUtils;
import io.cucumber.java.en.When;
import org.springframework.http.HttpMethod;

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


HashMap<String, String> authHeader = new HashMap<>();
authHeader.put("Authorization", authHeaderString);




String postBody=serializeUser(password,null,password,username);

String postBody= TestUtils.serializeUserRequest(password,null,password,username);
executeRestApiCall(HttpMethod.POST, url, authHeader,postBody);


}
}