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

Commit 828919c

Browse files
FF-107 added User Edit Steps (#29)
* added two step functions and added body to executeRequest * removed umls. * Implemented Steps for Edit User * FF-107 fix tests. Co-authored-by: qvalentin <[email protected]>
1 parent 08619d4 commit 828919c

File tree

8 files changed

+84
-225
lines changed

8 files changed

+84
-225
lines changed
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
package de.filefighter.rest.configuration;
22

3-
import org.jetbrains.annotations.NotNull;
4-
import org.springframework.context.annotation.Bean;
5-
import org.springframework.context.annotation.Configuration;
6-
import org.springframework.web.servlet.config.annotation.CorsRegistry;
7-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
8-
9-
@Configuration
103
public class RestConfiguration {
114

125
//Custom static constants
136
public static final String BASE_API_URI = "/api/v1";
14-
public static final String AUTHORIZATION_BASIC_PREFIX = "Basic: ";
15-
public static final String AUTHORIZATION_BEARER_PREFIX = "Bearer: ";
7+
public static final String AUTHORIZATION_BASIC_PREFIX = "Basic ";
8+
public static final String AUTHORIZATION_BEARER_PREFIX = "Bearer ";
169
public static final String FS_BASE_URI = "/filesystem/";
1710
public static final String FS_PATH_HEADER = "X-FF-PATH";
1811
public static final String USER_BASE_URI = "/users/";
1912

13+
// PreventInstantiation
14+
private RestConfiguration() {
15+
}
2016
}

src/main/java/de/filefighter/rest/domain/user/rest/UserRestController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
@RestController
1717
@Api(value = "User Rest Controller", tags = {"User"})
18+
1819
@RequestMapping(BASE_API_URI)
1920
public class UserRestController {
2021

21-
private final static Logger LOG = LoggerFactory.getLogger(UserRestController.class);
22+
private static final Logger LOG = LoggerFactory.getLogger(UserRestController.class);
2223

2324
private final UserRestServiceInterface userRestService;
2425

src/main/resources/CLASS_DIAGRAM_rest.uml

Lines changed: 0 additions & 178 deletions
This file was deleted.

src/main/resources/DB_SCHEMA_filefighter.uml

Lines changed: 0 additions & 22 deletions
This file was deleted.

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class RestApplicationIntegrationTest {
4747
PermissionRestController permissionRestController;
4848

4949
@Test
50-
public void contextLoads() {
50+
void contextLoads() {
5151
assertThat(healthController).isNotNull();
5252
assertThat(userController).isNotNull();
5353
assertThat(fileSystemRestController).isNotNull();
@@ -59,17 +59,25 @@ public void contextLoads() {
5959
protected void executeRestApiCall(HttpMethod httpMethod, String url) {
6060
final Map<String, String> headers = new HashMap<>();
6161
headers.put("Accept", "application/json");
62-
executeRequest(httpMethod, url, headers);
62+
executeRequest(httpMethod, url, headers,null);
6363
}
6464

6565
protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers) {
66-
executeRequest(httpMethod, url, headers);
66+
executeRequest(httpMethod, url, headers,null);
67+
}
68+
protected void executeRestApiCall(HttpMethod httpMethod, String url, Map<String, String> headers,String postBody) {
69+
executeRequest(httpMethod, url, headers, postBody);
6770
}
6871

69-
private void executeRequest(HttpMethod httpMethod, String url, Map<String, String> headers) {
72+
private void executeRequest(HttpMethod httpMethod, String url, Map<String, String> headers,String postBody) {
7073
final HeaderSettingRequestCallback requestCallback = new HeaderSettingRequestCallback(headers);
74+
if (postBody!=null){
75+
requestCallback.setBody(postBody);
76+
}
7177
final ResponseResultErrorHandler errorHandler = new ResponseResultErrorHandler();
7278

79+
headers.put("Content-Type", "application/json");
80+
7381
restTemplate.setErrorHandler(errorHandler);
7482
latestResponse = restTemplate
7583
.execute("http://localhost:" + port + url, httpMethod, requestCallback, response -> {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package de.filefighter.rest.cucumber;
2+
3+
import de.filefighter.rest.RestApplicationIntegrationTest;
4+
import io.cucumber.java.en.When;
5+
import org.springframework.http.HttpMethod;
6+
7+
import java.util.HashMap;
8+
9+
import static de.filefighter.rest.configuration.RestConfiguration.*;
10+
11+
public class UserEditInformationSteps extends RestApplicationIntegrationTest {
12+
@When("user requests change of username with value {string} and accessToken {string}")
13+
public void userRequestsChangeOfUsernameWithValueAndAccessTokenAndId(String newUsername, String accessToken) {
14+
String authHeaderString = AUTHORIZATION_BEARER_PREFIX + accessToken;
15+
String url = BASE_API_URI + USER_BASE_URI + "edit";
16+
17+
18+
HashMap<String, String> authHeader = new HashMap<>();
19+
authHeader.put("Authorization", authHeaderString);
20+
21+
22+
23+
24+
String postBody="{" +
25+
" \"groupIds\": [" +
26+
" 0" +
27+
" ]," +
28+
" \"username\": \""+newUsername+"\"" +
29+
"}";
30+
31+
executeRestApiCall(HttpMethod.PUT, url, authHeader,postBody);
32+
}
33+
34+
@When("user requests change of password with value {string} and accessToken {string} and id {string}")
35+
public void userRequestsChangeOfPasswordWithValueAndAccessTokenAndId(String newPassword, String accessToken, String userId) {
36+
String authHeaderString = AUTHORIZATION_BEARER_PREFIX + accessToken;
37+
String url = BASE_API_URI + USER_BASE_URI + userId + "/edit";
38+
39+
HashMap<String, String> authHeader = new HashMap<>();
40+
authHeader.put("Authorization", authHeaderString);
41+
42+
43+
String postBody="{\n" +
44+
" \"confirmationPassword\": \""+newPassword+"\"," +
45+
" \"groupIds\": [" +
46+
" 0" +
47+
" ]," +
48+
" \"password\": \""+newPassword+"\"," +
49+
"}";
50+
51+
executeRestApiCall(HttpMethod.GET, url, authHeader,postBody);
52+
}
53+
}

0 commit comments

Comments
 (0)