use of org.orcid.core.exception.DuplicatedGroupIdRecordException in project ORCID-Source by ORCID.
the class GroupIdRecordManagerTest method testCreateDuplicateGroupIdRecords.
@Test
public void testCreateDuplicateGroupIdRecords() {
GroupIdRecord g1 = new GroupIdRecord();
g1.setDescription("Description");
g1.setGroupId("orcid-generated:valid-group-id#1");
g1.setName("Group # " + System.currentTimeMillis());
g1.setType("publisher");
//Create the first one
g1 = groupIdRecordManager.createGroupIdRecord(g1);
Long putCode = g1.getPutCode();
assertNotNull(g1.getSource());
assertNotNull(g1.getSource().getSourceClientId());
assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
//Try to create a duplicate
try {
g1.setPutCode(null);
g1 = groupIdRecordManager.createGroupIdRecord(g1);
fail();
} catch (DuplicatedGroupIdRecordException e) {
} catch (Exception e) {
fail();
}
//Try to create a UPPER duplicate
try {
g1.setPutCode(null);
g1.setGroupId("orcid-generated:VALID-GROUP-ID#1");
g1 = groupIdRecordManager.createGroupIdRecord(g1);
fail();
} catch (DuplicatedGroupIdRecordException e) {
} catch (Exception e) {
fail();
}
//Try to create a duplicate mixed cases
try {
g1.setPutCode(null);
g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
g1 = groupIdRecordManager.createGroupIdRecord(g1);
fail();
} catch (DuplicatedGroupIdRecordException e) {
} catch (Exception e) {
fail();
}
//Create a different one
g1.setPutCode(null);
g1.setGroupId("orcid-generated:valid-group-id#2");
GroupIdRecord g2 = groupIdRecordManager.createGroupIdRecord(g1);
assertNotNull(g2);
assertNotNull(g2.getPutCode());
assertTrue(!g2.getPutCode().equals(putCode));
assertEquals("orcid-generated:valid-group-id#2", g2.getGroupId());
assertNotNull(g2.getSource());
assertNotNull(g2.getSource().getSourceClientId());
assertEquals(CLIENT_ID, g2.getSource().getSourceClientId().getPath());
//Try to create again a duplicate for any of the two existing
try {
g1.setPutCode(null);
g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
g1 = groupIdRecordManager.createGroupIdRecord(g1);
fail();
} catch (DuplicatedGroupIdRecordException e) {
} catch (Exception e) {
fail();
}
try {
g1.setPutCode(null);
g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#2");
g1 = groupIdRecordManager.createGroupIdRecord(g1);
fail();
} catch (DuplicatedGroupIdRecordException e) {
} catch (Exception e) {
fail();
}
groupIdRecordManager.deleteGroupIdRecord(putCode);
groupIdRecordManager.deleteGroupIdRecord(g2.getPutCode());
}
use of org.orcid.core.exception.DuplicatedGroupIdRecordException in project ORCID-Source by ORCID.
the class GroupIdRecordManagerTest method testUpdateDuplicateGroupIdRecords.
@Test
public void testUpdateDuplicateGroupIdRecords() {
String groupName = "Group # " + System.currentTimeMillis();
GroupIdRecord g1 = new GroupIdRecord();
g1.setDescription("Description");
g1.setGroupId("orcid-generated:valid-group-id#1");
g1.setName(groupName);
g1.setType("publisher");
//Create the first one
g1 = groupIdRecordManager.createGroupIdRecord(g1);
Long putCode1 = g1.getPutCode();
assertNotNull(g1.getSource());
assertNotNull(g1.getSource().getSourceClientId());
assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
//Create another one
g1.setPutCode(null);
g1.setGroupId("orcid-generated:valid-group-id#2");
g1 = groupIdRecordManager.createGroupIdRecord(g1);
Long putCode2 = g1.getPutCode();
assertNotNull(g1.getSource());
assertNotNull(g1.getSource().getSourceClientId());
assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
//Create another one
g1.setPutCode(null);
g1.setGroupId("orcid-generated:valid-group-id#3");
g1 = groupIdRecordManager.createGroupIdRecord(g1);
Long putCode3 = g1.getPutCode();
assertNotNull(g1.getSource());
assertNotNull(g1.getSource().getSourceClientId());
assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
//Update #1 with an existing group id
try {
GroupIdRecord existingOne = groupIdRecordManager.findByGroupId("orcid-generated:valid-group-id#1").get();
existingOne.setGroupId("orcid-generated:valid-group-id#2");
existingOne.setDescription("updated-description");
groupIdRecordManager.updateGroupIdRecord(existingOne.getPutCode(), existingOne);
fail();
} catch (DuplicatedGroupIdRecordException e) {
} catch (Exception e) {
fail();
}
//Update #1 with an existing group id
try {
GroupIdRecord existingOne = groupIdRecordManager.findByGroupId("orcid-generated:valid-group-id#1").get();
existingOne.setGroupId("orcid-generated:valid-group-id#3");
existingOne.setDescription("updated-description");
groupIdRecordManager.updateGroupIdRecord(existingOne.getPutCode(), existingOne);
fail();
} catch (DuplicatedGroupIdRecordException e) {
} catch (Exception e) {
fail();
}
//Update #1 with a new group id
GroupIdRecord existingOne = groupIdRecordManager.findByGroupId("orcid-generated:valid-group-id#1").get();
existingOne.setGroupId("orcid-generated:valid-group-id#1-updated");
existingOne.setDescription("updated-description");
existingOne = groupIdRecordManager.updateGroupIdRecord(existingOne.getPutCode(), existingOne);
assertNotNull(existingOne);
assertEquals(putCode1, existingOne.getPutCode());
assertEquals("orcid-generated:valid-group-id#1-updated", existingOne.getGroupId());
assertEquals("updated-description", existingOne.getDescription());
assertEquals(groupName, existingOne.getName());
assertNotNull(existingOne.getSource());
assertNotNull(existingOne.getSource().getSourceClientId());
assertEquals(CLIENT_ID, existingOne.getSource().getSourceClientId().getPath());
//Delete them
groupIdRecordManager.deleteGroupIdRecord(putCode1);
groupIdRecordManager.deleteGroupIdRecord(putCode2);
groupIdRecordManager.deleteGroupIdRecord(putCode3);
}
Aggregations