Search in sources :

Example 16 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithBlankAuthorizationUri.

@Test
public void createPermissionNotificationWithBlankAuthorizationUri() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0/samples/notification-permission-2.0.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri("");
    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/" + 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);
    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.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 17 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.

@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.1/samples/notification-permission-2.1.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri(authUrl.getUri() + "    ");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse response = notificationsClient_V2_1.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 AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithBlankAuthorizationUri.

@Test
public void createPermissionNotificationWithBlankAuthorizationUri() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.1/samples/notification-permission-2.1.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri("");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse postResponse = notificationsClient_V2_1.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.1/" + testUser1OrcidId + "/notification-permission/\\d+"));
    String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
    Long putCode = Long.valueOf(putCodeString);
    ClientResponse viewResponse = notificationsClient_V2_1.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.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 19 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithAbsentAuthorizationUriElement.

@Test
public void createPermissionNotificationWithAbsentAuthorizationUriElement() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc2/samples/notification-permission-2.0_rc2.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri("");
    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);
    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.notification.permission_rc2.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission) Test(org.junit.Test)

Example 20 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.

@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc1/samples/notification-permission-2.0_rc1.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_rc1.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 ClientResponse (com.sun.jersey.api.client.ClientResponse)24 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)13 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)11 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc1.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc2.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission)4 Source (org.orcid.jaxb.model.common_v2.Source)2 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)2 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)2 NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)2 Item (org.orcid.jaxb.model.notification.permission_v2.Item)2 Items (org.orcid.jaxb.model.notification.permission_v2.Items)2 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)2 NotificationAddItemsEntity (org.orcid.persistence.jpa.entities.NotificationAddItemsEntity)2