use of org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method createNotificationInvalidWorkIDType.
@Test
public void createNotificationInvalidWorkIDType() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0/samples/notification-permission-2.0.xml");
notification.setPutCode(null);
notification.getItems().getItems().get(0).getExternalIdentifier().setType("invalid");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.
@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0/samples/notification-permission-2.0.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.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertNull(response.getLocation());
}
use of org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationManagerTest method filterActionedNotificationAlertsTest.
@Test
public void filterActionedNotificationAlertsTest() {
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
when(mockNotificationDao.findByOricdAndId(Matchers.anyString(), Matchers.anyLong())).thenReturn(null);
List<Notification> notifications = IntStream.range(0, 10).mapToObj(new IntFunction<Notification>() {
@Override
public Notification apply(int value) {
if (value % 3 == 0) {
NotificationInstitutionalConnection n = new NotificationInstitutionalConnection();
n.setSource(new Source("0000-0000-0000-0000"));
n.setPutCode(Long.valueOf(value));
return n;
} else {
NotificationPermission n = new NotificationPermission();
n.setPutCode(Long.valueOf(value));
return n;
}
}
}).collect(Collectors.toList());
assertEquals(10, notifications.size());
notifications = notificationManager.filterActionedNotificationAlerts(notifications, "some-orcid");
assertEquals(6, notifications.size());
for (Notification n : notifications) {
assertEquals(NotificationType.PERMISSION, n.getNotificationType());
assertNotNull(n.getPutCode());
assertThat(n.getPutCode(), not(anyOf(is(Long.valueOf(0)), is(Long.valueOf(3)), is(Long.valueOf(6)), is(Long.valueOf(9)))));
}
}
use of org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method createNotificationInvalidWorkIDType.
@Test
public void createNotificationInvalidWorkIDType() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc2/samples/notification-permission-2.0_rc2.xml");
notification.setPutCode(null);
notification.getItems().getItems().get(0).getExternalIdentifier().setType("invalid");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method flagAsArchived.
@Test
public void flagAsArchived() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc2/samples/notification-permission-2.0_rc2.xml");
notification.setPutCode(null);
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse postResponse = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc2/" + testUser1OrcidId + "/notification-permission/\\d+"));
String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
Long putCode = Long.valueOf(putCodeString);
ClientResponse viewResponse = notificationsClient.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
assertEquals(Response.Status.OK.getStatusCode(), viewResponse.getStatus());
NotificationPermission retrievedNotification = viewResponse.getEntity(NotificationPermission.class);
assertNotNull(retrievedNotification);
assertNull(retrievedNotification.getArchivedDate());
ClientResponse archiveResponse = notificationsClient.flagAsArchivedPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
assertEquals(Response.Status.OK.getStatusCode(), archiveResponse.getStatus());
ClientResponse viewAfterArchiveResponse = notificationsClient.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
assertEquals(Response.Status.OK.getStatusCode(), viewAfterArchiveResponse.getStatus());
NotificationPermission retrievedAfterArchiveNotification = viewAfterArchiveResponse.getEntity(NotificationPermission.class);
assertNotNull(retrievedAfterArchiveNotification.getArchivedDate());
}
Aggregations