Skip to content

Commit

Permalink
CST-14906 Code fix after cherrypick (6) Test fix with new test forms …
Browse files Browse the repository at this point in the history
…and relation for OrcidQueueConsumerIT
  • Loading branch information
Mattia Vianelli committed Sep 20, 2024
1 parent 695139d commit f05e782
Showing 1 changed file with 32 additions and 228 deletions.
260 changes: 32 additions & 228 deletions dspace-api/src/test/java/org/dspace/orcid/OrcidQueueConsumerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,40 +574,6 @@ public void testNoOrcidQueueRecordCreationOccursIfPublicationSynchronizationIsDi
assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testOrcidQueueRecordCreationForFunding() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationFundingsPreference(ALL)
.build();

Collection fundingCollection = createCollection("Fundings", "Funding");

Item funding = ItemBuilder.createItem(context, fundingCollection)
.withTitle("Test funding")
.build();

context.restoreAuthSystemState();
context.commit();

List<OrcidQueue> orcidQueueRecords = orcidQueueService.findAll(context);
assertThat(orcidQueueRecords, hasSize(1));
assertThat(orcidQueueRecords.get(0), matches(profile, funding, "Funding", null, INSERT));

addMetadata(funding, "dc", "type", null, "Funding type", null);
context.commit();

List<OrcidQueue> newOrcidQueueRecords = orcidQueueService.findAll(context);
assertThat(newOrcidQueueRecords, hasSize(1));

assertThat(orcidQueueRecords.get(0), equalTo(newOrcidQueueRecords.get(0)));
}

