This repository has been archived by the owner on Jul 29, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifications): add user notifications
- Loading branch information
1 parent
10b03ba
commit 6dab365
Showing
7 changed files
with
400 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
149 changes: 149 additions & 0 deletions
149
src/test/java/io/gravitee/repository/PortalNotificationConfigRepositoryTest.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,149 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository; | ||
|
||
import io.gravitee.repository.config.AbstractRepositoryTest; | ||
import io.gravitee.repository.management.model.PortalNotificationConfig; | ||
import io.gravitee.repository.management.model.PortalNotificationReferenceType; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class PortalNotificationConfigRepositoryTest extends AbstractRepositoryTest { | ||
|
||
@Override | ||
protected String getTestCasesPath() { | ||
return "/data/portalnotificationConfig-tests/"; | ||
} | ||
|
||
@Test | ||
public void shouldCreate() throws Exception { | ||
final PortalNotificationConfig cfg = new PortalNotificationConfig(); | ||
cfg.setReferenceType(PortalNotificationReferenceType.API); | ||
cfg.setReferenceId("config-created"); | ||
cfg.setUserId("userid"); | ||
cfg.setHooks(Arrays.asList("A", "B", "C")); | ||
cfg.setUpdatedAt(new Date(1439022010883L)); | ||
cfg.setCreatedAt(new Date(1439022010883L)); | ||
|
||
PortalNotificationConfig notificationCreated = portalNotificationConfigRepository.create(cfg); | ||
|
||
assertEquals(cfg.getReferenceType(), notificationCreated.getReferenceType()); | ||
assertEquals(cfg.getReferenceId(), notificationCreated.getReferenceId()); | ||
assertEquals(cfg.getUserId(), notificationCreated.getUserId()); | ||
assertEquals(cfg.getHooks(), notificationCreated.getHooks()); | ||
assertEquals(cfg.getCreatedAt(), notificationCreated.getCreatedAt()); | ||
assertEquals(cfg.getUpdatedAt(), notificationCreated.getUpdatedAt()); | ||
} | ||
|
||
@Test | ||
public void shouldDelete() throws Exception { | ||
assertTrue(portalNotificationConfigRepository.findById("userid", PortalNotificationReferenceType.API, "config-to-delete").isPresent()); | ||
final PortalNotificationConfig cfg = new PortalNotificationConfig(); | ||
cfg.setReferenceType(PortalNotificationReferenceType.API); | ||
cfg.setReferenceId("config-to-delete"); | ||
cfg.setUserId("userid"); | ||
portalNotificationConfigRepository.delete(cfg); | ||
assertFalse(portalNotificationConfigRepository.findById("userid", PortalNotificationReferenceType.API, "config-to-delete").isPresent()); | ||
} | ||
|
||
@Test | ||
public void shouldUpdate() throws Exception { | ||
final PortalNotificationConfig cfg = new PortalNotificationConfig(); | ||
cfg.setReferenceType(PortalNotificationReferenceType.API); | ||
cfg.setReferenceId("config-to-update"); | ||
cfg.setUserId("userid"); | ||
cfg.setHooks(Arrays.asList("D", "B", "C")); | ||
cfg.setUpdatedAt(new Date(1479022010883L)); | ||
cfg.setCreatedAt(new Date(1469022010883L)); | ||
|
||
PortalNotificationConfig notificationUpdated = portalNotificationConfigRepository.update(cfg); | ||
|
||
assertEquals(cfg.getReferenceType(), notificationUpdated.getReferenceType()); | ||
assertEquals(cfg.getReferenceId(), notificationUpdated.getReferenceId()); | ||
assertEquals(cfg.getUserId(), notificationUpdated.getUserId()); | ||
assertEquals(cfg.getHooks(), notificationUpdated.getHooks()); | ||
assertEquals(cfg.getCreatedAt(), notificationUpdated.getCreatedAt()); | ||
assertEquals(cfg.getUpdatedAt(), notificationUpdated.getUpdatedAt()); | ||
} | ||
|
||
@Test | ||
public void shouldFindById() throws Exception { | ||
final PortalNotificationConfig cfg = new PortalNotificationConfig(); | ||
cfg.setReferenceType(PortalNotificationReferenceType.API); | ||
cfg.setReferenceId("config-to-find"); | ||
cfg.setUserId("userid"); | ||
cfg.setHooks(Arrays.asList("A", "B")); | ||
cfg.setUpdatedAt(new Date(1439022010883L)); | ||
cfg.setCreatedAt(new Date(1439022010883L)); | ||
|
||
Optional<PortalNotificationConfig> optNotificationFound = | ||
portalNotificationConfigRepository.findById("userid", PortalNotificationReferenceType.API, "config-to-find"); | ||
|
||
assertTrue(optNotificationFound.isPresent()); | ||
PortalNotificationConfig notificationFound = optNotificationFound.get(); | ||
assertEquals(cfg.getReferenceType(), notificationFound.getReferenceType()); | ||
assertEquals(cfg.getReferenceId(), notificationFound.getReferenceId()); | ||
assertEquals(cfg.getUserId(), notificationFound.getUserId()); | ||
assertEquals(cfg.getHooks(), notificationFound.getHooks()); | ||
assertEquals(cfg.getCreatedAt(), notificationFound.getCreatedAt()); | ||
assertEquals(cfg.getUpdatedAt(), notificationFound.getUpdatedAt()); | ||
} | ||
|
||
@Test | ||
public void shouldNotFoundById() throws Exception { | ||
Optional<PortalNotificationConfig> optNotificationFound; | ||
//userid | ||
optNotificationFound = portalNotificationConfigRepository.findById( | ||
"userid-unknown", | ||
PortalNotificationReferenceType.API, | ||
"config-to-find"); | ||
assertFalse(optNotificationFound.isPresent()); | ||
//type | ||
optNotificationFound = portalNotificationConfigRepository.findById( | ||
"userid", | ||
PortalNotificationReferenceType.APPLICATION, | ||
"config-to-find"); | ||
assertFalse(optNotificationFound.isPresent()); | ||
//ref | ||
optNotificationFound = portalNotificationConfigRepository.findById( | ||
"userid", | ||
PortalNotificationReferenceType.API, | ||
"config-to-not-find"); | ||
assertFalse(optNotificationFound.isPresent()); | ||
} | ||
|
||
@Test | ||
public void shouldFindByHookAndReference() throws Exception { | ||
List<PortalNotificationConfig> configs = portalNotificationConfigRepository.findByReferenceAndHook( | ||
"B", | ||
PortalNotificationReferenceType.APPLICATION, | ||
"search"); | ||
|
||
assertEquals("size", 2, configs.size()); | ||
List<String> userIds = configs.stream().map(PortalNotificationConfig::getUserId).collect(Collectors.toList()); | ||
assertTrue("userA", userIds.contains("userA")); | ||
assertTrue("userB", userIds.contains("userB")); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/test/java/io/gravitee/repository/PortalNotificationRepositoryTest.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,78 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository; | ||
|
||
import io.gravitee.repository.config.AbstractRepositoryTest; | ||
import io.gravitee.repository.management.model.PortalNotification; | ||
import org.junit.Test; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class PortalNotificationRepositoryTest extends AbstractRepositoryTest { | ||
|
||
@Override | ||
protected String getTestCasesPath() { | ||
return "/data/portalnotification-tests/"; | ||
} | ||
|
||
@Test | ||
public void shouldCreate() throws Exception { | ||
final PortalNotification notification = new PortalNotification(); | ||
notification.setId("notif-create"); | ||
notification.setTitle("notif-title"); | ||
notification.setMessage("notif-message"); | ||
notification.setUserId("notif-userId"); | ||
notification.setCreatedAt(new Date(1439022010883L)); | ||
|
||
PortalNotification notificationCreated = portalNotificationRepository.create(notification); | ||
|
||
assertEquals(notification.getId(), notificationCreated.getId()); | ||
assertEquals(notification.getTitle(), notificationCreated.getTitle()); | ||
assertEquals(notification.getMessage(), notificationCreated.getMessage()); | ||
assertEquals(notification.getUserId(), notificationCreated.getUserId()); | ||
assertEquals(notification.getCreatedAt(), notificationCreated.getCreatedAt()); | ||
} | ||
|
||
@Test | ||
public void shouldDelete() throws Exception { | ||
assertEquals(1, portalNotificationRepository.findByUserId("notif-userId-toDelete").size()); | ||
portalNotificationRepository.delete("notif-toDelete"); | ||
assertTrue(portalNotificationRepository.findByUserId("notif-userId-toDelete").isEmpty()); | ||
} | ||
|
||
@Test | ||
public void shouldFindByUserId() throws Exception { | ||
List<PortalNotification> notifications = portalNotificationRepository.findByUserId("notif-userId-findByUserId"); | ||
|
||
assertEquals(1, notifications.size()); | ||
PortalNotification notification = notifications.get(0); | ||
assertEquals("notif-findByUserId", notification.getId()); | ||
assertEquals("notif-title-findByUserId", notification.getTitle()); | ||
assertEquals("notif-message-findByUserId", notification.getMessage()); | ||
assertEquals("notif-userId-findByUserId", notification.getUserId()); | ||
assertEquals(new Date(1439022010883L), notification.getCreatedAt()); | ||
} | ||
|
||
@Test | ||
public void shouldNotFindByUsername() throws Exception { | ||
List<PortalNotification> notifications = portalNotificationRepository.findByUserId("unknown"); | ||
|
||
assertTrue(notifications.isEmpty()); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/test/resources/data/portalnotification-tests/portalNotifications.json
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,23 @@ | ||
[ | ||
{ | ||
"id": "notif-toUpdate", | ||
"title": "notif-title-toUpdate", | ||
"message": "notif-message-toUpdate", | ||
"userId": "notif-userId-toUpdate", | ||
"createdAt": 1439022010883 | ||
}, | ||
{ | ||
"id": "notif-toDelete", | ||
"title": "notif-title-toDelete", | ||
"message": "notif-message-toDelete", | ||
"userId": "notif-userId-toDelete", | ||
"createdAt": 1439022010883 | ||
}, | ||
{ | ||
"id": "notif-findByUserId", | ||
"title": "notif-title-findByUserId", | ||
"message": "notif-message-findByUserId", | ||
"userId": "notif-userId-findByUserId", | ||
"createdAt": 1439022010883 | ||
} | ||
] |
Oops, something went wrong.