use of org.orcid.jaxb.model.groupid_rc2.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();
}
}
use of org.orcid.jaxb.model.groupid_rc2.GroupIdRecord in project ORCID-Source by ORCID.
the class ValidateV2RC1SamplesTest method validateGroupIdValue.
@Test
public void validateGroupIdValue() throws SAXException, IOException, JAXBException {
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(getClass().getResource("/group-id-2.0_rc1/group-id-2.0_rc1.xsd"));
Validator validator = schema.newValidator();
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
char[] upperAlphabet = "abcdefghijklmnopqrstuvwxyz".toUpperCase().toCharArray();
char[] numbers = "0123456789".toCharArray();
char[] validCharacters = "^._~:/?#[]@!$&'()*+,;=-".toCharArray();
//All valid characters
char[] allValid = ArrayUtils.addAll(alphabet, upperAlphabet);
allValid = ArrayUtils.addAll(allValid, numbers);
allValid = ArrayUtils.addAll(allValid, validCharacters);
String invalidCharactersString = "{}\"<>\\";
char[] invalidCharacters = invalidCharactersString.toCharArray();
//All valid and non valid characters
char[] allWithInvalids = ArrayUtils.addAll(allValid, invalidCharacters);
GroupIdRecord g1 = new GroupIdRecord();
g1.setDescription("description");
g1.setType("newsletter");
System.out.println("Validating group_id agains a list of 3000 valid values");
for (int i = 0; i < 3000; i++) {
String randomValue = "orcid-generated:" + RandomStringUtils.random(200, allValid);
g1.setName(randomValue);
g1.setGroupId(randomValue);
JAXBContext context;
context = JAXBContext.newInstance(GroupIdRecord.class);
Source source = new JAXBSource(context, g1);
try {
validator.validate(source);
} catch (Exception e) {
fail("fail validating: " + randomValue + " on iteration " + i);
}
}
System.out.println("Validating group_id agains a list of 3000 invalid values");
for (int i = 0; i < 3000; i++) {
String randomValue = "orcid-generated:" + RandomStringUtils.random(200, allWithInvalids);
boolean regenerateString = true;
do {
for (int j = 0; j < randomValue.length(); j++) {
if (invalidCharactersString.contains(String.valueOf(randomValue.charAt(j)))) {
regenerateString = false;
break;
}
}
if (regenerateString) {
randomValue += RandomStringUtils.random(3, invalidCharacters);
regenerateString = false;
}
} while (regenerateString);
g1.setName(randomValue);
g1.setGroupId(randomValue);
JAXBContext context;
context = JAXBContext.newInstance(GroupIdRecord.class);
Source source = new JAXBSource(context, g1);
try {
validator.validate(source);
fail(randomValue + " should not be vaild according to the XSD on iteration " + i);
} catch (Exception e) {
}
}
}
use of org.orcid.jaxb.model.groupid_rc2.GroupIdRecord in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl 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();
}
use of org.orcid.jaxb.model.groupid_rc2.GroupIdRecord in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_GroupIdTest method testGetGroupIdRecord.
@Test
public void testGetGroupIdRecord() {
SecurityContextTestUtils.setUpSecurityContextForGroupIdClientOnly();
Response response = serviceDelegator.viewGroupIdRecord(Long.valueOf("2"));
assertNotNull(response);
GroupIdRecord groupIdRecord = (GroupIdRecord) response.getEntity();
assertNotNull(groupIdRecord);
Utils.verifyLastModified(groupIdRecord.getLastModifiedDate());
assertEquals(Long.valueOf(2), groupIdRecord.getPutCode());
assertEquals("issn:0000002", groupIdRecord.getGroupId());
assertEquals("TestGroup2", groupIdRecord.getName());
assertEquals("TestDescription2", groupIdRecord.getDescription());
assertEquals("publisher", groupIdRecord.getType());
}
use of org.orcid.jaxb.model.groupid_rc2.GroupIdRecord in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_GeneralTest method testOrcidProfileCreateCanViewAndCreateGroupIds.
@Test
public void testOrcidProfileCreateCanViewAndCreateGroupIds() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
try {
serviceDelegator.viewGroupIdRecord(1L);
} catch (Exception e) {
fail();
}
try {
serviceDelegator.viewGroupIdRecords("10", "1");
} catch (Exception e) {
fail();
}
GroupIdRecord groupIdRecord = Utils.getGroupIdRecord();
try {
serviceDelegator.createGroupIdRecord(groupIdRecord);
} catch (Exception e) {
fail();
}
GroupIdRecordEntity toDelete = groupIdRecordDao.findByGroupId(groupIdRecord.getGroupId());
groupIdRecordDao.remove(toDelete.getId());
}
Aggregations