forked from TEAMMATES/teammates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEAMMATES#12048] Create SQL logic for CreateNotificationAction and a…
…dd relevant tests for v9 migration (TEAMMATES#12077)
- Loading branch information
Showing
10 changed files
with
250 additions
and
14 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/it/java/teammates/it/storage/sqlapi/NotificationDbIT.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,41 @@ | ||
package teammates.it.storage.sqlapi; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.NotificationStyle; | ||
import teammates.common.datatransfer.NotificationTargetUser; | ||
import teammates.common.exception.EntityAlreadyExistsException; | ||
import teammates.common.exception.InvalidParametersException; | ||
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess; | ||
import teammates.storage.sqlapi.NotificationsDb; | ||
import teammates.storage.sqlentity.Notification; | ||
|
||
/** | ||
* SUT: {@link NotificationsDb}. | ||
*/ | ||
public class NotificationDbIT extends BaseTestCaseWithSqlDatabaseAccess { | ||
|
||
private final NotificationsDb notificationsDb = NotificationsDb.inst(); | ||
|
||
@Test | ||
public void testCreateNotification() throws EntityAlreadyExistsException, InvalidParametersException { | ||
______TS("success: create notification that does not exist"); | ||
Notification newNotification = new Notification.NotificationBuilder() | ||
.withStartTime(Instant.parse("2011-01-01T00:00:00Z")) | ||
.withEndTime(Instant.parse("2099-01-01T00:00:00Z")) | ||
.withStyle(NotificationStyle.DANGER) | ||
.withTargetUser(NotificationTargetUser.GENERAL) | ||
.withTitle("A deprecation note") | ||
.withMessage("<p>Deprecation happens in three minutes</p>") | ||
.build(); | ||
|
||
notificationsDb.createNotification(newNotification); | ||
|
||
UUID notificationId = newNotification.getNotificationId(); | ||
Notification actualNotification = notificationsDb.getNotification(notificationId); | ||
verifyEquals(newNotification, actualNotification); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/teammates/sqllogic/core/NotificationsLogic.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,40 @@ | ||
package teammates.sqllogic.core; | ||
|
||
import teammates.common.exception.EntityAlreadyExistsException; | ||
import teammates.common.exception.InvalidParametersException; | ||
import teammates.storage.sqlapi.NotificationsDb; | ||
import teammates.storage.sqlentity.Notification; | ||
|
||
/** | ||
* Handles the logic related to notifications. | ||
*/ | ||
public final class NotificationsLogic { | ||
|
||
private static final NotificationsLogic instance = new NotificationsLogic(); | ||
|
||
private NotificationsDb notificationsDb; | ||
|
||
private NotificationsLogic() { | ||
// prevent initialization | ||
} | ||
|
||
public static NotificationsLogic inst() { | ||
return instance; | ||
} | ||
|
||
void initLogicDependencies(NotificationsDb notificationsDb) { | ||
this.notificationsDb = notificationsDb; | ||
} | ||
|
||
/** | ||
* Creates a notification. | ||
* | ||
* @return the created notification | ||
* @throws InvalidParametersException if the notification is not valid | ||
* @throws EntityAlreadyExistsException if the notification already exists in the database. | ||
*/ | ||
public Notification createNotification(Notification notification) | ||
throws InvalidParametersException, EntityAlreadyExistsException { | ||
return notificationsDb.createNotification(notification); | ||
} | ||
} |
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
Oops, something went wrong.