-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add and manage announcements #30
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Florent MILLOT <millotflo@gmail.com>
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/useradmin/server/UserAdminController.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you create AnnouncementController then you can connect AnnoucementController and AnnouncementService directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, cf above
@Test | ||
void testGetAllMaintenanceMessages() throws Exception { | ||
announcementRepository.save(new AnnouncementEntity("I think dangling line is a funny name for a line", Duration.ofSeconds(60))); | ||
assertEquals(1, announcementRepository.findAll().size()); | ||
|
||
// Try to retrieve all the messages and expect everything to be ok | ||
MvcResult mvcResult = mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/announcements") | ||
.header("userId", ADMIN_USER)) | ||
.andExpect(status().isOk()).andReturn(); | ||
List<AnnouncementEntity> announcements = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { | ||
}); | ||
assertEquals(1, announcements.size()); | ||
|
||
// Try to retrieve all the messages with a user that's not an admin and expect 403 FORBIDDEN | ||
mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/announcements") | ||
.header("userId", NOT_ADMIN)) | ||
.andExpect(status().isForbidden()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you separete the tests for OK results and for forbidden ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just updated and completed the test, I prefer to keep them like it was (TL already told me few times to change only the necessary so that's what I do now)
@Test | ||
public void testCancelMaintenanceMessage() throws Exception { | ||
AnnouncementEntity announcement = announcementRepository.save(new AnnouncementEntity("I think dangling line is a funny name for a line", Duration.ofSeconds(60))); | ||
assertEquals(1, announcementRepository.findAll().size()); | ||
|
||
//Send a cancel maintenance message and expect everything to be ok | ||
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/messages/cancel-maintenance") | ||
mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + announcement.getId()) | ||
.header("userId", ADMIN_USER)) | ||
.andExpect(status().isOk()); | ||
assertCancelMaintenanceMessageSent(); | ||
assertEquals(0, announcementRepository.findAll().size()); | ||
|
||
// With a non-existing ID, expect 404 | ||
mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + UUID.randomUUID()) | ||
.header("userId", ADMIN_USER)) | ||
.andExpect(status().isNotFound()); | ||
|
||
//Send a cancel maintenance message with a user that's not an admin and expect 403 FORBIDDEN | ||
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/messages/cancel-maintenance") | ||
mockMvc.perform(delete("/" + UserAdminApi.API_VERSION + "/announcements/" + UUID.randomUUID()) | ||
.header("userId", NOT_ADMIN)) | ||
.andExpect(status().isForbidden()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
src/test/java/org/gridsuite/useradmin/server/UserAdminTest.java
Outdated
Show resolved
Hide resolved
if (announcement.getDuration() == null) { | ||
notificationService.emitMaintenanceMessage(announcement.getMessage()); | ||
} else { | ||
notificationService.emitMaintenanceMessage(announcement.getMessage(), announcement.getDuration().toSeconds()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can be handled in the EmitMessage method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have done that also, but it's not a big deal and does not change that much so I kept the existing code
Signed-off-by: Florent MILLOT <millotflo@gmail.com>
Quality Gate passedIssues Measures |
Signed-off-by: Abdelsalem <abdelsalem.hedhili@rte-france.com>
Quality Gate passedIssues Measures |
No description provided.