Search in sources :

Example 1 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithAbsentAuthorizationUriElement.

@Test
public void createPermissionNotificationWithAbsentAuthorizationUriElement() 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("");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse postResponse = notificationsClient_V3_0_dev1.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(".*/v3.0_dev1/" + testUser1OrcidId + "/notification-permission/\\d+"));
    String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
    Long putCode = Long.valueOf(putCodeString);
    ClientResponse viewResponse = notificationsClient_V3_0_dev1.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), viewResponse.getStatus());
    NotificationPermission retrievedNotification = viewResponse.getEntity(NotificationPermission.class);
    assertNotNull(retrievedNotification);
    assertTrue(retrievedNotification.getAuthorizationUrl().getPath().endsWith(authUrl.getPath()));
    assertFalse(retrievedNotification.getAuthorizationUrl().getPath().startsWith("http"));
    assertTrue(retrievedNotification.getAuthorizationUrl().getUri().startsWith("http"));
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Test(org.junit.Test)

Example 2 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.

@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() 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(authUrl.getUri() + "    ");
    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());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Test(org.junit.Test)

Example 3 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithBlankAuthorizationUri.

@Test
public void createPermissionNotificationWithBlankAuthorizationUri() 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("");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse postResponse = notificationsClient_V3_0_dev1.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(".*/v3.0_dev1/" + testUser1OrcidId + "/notification-permission/\\d+"));
    String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
    Long putCode = Long.valueOf(putCodeString);
    ClientResponse viewResponse = notificationsClient_V3_0_dev1.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), viewResponse.getStatus());
    NotificationPermission retrievedNotification = viewResponse.getEntity(NotificationPermission.class);
    assertNotNull(retrievedNotification);
    assertTrue(retrievedNotification.getAuthorizationUrl().getPath().endsWith(authUrl.getPath()));
    assertFalse(retrievedNotification.getAuthorizationUrl().getPath().startsWith("http"));
    assertTrue(retrievedNotification.getAuthorizationUrl().getUri().startsWith("http"));
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Test(org.junit.Test)

Example 4 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method unmarshall.

public NotificationPermission unmarshall(Reader reader) {
    try {
        JAXBContext context = JAXBContext.newInstance(NotificationPermission.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (NotificationPermission) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 5 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method flagAsArchived.

@Test
public void flagAsArchived() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_3.0_dev1/samples/notification-permission-3.0_dev1.xml");
    notification.setPutCode(null);
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse postResponse = notificationsClient_V3_0_dev1.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(".*/v3.0_dev1/" + testUser1OrcidId + "/notification-permission/\\d+"));
    String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
    Long putCode = Long.valueOf(putCodeString);
    ClientResponse viewResponse = notificationsClient_V3_0_dev1.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_V3_0_dev1.flagAsArchivedPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), archiveResponse.getStatus());
    ClientResponse viewAfterArchiveResponse = notificationsClient_V3_0_dev1.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.v3.dev1.notification.permission.NotificationPermission) Test(org.junit.Test)

Aggregations

NotificationPermission (org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission)14 Test (org.junit.Test)10 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 AuthorizationUrl (org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl)7 Notification (org.orcid.jaxb.model.v3.dev1.notification.Notification)5 NotificationInstitutionalConnection (org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection)4 URISyntaxException (java.net.URISyntaxException)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 IntFunction (java.util.function.IntFunction)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 Source (org.orcid.jaxb.model.v3.dev1.common.Source)2 NotificationType (org.orcid.jaxb.model.v3.dev1.notification.NotificationType)2 Item (org.orcid.jaxb.model.v3.dev1.notification.permission.Item)2 NotificationAddItemsEntity (org.orcid.persistence.jpa.entities.NotificationAddItemsEntity)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1