-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[#12048] Migrate tests for GetNotificationActionTest #13210
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
345c092
Add GetNotificationActionTest for migration
InfinityTwo 0463d39
Modify mockLogic to call main method
InfinityTwo 9d3dd27
Fix linting
InfinityTwo fab83ee
Remove the use of typical bundle in test
InfinityTwo a1a0984
Merge branch 'master' into db-migration-c
InfinityTwo 70c9927
Merge branch 'master' into db-migration-c
domoberzin 65a8ed5
Merge branch 'master' into db-migration-c
jasonqiu212 a332191
Merge branch 'master' into db-migration-c
domoberzin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/test/java/teammates/sqlui/webapi/GetNotificationActionTest.java
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package teammates.sqlui.webapi; | ||
|
||
import static org.mockito.Mockito.reset; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.UUID; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.util.Const; | ||
import teammates.storage.sqlentity.Notification; | ||
import teammates.ui.output.NotificationData; | ||
import teammates.ui.webapi.EntityNotFoundException; | ||
import teammates.ui.webapi.GetNotificationAction; | ||
import teammates.ui.webapi.InvalidHttpParameterException; | ||
import teammates.ui.webapi.JsonResult; | ||
|
||
/** | ||
* SUT: {@link GetNotificationAction}. | ||
*/ | ||
public class GetNotificationActionTest extends BaseActionTest<GetNotificationAction> { | ||
|
||
@Override | ||
String getActionUri() { | ||
return Const.ResourceURIs.NOTIFICATION; | ||
} | ||
|
||
@Override | ||
String getRequestMethod() { | ||
return GET; | ||
} | ||
|
||
@BeforeMethod | ||
public void baseClassSetup() { | ||
loginAsAdmin(); | ||
} | ||
|
||
@Test | ||
protected void testExecute_withValidNotificationId_shouldReturnData() { | ||
Notification testNotification = getTypicalNotificationWithId(); | ||
NotificationData expected = new NotificationData(testNotification); | ||
|
||
String[] requestParams = new String[] { | ||
Const.ParamsNames.NOTIFICATION_ID, String.valueOf(testNotification.getId()), | ||
}; | ||
|
||
when(mockLogic.getNotification(testNotification.getId())).thenReturn(testNotification); | ||
|
||
GetNotificationAction action = getAction(requestParams); | ||
JsonResult jsonResult = getJsonResult(action); | ||
|
||
NotificationData output = (NotificationData) jsonResult.getOutput(); | ||
verifyNotificationEquals(expected, output); | ||
|
||
reset(mockLogic); | ||
} | ||
|
||
@Test | ||
protected void testExecute_nonExistentNotification_shouldThrowError() { | ||
GetNotificationAction action = getAction(Const.ParamsNames.NOTIFICATION_ID, UUID.randomUUID().toString()); | ||
EntityNotFoundException enfe = assertThrows(EntityNotFoundException.class, action::execute); | ||
|
||
assertEquals("Notification does not exist.", enfe.getMessage()); | ||
} | ||
|
||
@Test | ||
protected void testExecute_notificationIdIsNull_shouldThrowError() { | ||
GetNotificationAction action = getAction(Const.ParamsNames.NOTIFICATION_ID, null, new String[] {}); | ||
InvalidHttpParameterException ihpe = assertThrows(InvalidHttpParameterException.class, action::execute); | ||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
assertEquals("The [notificationid] HTTP parameter is null.", ihpe.getMessage()); | ||
} | ||
|
||
private void verifyNotificationEquals(NotificationData expected, NotificationData actual) { | ||
assertEquals(expected.getNotificationId(), actual.getNotificationId()); | ||
assertEquals(expected.getStyle(), actual.getStyle()); | ||
assertEquals(expected.getTargetUser(), actual.getTargetUser()); | ||
assertEquals(expected.getTitle(), actual.getTitle()); | ||
assertEquals(expected.getMessage(), actual.getMessage()); | ||
assertEquals(expected.getStartTimestamp(), actual.getStartTimestamp()); | ||
assertEquals(expected.getEndTimestamp(), actual.getEndTimestamp()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Minor style suggestion: Consider adding a blank line between the action and the assertions to improve readability.