@Test
public void testOrcidQueueRecordCreationForProduct() throws Exception {

Expand All @@ -627,6 +593,14 @@ public void testOrcidQueueRecordCreationForProduct() throws Exception {
.withAuthor("Test User")
.build();

EntityType productType = EntityTypeBuilder.createEntityTypeBuilder(context, "Product").build();
EntityType personType = EntityTypeBuilder.createEntityTypeBuilder(context, "Person").build();

RelationshipType isCreatorOfProduct = createRelationshipTypeBuilder(context, productType, personType,
"isCreatorOfProduct", "isProductOfCreator", 0, null, 0, null).build();

RelationshipBuilder.createRelationshipBuilder(context, product, profile, isCreatorOfProduct).build();

context.restoreAuthSystemState();
context.commit();

Expand Down Expand Up @@ -662,6 +636,14 @@ public void testOrcidQueueRecordCreationForPatent() throws Exception {
.withAuthor("Test User")
.build();

EntityType patentType = EntityTypeBuilder.createEntityTypeBuilder(context, "Patent").build();
EntityType personType = EntityTypeBuilder.createEntityTypeBuilder(context, "Person").build();

RelationshipType isInventorOfPatent = createRelationshipTypeBuilder(context, patentType, personType,
"isInventorOfPatent", "isPatentOfInventor", 0, null, 0, null).build();

RelationshipBuilder.createRelationshipBuilder(context, patent, profile, isInventorOfPatent).build();

context.restoreAuthSystemState();
context.commit();

Expand All @@ -678,43 +660,6 @@ public void testOrcidQueueRecordCreationForPatent() throws Exception {
assertThat(orcidQueueRecords.get(0), equalTo(newOrcidQueueRecords.get(0)));
}

@Test
public void testOrcidQueueRecordCreationToUpdateFunding() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationFundingsPreference(ALL)
.build();

Collection projectCollection = createCollection("Projects", "Project");

Item project = ItemBuilder.createItem(context, projectCollection)
.withTitle("Test project")
.build();

createOrcidHistory(context, profile, project)
.withPutCode("123456")
.build();

EntityType projectType = EntityTypeBuilder.createEntityTypeBuilder(context, "Project").build();
EntityType personType = EntityTypeBuilder.createEntityTypeBuilder(context, "Person").build();

RelationshipType isProjectOfPerson = createRelationshipTypeBuilder(context, projectType, personType,
"isProjectOfPerson", "isPersonOfProject", 0, null, 0, null).build();

RelationshipBuilder.createRelationshipBuilder(context, project, profile, isProjectOfPerson).build();

context.restoreAuthSystemState();
context.commit();

List<OrcidQueue> orcidQueueRecords = orcidQueueService.findAll(context);
assertThat(orcidQueueRecords, hasSize(1));
}

@Test
public void testOrcidQueueRecordCreationToUpdateProduct() throws Exception {

Expand All @@ -737,6 +682,14 @@ public void testOrcidQueueRecordCreationToUpdateProduct() throws Exception {
.withPutCode("123456")
.build();

EntityType productType = EntityTypeBuilder.createEntityTypeBuilder(context, "Product").build();
EntityType personType = EntityTypeBuilder.createEntityTypeBuilder(context, "Person").build();

RelationshipType isCreatorOfProduct = createRelationshipTypeBuilder(context, productType, personType,
"isCreatorOfProduct", "isProductOfCreator", 0, null, 0, null).build();

RelationshipBuilder.createRelationshipBuilder(context, product, profile, isCreatorOfProduct).build();

addMetadata(product, "dc", "contributor", "author", "Test User", profile.getID().toString());

context.restoreAuthSystemState();
Expand Down Expand Up @@ -769,6 +722,14 @@ public void testOrcidQueueRecordCreationToUpdatePatent() throws Exception {
.withPutCode("123456")
.build();

EntityType patentType = EntityTypeBuilder.createEntityTypeBuilder(context, "Patent").build();
EntityType personType = EntityTypeBuilder.createEntityTypeBuilder(context, "Person").build();

RelationshipType isInventorOfPatent = createRelationshipTypeBuilder(context, patentType, personType,
"isInventorOfPatent", "isPatentOfInventor", 0, null, 0, null).build();

RelationshipBuilder.createRelationshipBuilder(context, patent, profile, isInventorOfPatent).build();

addMetadata(patent, "dc", "contributor", "author", "Test User", profile.getID().toString());

context.restoreAuthSystemState();
Expand All @@ -779,34 +740,6 @@ public void testOrcidQueueRecordCreationToUpdatePatent() throws Exception {
assertThat(orcidQueueRecords.get(0), matches(profile, patent, "Patent", "123456", UPDATE));
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfFundingSynchronizationIsDisabled() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.build();

Collection fundingCollection = createCollection("Fundings", "Funding");

Item funding = ItemBuilder.createItem(context, fundingCollection)
.withTitle("Test funding")
.build();

context.restoreAuthSystemState();
context.commit();

assertThat(orcidQueueService.findAll(context), empty());

addMetadata(profile, "dspace", "orcid", "sync-fundings", DISABLED.name(), null);
context.commit();

assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfProductSynchronizationIsDisabled() throws Exception {

Expand Down Expand Up @@ -867,67 +800,6 @@ public void testNoOrcidQueueRecordCreationOccursIfPatentSynchronizationIsDisable
assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfProfileHasNotOrcidIdentifier() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationFundingsPreference(ALL)
.withOrcidSynchronizationProductsPreference(ALL)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Collection fundingCollection = createCollection("Fundings", "Funding");

ItemBuilder.createItem(context, fundingCollection)
.withTitle("Test funding")
.build();

Collection productCollection = createCollection("Products", "Product");

ItemBuilder.createItem(context, productCollection)
.withTitle("Test product")
.withAuthor("Test User")
.build();

Collection patentsCollection = createCollection("Patents", "Patent");

ItemBuilder.createItem(context, patentsCollection)
.withTitle("Test patent")
.withAuthor("Test User")
.build();

context.restoreAuthSystemState();
context.commit();

assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfProfileHasNotOrcidAccessToken() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidSynchronizationFundingsPreference(ALL)
.build();

Collection fundingCollection = createCollection("Fundings", "Funding");

ItemBuilder.createItem(context, fundingCollection)
.withTitle("Test funding")
.build();

context.restoreAuthSystemState();
context.commit();

assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testNoOrcidQueueRecordCreationOccursForNotConfiguredEntities() throws Exception {
Expand Down Expand Up @@ -1004,74 +876,6 @@ public void testOrcidQueueRecalculationOnProfilePreferenceUpdate() throws Except

}

@Test
public void testWithMetadataFieldToIgnore() throws Exception {
configurationService.addPropertyValue("orcid.linkable-metadata-fields.ignore", "dc.contributor.author");
configurationService.addPropertyValue("orcid.linkable-metadata-fields.ignore", "crisfund.coinvestigators");

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-0000-0012-2345")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationFundingsPreference(ALL)
.withOrcidSynchronizationPublicationsPreference(ALL)
.withOrcidSynchronizationProductsPreference(ALL)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Collection publicationCollection = createCollection("Publications", "Publication");

Item firstPublication = ItemBuilder.createItem(context, publicationCollection)
.withTitle("Another Test publication")
.withEditor("Test User")
.build();

Item secondPublication = ItemBuilder.createItem(context, publicationCollection)
.withTitle("Another Test publication")
.withAuthor("Test User")
.withEditor("Test User")
.build();

ItemBuilder.createItem(context, publicationCollection)
.withTitle("Test publication")
.withAuthor("Test User")
.build();

Collection fundingCollection = createCollection("Fundings", "Funding");

Item firstFunding = ItemBuilder.createItem(context, fundingCollection)
.withTitle("Test funding")
.build();

ItemBuilder.createItem(context, fundingCollection)
.withTitle("Another funding")
.build();

Collection productCollection = createCollection("Products", "Product");

Item firstProduct = ItemBuilder.createItem(context, productCollection)
.withTitle("Test product")
.withAuthor("Test User")
.build();

Collection patentCollection = createCollection("Patents", "Patent");

Item firstPatent = ItemBuilder.createItem(context, patentCollection)
.withTitle("Test patent")
.withAuthor("Test User")
.build();

context.restoreAuthSystemState();

List<OrcidQueue> records = orcidQueueService.findAll(context);
assertThat(records, hasSize(3));
assertThat(records, hasItem(matches(profile, firstPublication, "Publication", null, INSERT)));
assertThat(records, hasItem(matches(profile, secondPublication, "Publication", null, INSERT)));
assertThat(records, hasItem(matches(profile, firstFunding, "Funding", null, INSERT)));
}

@Test
public void testWithManyInsertionAndDeletionOfSameMetadataValue() throws Exception {

Expand Down

0 comments on commit f05e782

Please sign in to comment.