Skip to content

Commit

Permalink
Closes Taskana#2536 - Initialized groups and permissions with Collect…
Browse files Browse the repository at this point in the history
…ions.emptySet() and added test
  • Loading branch information
MM1277 committed Mar 15, 2024
1 parent a6249bd commit 5692ba6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class UserRepresentationModel extends RepresentationModel<UserRepresentat
/** Unique Id. */
@NotNull private String userId;
/** The groups of the User. */
private Set<String> groups;
private Set<String> groups = Collections.emptySet();
/** The permissions of the User. */
private Set<String> permissions;
private Set<String> permissions = Collections.emptySet();
/**
* The domains of the User.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void should_ReturnExceptionCurrentUserWithBadValue() {
HttpEntity<?> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));

ThrowingCallable httpCall =
() -> TEMPLATE.exchange(
() ->
TEMPLATE.exchange(
url,
HttpMethod.GET,
auth,
Expand All @@ -103,7 +104,8 @@ void should_ReturnExceptionCurrentUserWithEmptyValue() {
HttpEntity<?> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));

ThrowingCallable httpCall =
() -> TEMPLATE.exchange(
() ->
TEMPLATE.exchange(
url,
HttpMethod.GET,
auth,
Expand Down Expand Up @@ -180,7 +182,7 @@ void should_ReturnExistingUsers_When_ParameterContainsDuplicateAndInvalidIds() t
}

@Test
void should_CreateValidUser_When_CallingCreateEndpoint() throws Exception {
void should_CreateValidUser_When_CallingCreateEndpointWithAllAttributes() throws Exception {
UserRepresentationModel newUser = new UserRepresentationModel();
newUser.setUserId("12345");
newUser.setGroups(Set.of("group1", "group2"));
Expand All @@ -191,6 +193,13 @@ void should_CreateValidUser_When_CallingCreateEndpoint() throws Exception {
newUser.setLongName("Georg, Hans - (12345)");
newUser.setEmail("hans.georg@web.com");
newUser.setMobilePhone("017325862");
newUser.setPhone("017325862");
newUser.setDomains(Set.of("domain1", "domain2"));
newUser.setData("data");
newUser.setOrgLevel4("orgLevel4");
newUser.setOrgLevel3("orgLevel3");
newUser.setOrgLevel2("orgLevel2");
newUser.setOrgLevel1("orgLevel1");

String url = restHelper.toUrl(RestEndpoints.URL_USERS);
HttpEntity<?> auth = new HttpEntity<>(newUser, RestHelper.generateHeadersForUser("teamlead-1"));
Expand All @@ -207,6 +216,57 @@ void should_CreateValidUser_When_CallingCreateEndpoint() throws Exception {
url = restHelper.toUrl(RestEndpoints.URL_USERS_ID, "12345");
auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));

responseEntity =
TEMPLATE.exchange(
url,
HttpMethod.GET,
auth,
ParameterizedTypeReference.forType(UserRepresentationModel.class));
assertThat(responseEntity.getBody()).isNotNull();
assertThat(responseEntity.getBody().getFirstName().equals("Hans"));
assertThat(responseEntity.getBody().getLastName().equals("Georg"));
assertThat(responseEntity.getBody().getFullName().equals("Georg, Hans"));
assertThat(responseEntity.getBody().getLongName().equals("Georg, Hans - (12345)"));
assertThat(responseEntity.getBody().getEmail().equals("hans.georg@web.com"));
assertThat(responseEntity.getBody().getMobilePhone().equals("017325862"));
assertThat(responseEntity.getBody().getPhone().equals("017325862"));
assertThat(responseEntity.getBody().getData().equals("data"));
assertThat(responseEntity.getBody().getOrgLevel4().equals("orgLevel4"));
assertThat(responseEntity.getBody().getOrgLevel3().equals("orgLevel3"));
assertThat(responseEntity.getBody().getOrgLevel2().equals("orgLevel2"));
assertThat(responseEntity.getBody().getOrgLevel1().equals("orgLevel1"));
assertThat(responseEntity.getBody().getPermissions().equals(Set.of("group1", "group2")));
assertThat(responseEntity.getBody().getGroups().equals(Set.of("perm1", "perm2")));
assertThat(responseEntity.getBody().getDomains().equals(Set.of("domain1", "domain2")));
}

@Test
void should_CreateValidUser_When_CallingCreateEndpointWithoutGroupsPermissionsDomains()
throws Exception {
UserRepresentationModel newUser = new UserRepresentationModel();
newUser.setUserId("123456");
newUser.setFirstName("Hans");
newUser.setLastName("Georg");
newUser.setFullName("Georg, Hans");
newUser.setLongName("Georg, Hans - (12345)");
newUser.setEmail("hans.georg@web.com");
newUser.setMobilePhone("017325862");

String url = restHelper.toUrl(RestEndpoints.URL_USERS);
HttpEntity<?> auth = new HttpEntity<>(newUser, RestHelper.generateHeadersForUser("teamlead-1"));

ResponseEntity<UserRepresentationModel> responseEntity =
TEMPLATE.exchange(
url,
HttpMethod.POST,
auth,
ParameterizedTypeReference.forType(UserRepresentationModel.class));
assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);

url = restHelper.toUrl(RestEndpoints.URL_USERS_ID, "123456");
auth = new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1"));

responseEntity =
TEMPLATE.exchange(
url,
Expand Down

0 comments on commit 5692ba6

Please sign in to comment.