Search in sources :

Example 91 with PeerReview

use of org.orcid.jaxb.model.record_rc1.PeerReview in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validatePeerReview_invalidPutCodeTest.

@Test(expected = InvalidPutCodeException.class)
public void validatePeerReview_invalidPutCodeTest() {
    SourceEntity source = mock(SourceEntity.class);
    when(source.getSourceName()).thenReturn("source name");
    PeerReview pr = getPeerReview();
    pr.setPutCode(1L);
    activityValidator.validatePeerReview(pr, source, true, true, Visibility.PUBLIC);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 92 with PeerReview

use of org.orcid.jaxb.model.record_rc1.PeerReview in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validatePeerReview_dontChangeVisibilityTest.

@Test(expected = VisibilityMismatchException.class)
public void validatePeerReview_dontChangeVisibilityTest() {
    PeerReview pr = getPeerReview();
    pr.setVisibility(Visibility.LIMITED);
    activityValidator.validatePeerReview(pr, null, false, true, Visibility.PUBLIC);
}
Also used : PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 93 with PeerReview

use of org.orcid.jaxb.model.record_rc1.PeerReview in project ORCID-Source by ORCID.

the class MemberV2_1Test method testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.1/samples/read_samples/peer-review-2.1.xml", PeerReview.class);
    peerReviewToCreate.setPutCode(null);
    peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
    peerReviewToCreate.setVisibility(Visibility.PUBLIC);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType(WorkExternalIdentifierType.AGR.value());
    wExtId.setRelationship(Relationship.SELF);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2_1ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, 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/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
    ClientResponse getResponse = memberV2_1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
    assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
    gotPeerReview.getSubjectName().getTitle().setContent("updated title");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV2_1ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotPeerReview);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2_1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    PeerReview gotAfterUpdatePeerReview = getAfterUpdateResponse.getEntity(PeerReview.class);
    assertEquals("peer-review:subject-name", gotAfterUpdatePeerReview.getSubjectName().getTitle().getContent());
    ClientResponse deleteResponse = memberV2_1ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdatePeerReview.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 94 with PeerReview

use of org.orcid.jaxb.model.record_rc1.PeerReview in project ORCID-Source by ORCID.

the class MemberV2_1Test method createViewUpdateAndDeletePeerReview.

@Test
public void createViewUpdateAndDeletePeerReview() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.1/samples/read_samples/peer-review-2.1.xml", PeerReview.class);
    peerReviewToCreate.setPutCode(null);
    peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType(WorkExternalIdentifierType.AGR.value());
    wExtId.setRelationship(Relationship.SELF);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2_1ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, 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/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
    ClientResponse getResponse = memberV2_1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
    assertEquals("peer-review:url", gotPeerReview.getUrl().getValue());
    assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
    assertEquals(groupRecords.get(0).getGroupId(), gotPeerReview.getGroupId());
    //Save the original visibility
    Visibility originalVisibility = gotPeerReview.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    //Verify you cant update the visibility
    gotPeerReview.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2_1ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    //Set the visibility again to the initial one
    gotPeerReview.setVisibility(originalVisibility);
    gotPeerReview.getSubjectName().getTitle().setContent("updated title");
    putResponse = memberV2_1ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2_1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    PeerReview gotAfterUpdateWork = getAfterUpdateResponse.getEntity(PeerReview.class);
    assertEquals("updated title", gotAfterUpdateWork.getSubjectName().getTitle().getContent());
    assertEquals(groupRecords.get(0).getGroupId(), gotAfterUpdateWork.getGroupId());
    ClientResponse deleteResponse = memberV2_1ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdateWork.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Visibility(org.orcid.jaxb.model.common_v2.Visibility) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 95 with PeerReview

use of org.orcid.jaxb.model.record_rc1.PeerReview in project ORCID-Source by ORCID.

the class MemberV2Test method testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0/samples/read_samples/peer-review-2.0.xml", PeerReview.class);
    peerReviewToCreate.setPutCode(null);
    peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
    peerReviewToCreate.setVisibility(Visibility.PUBLIC);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType(WorkExternalIdentifierType.AGR.value());
    wExtId.setRelationship(Relationship.SELF);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, 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/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
    assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
    gotPeerReview.getSubjectName().getTitle().setContent("updated title");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotPeerReview);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    PeerReview gotAfterUpdatePeerReview = getAfterUpdateResponse.getEntity(PeerReview.class);
    assertEquals("peer-review:subject-name", gotAfterUpdatePeerReview.getSubjectName().getTitle().getContent());
    ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdatePeerReview.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)71 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)68 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 Response (javax.ws.rs.core.Response)17 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)17 DBUnitTest (org.orcid.test.DBUnitTest)17 Url (org.orcid.jaxb.model.common_v2.Url)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)10 ArrayList (java.util.ArrayList)9 PeerReview (org.orcid.jaxb.model.record_rc1.PeerReview)9 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)8 BaseTest (org.orcid.core.BaseTest)6 Title (org.orcid.jaxb.model.common_v2.Title)6 WorkExternalIdentifier (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier)6 WorkExternalIdentifierId (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId)6 PeerReview (org.orcid.jaxb.model.record_rc3.PeerReview)6 PeerReview (org.orcid.jaxb.model.record_rc4.PeerReview)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 Funding (org.orcid.jaxb.model.record_v2.Funding)6 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)6