Skip to content

Commit

Permalink
[CST-14906] Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Sep 24, 2024
1 parent e9811a0 commit e0ccaea
Showing 1 changed file with 52 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,8 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation
EntityType projectType = EntityTypeBuilder.createEntityTypeBuilder(context, "Project").build();
EntityType personType = EntityTypeBuilder.createEntityTypeBuilder(context, "Person").build();
EntityType orgUnitType = EntityTypeBuilder.createEntityTypeBuilder(context, "OrgUnit").build();
EntityType productType = EntityTypeBuilder.createEntityTypeBuilder(context, "Product").build();
EntityType patentType = EntityTypeBuilder.createEntityTypeBuilder(context, "Patent").build();

RelationshipType isAuthorOfPublication = createRelationshipTypeBuilder(context, personType, publicationType,
"isAuthorOfPublication", "isPublicationOfAuthor", 0, null, 0, null).build();
Expand All @@ -2386,6 +2388,14 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation
RelationshipType isProjectOfPerson = createRelationshipTypeBuilder(context, projectType, personType,
"isProjectOfPerson", "isPersonOfProject", 0, null, 0, null).build();

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

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



EPerson ePerson = EPersonBuilder.createEPerson(context)
.withCanLogin(true)
.withOrcid("0000-1111-2222-3333")
Expand All @@ -2406,32 +2416,25 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation

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

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

Collection orgUnits = createCollection("OrgUnits", "OrgUnit");

Item publication = createPublication(publications, "Test publication", profile, isAuthorOfPublication);
Collection projects = createCollection("Projects", "Project");

Item product = createProduct(products, "Test product", profile);
Collection patents = createCollection("Patents", "Patent");

Collection projects = createCollection("Projects", "Project");
Collection products = createCollection("Products", "Product");

Item publication = createPublication(publications, "Test publication", profile, isAuthorOfPublication);

Item firstProject = createProject(projects, "First project", profile, isProjectOfPerson);
Item secondProject = createProject(projects, "Second project", profile, isProjectOfPerson);

createOrgUnit(orgUnits, "OrgUnit", profile, isOrgUnitOfPerson);

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

Item firstPatent = createPatent(patents, "First patent", profile);
Item secondPatent = createPatent(patents, "Second patent", profile);

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


Item firstFunding = createFundingWithInvestigator(fundings, "First funding", profile);
Item secondFunding = createFundingWithCoInvestigator(fundings, "Second funding", profile);
Item firstPatent = createPatent(patents, "First patent", profile, isPatentOfInventor);
Item secondPatent = createPatent(patents, "Second patent", profile, isPatentOfInventor);

Item product = createProduct(products, "Test product", profile, isProductOfCreator);

context.restoreAuthSystemState();

Expand Down Expand Up @@ -2468,28 +2471,41 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());

queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId);
assertThat(queueRecords, hasSize(5));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(publication)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstProject)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondProject)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstPatent)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondPatent)));

getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString())
.content(
getPatchContent(asList(new ReplaceOperation("/orcid/products", "ALL"))))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());

queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId);
assertThat(queueRecords, hasSize(6));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(publication)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstFunding)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondFunding)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(product)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstProject)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondProject)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstPatent)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondPatent)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(product)));

getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString())
.content(getPatchContent(
asList(new ReplaceOperation("/orcid/products", "ALL"))))
.content(getPatchContent(asList(new ReplaceOperation("/orcid/publications", "DISABLED"))))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());
.andExpect(status().isOk());

queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId);
assertThat(queueRecords, hasSize(5));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstFunding)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondFunding)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(product)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstProject)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondProject)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstPatent)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondPatent)));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(product)));

getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString())
.content(getPatchContent(
Expand Down Expand Up @@ -2522,30 +2538,6 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation

assertThat(orcidQueueService.findByProfileItemId(context, profileItemId), empty());

configurationService.setProperty("orcid.linkable-metadata-fields.ignore", "crisfund.coinvestigators");

getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString())
.content(
getPatchContent(asList(new ReplaceOperation(
"/orcid/fundings",
"DISABLED"))))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());

queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId);
assertThat(queueRecords, hasSize(1));
assertThat(queueRecords, has(orcidQueueRecordWithEntity(product)));

getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString())
.content(
getPatchContent(asList(new ReplaceOperation(
"/orcid/products",
"DISABLED"))))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk());

assertThat(orcidQueueService.findByProfileItemId(context, profileItemId), empty());

}

@Test
Expand Down Expand Up @@ -2788,19 +2780,25 @@ private Item createPublication(Collection collection, String title, Item author,

}

private Item createProduct(Collection collection, String title, Item author) {
return ItemBuilder.createItem(context, collection)
private Item createProduct(Collection collection, String title, Item person, RelationshipType isCreatorOfProduct) {
Item product = ItemBuilder.createItem(context, collection)
.withTitle(title)
.withAuthor(author.getName())
.build();

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

return product;
}


private Item createPatent(Collection collection, String title, Item author) {
return ItemBuilder.createItem(context, collection)
private Item createPatent(Collection collection, String title, Item person, RelationshipType isInventorOfPatent) {
Item patent = ItemBuilder.createItem(context, collection)
.withTitle(title)
.withAuthor(author.getName())
.build();

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

return patent;
}

private Item createOrgUnit(Collection collection, String title, Item person,
Expand Down

0 comments on commit e0ccaea

Please sign in to comment.