-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(User): Add new endpoints to get/update requesting user profile
- Loading branch information
Showing
7 changed files
with
195 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import static org.springframework.restdocs.payload.PayloadDocumentation.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; | ||
|
@@ -71,6 +72,29 @@ public void before() throws TException { | |
userGroups2.add(UserGroup.SECURITY_ADMIN); | ||
secondaryDepartmentsAndRoles.put("DEPARTMENT1", userGroups1); | ||
secondaryDepartmentsAndRoles.put("DEPARTMENT2", userGroups2); | ||
|
||
Map<String, Boolean> notificationPreferences = new HashMap<>(); | ||
notificationPreferences.put("releaseCONTRIBUTORS", true); | ||
notificationPreferences.put("componentCREATED_BY", true); | ||
notificationPreferences.put("releaseCREATED_BY", true); | ||
notificationPreferences.put("moderationREQUESTING_USER", true); | ||
notificationPreferences.put("projectPROJECT_OWNER", true); | ||
notificationPreferences.put("moderationMODERATORS", true); | ||
notificationPreferences.put("releaseSUBSCRIBERS", true); | ||
notificationPreferences.put("componentMODERATORS", true); | ||
notificationPreferences.put("projectMODERATORS", true); | ||
notificationPreferences.put("projectROLES", true); | ||
notificationPreferences.put("releaseROLES", true); | ||
notificationPreferences.put("componentROLES", true); | ||
notificationPreferences.put("projectLEAD_ARCHITECT", true); | ||
notificationPreferences.put("componentCOMPONENT_OWNER", true); | ||
notificationPreferences.put("projectSECURITY_RESPONSIBLES", true); | ||
notificationPreferences.put("clearingREQUESTING_USER", true); | ||
notificationPreferences.put("projectCONTRIBUTORS", true); | ||
notificationPreferences.put("componentSUBSCRIBERS", true); | ||
notificationPreferences.put("projectPROJECT_RESPONSIBLE", true); | ||
notificationPreferences.put("releaseMODERATORS", true); | ||
|
||
user = new User(); | ||
user.setEmail("[email protected]"); | ||
user.setId("4784587578e87989"); | ||
|
@@ -82,6 +106,7 @@ public void before() throws TException { | |
user.setWantsMailNotification(true); | ||
user.setFormerEmailAddresses(Sets.newHashSet("[email protected]")); | ||
user.setSecondaryDepartmentsAndRoles(secondaryDepartmentsAndRoles); | ||
user.setNotificationPreferences(notificationPreferences); | ||
userList.add(user); | ||
|
||
given(this.userServiceMock.getUserByEmail("[email protected]")).willReturn(user); | ||
|
@@ -90,6 +115,7 @@ public void before() throws TException { | |
when(this.userServiceMock.addUser(any())).then( | ||
invocation -> new User("[email protected]", "DEPARTMENT").setId("1234567890").setFullname("FTest lTest") | ||
.setGivenname("FTest").setLastname("lTest").setUserGroup(UserGroup.USER)); | ||
given(this.userServiceMock.getUserByEmailOrExternalId(any())).willReturn(user); | ||
|
||
User user2 = new User(); | ||
user2.setEmail("[email protected]"); | ||
|
@@ -104,6 +130,8 @@ public void before() throws TException { | |
userList.add(user2); | ||
|
||
given(this.userServiceMock.getAllUsers()).willReturn(userList); | ||
User userWithTokens = new User("[email protected]", "sw360").setId("123456789"); | ||
given(this.userServiceMock.getUserByEmailOrExternalId(any())).willReturn(user); | ||
} | ||
|
||
@Test | ||
|
@@ -176,6 +204,7 @@ public void should_document_create_user() throws Exception { | |
subsectionWithPath("givenName").description("The given name of the user"), | ||
subsectionWithPath("lastName").description("The last name of the user"), | ||
subsectionWithPath("deactivated").description("Is user deactivated"), | ||
fieldWithPath("wantsMailNotification").description("Does user want to be notified via mail?"), | ||
subsectionWithPath("_links").description("<<resources-user-get,User>> to user resource") | ||
))); | ||
} | ||
|
@@ -201,6 +230,8 @@ public void should_document_get_user_by_id() throws Exception { | |
subsectionWithPath("secondaryDepartmentsAndRoles").description("The user's secondary departments and roles"), | ||
fieldWithPath("formerEmailAddresses").description("The user's former email addresses"), | ||
fieldWithPath("deactivated").description("Is user deactivated"), | ||
fieldWithPath("wantsMailNotification").description("Does user want to be notified via mail?"), | ||
subsectionWithPath("notificationPreferences").description("User's notification preferences"), | ||
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
@@ -226,6 +257,89 @@ public void should_document_get_user() throws Exception { | |
subsectionWithPath("secondaryDepartmentsAndRoles").description("The user's secondary departments and roles"), | ||
fieldWithPath("formerEmailAddresses").description("The user's former email addresses"), | ||
fieldWithPath("deactivated").description("Is user deactivated"), | ||
fieldWithPath("wantsMailNotification").description("Does user want to be notified via mail?"), | ||
subsectionWithPath("notificationPreferences").description("User's notification preferences"), | ||
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
||
@Test | ||
public void should_document_get_user_profile() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
mockMvc.perform(get("/api/users/profile") | ||
.header("Authorization", "Bearer " + accessToken) | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status().isOk()) | ||
.andDo(this.documentationHandler.document( | ||
responseFields( | ||
fieldWithPath("email").description("The user's email"), | ||
fieldWithPath("userGroup").description("The user group, possible values are: " + Arrays.asList(UserGroup.values())), | ||
fieldWithPath("fullName").description("The users's full name"), | ||
fieldWithPath("givenName").description("The user's given name"), | ||
fieldWithPath("lastName").description("The user's last name"), | ||
fieldWithPath("department").description("The user's company department"), | ||
subsectionWithPath("secondaryDepartmentsAndRoles").description("The user's secondary departments and roles"), | ||
fieldWithPath("formerEmailAddresses").description("The user's former email addresses"), | ||
fieldWithPath("deactivated").description("Is user deactivated"), | ||
fieldWithPath("wantsMailNotification").description("Does user want to be notified via mail?"), | ||
subsectionWithPath("notificationPreferences").description("User's notification preferences"), | ||
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
||
@Test | ||
public void should_document_update_user_profile() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
|
||
Map<String, Boolean> notificationPreferences = new HashMap<>(); | ||
notificationPreferences.put("releaseCONTRIBUTORS", true); | ||
notificationPreferences.put("componentCREATED_BY", false); | ||
notificationPreferences.put("releaseCREATED_BY", false); | ||
notificationPreferences.put("moderationREQUESTING_USER", false); | ||
notificationPreferences.put("projectPROJECT_OWNER", true); | ||
notificationPreferences.put("moderationMODERATORS", false); | ||
notificationPreferences.put("releaseSUBSCRIBERS", true); | ||
notificationPreferences.put("componentMODERATORS", true); | ||
notificationPreferences.put("projectMODERATORS", false); | ||
notificationPreferences.put("projectROLES", false); | ||
notificationPreferences.put("releaseROLES", true); | ||
notificationPreferences.put("componentROLES", true); | ||
notificationPreferences.put("projectLEAD_ARCHITECT", false); | ||
notificationPreferences.put("componentCOMPONENT_OWNER", true); | ||
notificationPreferences.put("projectSECURITY_RESPONSIBLES", true); | ||
notificationPreferences.put("clearingREQUESTING_USER", true); | ||
notificationPreferences.put("projectCONTRIBUTORS", true); | ||
notificationPreferences.put("componentSUBSCRIBERS", true); | ||
notificationPreferences.put("projectPROJECT_RESPONSIBLE", false); | ||
notificationPreferences.put("releaseMODERATORS", false); | ||
|
||
Map<String, Object> updatedProfile = new HashMap<>(); | ||
updatedProfile.put("wantsMailNotification", true); | ||
updatedProfile.put("notificationPreferences", notificationPreferences); | ||
|
||
mockMvc.perform(patch("/api/users/profile") | ||
.header("Authorization", "Bearer " + accessToken) | ||
.contentType(MediaTypes.HAL_JSON) | ||
.content(this.objectMapper.writeValueAsString(updatedProfile)) | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status().isOk()) | ||
.andDo(this.documentationHandler.document( | ||
requestFields( | ||
fieldWithPath("wantsMailNotification").description("Does user want to be notified via mail?"), | ||
subsectionWithPath("notificationPreferences").description("User's notification preferences") | ||
), | ||
responseFields( | ||
fieldWithPath("email").description("The user's email"), | ||
fieldWithPath("userGroup").description("The user group, possible values are: " + Arrays.asList(UserGroup.values())), | ||
fieldWithPath("fullName").description("The users's full name"), | ||
fieldWithPath("givenName").description("The user's given name"), | ||
fieldWithPath("lastName").description("The user's last name"), | ||
fieldWithPath("department").description("The user's company department"), | ||
fieldWithPath("deactivated").description("Is user deactivated"), | ||
subsectionWithPath("secondaryDepartmentsAndRoles").description("The user's secondary departments and roles"), | ||
fieldWithPath("formerEmailAddresses").description("The user's former email addresses"), | ||
fieldWithPath("wantsMailNotification").description("Does user want to be notified via mail?"), | ||
subsectionWithPath("notificationPreferences").description("User's notification preferences"), | ||
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|