Search in sources :

Example 16 with NotificationPermission

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Test(org.junit.Test)

Example 17 with NotificationPermission

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());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Test(org.junit.Test)

Example 18 with NotificationPermission

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)))));
    }
}
Also used : NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) IntFunction(java.util.function.IntFunction) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Source(org.orcid.jaxb.model.common_v2.Source) Notification(org.orcid.jaxb.model.notification_v2.Notification) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 19 with NotificationPermission

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission) Test(org.junit.Test)

Example 20 with NotificationPermission

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)45 ClientResponse (com.sun.jersey.api.client.ClientResponse)41 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)24 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)11 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission)8 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission)8 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission)8 JAXBContext (javax.xml.bind.JAXBContext)7 JAXBException (javax.xml.bind.JAXBException)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission)7 Notification (org.orcid.jaxb.model.notification_v2.Notification)6 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)5 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc2.AuthorizationUrl)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl)4 ArrayList (java.util.ArrayList)3 Source (org.orcid.jaxb.model.common_v2.Source)3 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)3