use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class NotificationManagerTest method testAmendEmail.
@Test
public void testAmendEmail() throws JAXBException, IOException, URISyntaxException {
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
String testOrcid = "0000-0000-0000-0003";
for (Locale locale : Locale.values()) {
NotificationEntity previousNotification = notificationDao.findLatestByOrcid(testOrcid);
long minNotificationId = previousNotification != null ? previousNotification.getId() : -1;
profileEntityManager.updateLocale(testOrcid, locale);
notificationManager.sendAmendEmail(testOrcid, AmendedSection.UNKNOWN, Collections.emptyList());
// New notification entity should have been created
NotificationEntity latestNotification = notificationDao.findLatestByOrcid(testOrcid);
assertNotNull(latestNotification);
assertTrue(latestNotification.getId() > minNotificationId);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.AMENDED, latestNotification.getNotificationType());
}
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class NotificationManagerTest method testFindPermissionsByOrcidAndClient.
/**
* Test independent of spring context, sets up NotificationManager with
* mocked notifiation dao and notification adapter
*/
@Test
public void testFindPermissionsByOrcidAndClient() {
List<Notification> notificationPermissions = IntStream.range(0, 10).mapToObj(i -> new NotificationPermission()).collect(Collectors.toList());
NotificationDao notificationDao = mock(NotificationDaoImpl.class);
JpaJaxbNotificationAdapter adapter = mock(JpaJaxbNotificationAdapterImpl.class);
when(notificationDao.findPermissionsByOrcidAndClient(anyString(), anyString(), anyInt(), anyInt())).thenReturn(new ArrayList<NotificationEntity>());
when(adapter.toNotification(Matchers.<ArrayList<NotificationEntity>>any())).thenReturn(notificationPermissions);
NotificationManager notificationManager = new NotificationManagerImpl();
ReflectionTestUtils.setField(notificationManager, "notificationAdapter", adapter);
ReflectionTestUtils.setField(notificationManager, "notificationDao", notificationDao);
NotificationPermissions notifications = notificationManager.findPermissionsByOrcidAndClient("some-orcid", "some-client", 0, OrcidApiConstants.MAX_NOTIFICATIONS_AVAILABLE);
assertEquals(notificationPermissions.size(), notifications.getNotifications().size());
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class NotificationsTest method createNotificationInvalidWorkIDType.
@Test
public void createNotificationInvalidWorkIDType() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_3.0_dev1/samples/notification-permission-3.0_dev1.xml");
notification.setPutCode(null);
notification.getItems().getItems().get(0).getExternalIdentifier().setType("invalid");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient_V3_0_dev1.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.
@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_3.0_dev1/samples/notification-permission-3.0_dev1.xml");
notification.setPutCode(null);
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
authUrl.setUri(null);
authUrl.setPath("/oauth/authorize?client_id=0000-0003-4223-0632&response_type=code&scope=/read-limited /activities/update&redirect_uri=https://developers.google.com/oauthplayground");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient_V3_0_dev1.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertNull(response.getLocation());
}
Aggregations