Search in sources :

Example 16 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class GroupIdRecordManagerTest method testCreateUpdateGetDeleteGroupIdRecord.

@Test
public void testCreateUpdateGetDeleteGroupIdRecord() {
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("Description");
    g1.setGroupId("orcid-generated:valid-group-id");
    g1.setName("Group # " + System.currentTimeMillis());
    g1.setType("publisher");
    // Test create
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode = g1.getPutCode();
    assertNotNull(putCode);
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    // Test find
    assertTrue(groupIdRecordManager.exists(g1.getGroupId()));
    Optional<GroupIdRecord> existingByGroupId = groupIdRecordManager.findByGroupId(g1.getGroupId());
    assertTrue(existingByGroupId.isPresent());
    assertNotNull(existingByGroupId.get().getPutCode());
    assertEquals(putCode, existingByGroupId.get().getPutCode());
    assertEquals(g1.getGroupId(), existingByGroupId.get().getGroupId());
    assertNotNull(existingByGroupId.get().getSource());
    assertNotNull(existingByGroupId.get().getSource().getSourceClientId());
    assertEquals(CLIENT_ID, existingByGroupId.get().getSource().getSourceClientId().getPath());
    GroupIdRecord existingByPutCode = groupIdRecordManager.getGroupIdRecord(g1.getPutCode());
    assertNotNull(existingByPutCode);
    assertNotNull(existingByPutCode.getPutCode());
    assertEquals(putCode, existingByPutCode.getPutCode());
    assertEquals(g1.getGroupId(), existingByPutCode.getGroupId());
    assertNotNull(existingByPutCode.getSource());
    assertNotNull(existingByPutCode.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, existingByPutCode.getSource().getSourceClientId().getPath());
    // Test update with invalid value
    try {
        g1.setGroupId("invalid-group-id");
        groupIdRecordManager.updateGroupIdRecord(g1.getPutCode(), g1);
        fail();
    } catch (OrcidValidationException e) {
        assertEquals("Invalid group-id: '" + g1.getGroupId() + "'", e.getMessage());
    } catch (Exception e) {
        fail();
    }
    // Test update with valid value
    try {
        g1.setGroupId("orcid-generated:other-valid-group-id");
        g1 = groupIdRecordManager.updateGroupIdRecord(g1.getPutCode(), g1);
        assertNotNull(g1);
        assertEquals("orcid-generated:other-valid-group-id", g1.getGroupId());
    } catch (Exception e) {
        fail();
    }
    // Test create with put code
    try {
        g1.setGroupId("orcid-generated:valid-group-id");
        groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (InvalidPutCodeException e) {
    } catch (Exception e) {
        fail();
    }
    // Test create with invalid group id
    try {
        g1.setPutCode(null);
        g1.setGroupId("other-invalid-group-id");
        groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (OrcidValidationException e) {
        assertEquals("Invalid group-id: '" + g1.getGroupId() + "'", e.getMessage());
    } catch (Exception e) {
        fail();
    }
    // Test delete
    groupIdRecordManager.deleteGroupIdRecord(putCode);
    try {
        groupIdRecordManager.deleteGroupIdRecord(Long.valueOf(-1L));
    } catch (GroupIdRecordNotFoundException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 17 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateGroupId_validTest.

/**
 * VALIDATE GROUP ID RECORD
 */
@Test
public void validateGroupId_validTest() {
    SourceEntity source = mock(SourceEntity.class);
    when(source.getSourceName()).thenReturn("source name");
    GroupIdRecord g = getGroupIdRecord();
    activityValidator.validateGroupIdRecord(g, true, source);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) Test(org.junit.Test)

Example 18 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateGroupId_invalidGroupIdTest.

@Test(expected = OrcidValidationException.class)
public void validateGroupId_invalidGroupIdTest() {
    SourceEntity source = mock(SourceEntity.class);
    when(source.getSourceName()).thenReturn("source name");
    GroupIdRecord g = getGroupIdRecord();
    g.setGroupId("invalid");
    activityValidator.validateGroupIdRecord(g, true, source);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) Test(org.junit.Test)

Example 19 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class ActivityValidatorTest method getGroupIdRecord.

public GroupIdRecord getGroupIdRecord() {
    GroupIdRecord g = new GroupIdRecord();
    g.setDescription("description");
    g.setGroupId("orcid-generated:0123456789");
    g.setName("group-name");
    g.setType("group-type");
    return g;
}
Also used : GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)

Example 20 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method viewGroupIdRecord.

@Override
public Response viewGroupIdRecord(Long putCode) {
    orcidSecurityManager.checkScopes(ScopePathType.GROUP_ID_RECORD_READ);
    GroupIdRecord record = groupIdRecordManagerReadOnly.getGroupIdRecord(putCode);
    return Response.ok(record).build();
}
Also used : GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)

Aggregations

GroupIdRecord (org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)21 Test (org.junit.Test)10 InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)4 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)4 DBUnitTest (org.orcid.test.DBUnitTest)4 HashMap (java.util.HashMap)3 Response (javax.ws.rs.core.Response)3 BaseTest (org.orcid.core.BaseTest)3 DuplicatedGroupIdRecordException (org.orcid.core.exception.DuplicatedGroupIdRecordException)3 GroupIdRecordNotFoundException (org.orcid.core.exception.GroupIdRecordNotFoundException)3 GroupIdRecordEntity (org.orcid.persistence.jpa.entities.GroupIdRecordEntity)3 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)3 ArrayList (java.util.ArrayList)2 LastModifiedDate (org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate)2 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)2 PeerReviewForm (org.orcid.pojo.ajaxForm.PeerReviewForm)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 AccessControlException (java.security.AccessControlException)1