Skip to content

Commit

Permalink
CST-12510 fix ITs, fix QAEvent generated by LDNCorrectionAction
Browse files Browse the repository at this point in the history
  • Loading branch information
abollini committed Nov 4, 2023
1 parent 5cc5a2a commit ebb8985
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public class LDNCorrectionAction implements LDNAction {
public ActionStatus execute(Notification notification, Item item) throws Exception {
ActionStatus result;
Context context = ContextUtil.obtainCurrentRequestContext();
//FIXME the original id should be just an (optional) identifier/reference of the event in
// the external system. The target Item should be passed as a constructor argument
QAEvent qaEvent = new QAEvent(QAEvent.COAR_NOTIFY,
notification.getObject().getId(), item.getID().toString(), item.getName(),
"oai:localhost:" + item.getHandle(), item.getID().toString(), item.getName(),
this.getQaEventTopic(), getScore(context, notification).doubleValue(),
"{\"abstracts[0]\": \"" + notification.getObject().getIetfCiteAs() + "\"}"
, new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.Charset;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.dspace.app.ldn.LDNMessageEntity;
import org.dspace.app.ldn.NotifyServiceEntity;
import org.dspace.app.ldn.model.Notification;
import org.dspace.app.ldn.service.LDNMessageService;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.builder.NotifyServiceBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
Expand Down Expand Up @@ -58,7 +61,6 @@ public void ldnInboxEndorsementActionTest() throws Exception {
Collection collection = CollectionBuilder.createCollection(context, community).build();
Item item = ItemBuilder.createItem(context, collection).build();
String object = configurationService.getProperty("dspace.ui.url") + "/handle/" + item.getHandle();

context.restoreAuthSystemState();

InputStream offerEndorsementStream = getClass().getResourceAsStream("ldn_offer_endorsement_object.json");
Expand All @@ -68,7 +70,7 @@ public void ldnInboxEndorsementActionTest() throws Exception {
ObjectMapper mapper = new ObjectMapper();
Notification notification = mapper.readValue(message, Notification.class);

getClient(getAuthToken(admin.getEmail(), password))
getClient()
.perform(post("/ldn/inbox")
.contentType("application/ld+json")
.content(message))
Expand Down Expand Up @@ -96,7 +98,7 @@ public void ldnInboxAnnounceEndorsementTest() throws Exception {

ObjectMapper mapper = new ObjectMapper();
Notification notification = mapper.readValue(message, Notification.class);
getClient(getAuthToken(admin.getEmail(), password))
getClient()
.perform(post("/ldn/inbox")
.contentType("application/ld+json")
.content(message))
Expand All @@ -109,12 +111,22 @@ public void ldnInboxAnnounceEndorsementTest() throws Exception {

@Test
public void ldnInboxAnnounceReviewTest() throws Exception {
context.turnOffAuthorisationSystem();
NotifyServiceEntity serviceEntity = NotifyServiceBuilder.createNotifyServiceBuilder(context)
.withName("Review Service")
.withLdnUrl("https://review-service.com/inbox/")
.withScore(BigDecimal.valueOf(0.6d))
.build();
Community com = CommunityBuilder.createCommunity(context).withName("Test Community").build();
Collection col = CollectionBuilder.createCollection(context, com).withName("Test Collection").build();
Item item = ItemBuilder.createItem(context, col).withHandle("123456789/9999").withTitle("Test Item").build();
context.restoreAuthSystemState();
InputStream announceReviewStream = getClass().getResourceAsStream("ldn_announce_review.json");
String message = IOUtils.toString(announceReviewStream, Charset.defaultCharset());
announceReviewStream.close();
ObjectMapper mapper = new ObjectMapper();
Notification notification = mapper.readValue(message, Notification.class);
getClient(getAuthToken(admin.getEmail(), password))
getClient()
.perform(post("/ldn/inbox")
.contentType("application/ld+json")
.content(message))
Expand All @@ -134,7 +146,7 @@ public void ldnInboxEndorsementActionBadRequestTest() throws Exception {
offerEndorsementStream.close();
ObjectMapper mapper = new ObjectMapper();
Notification notification = mapper.readValue(message, Notification.class);
getClient(getAuthToken(admin.getEmail(), password))
getClient()
.perform(post("/ldn/inbox")
.contentType("application/ld+json")
.content(message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void findAllTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.submissioncoarnotifyconfigs", Matchers.containsInAnyOrder(
SubmissionCOARNotifyMatcher.matchCOARNotifyEntry("default",
SubmissionCOARNotifyMatcher.matchCOARNotifyEntry("coarnotify",
List.of("review", "endorsement", "ingest"))
)));
}
Expand All @@ -64,11 +64,11 @@ public void findOneTestNonExistingCOARNotify() throws Exception {
public void findOneTest() throws Exception {
String epersonToken = getAuthToken(eperson.getEmail(), password);

getClient(epersonToken).perform(get("/api/config/submissioncoarnotifyconfigs/default"))
getClient(epersonToken).perform(get("/api/config/submissioncoarnotifyconfigs/coarnotify"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", Matchers.is(
SubmissionCOARNotifyMatcher.matchCOARNotifyEntry("default",
SubmissionCOARNotifyMatcher.matchCOARNotifyEntry("coarnotify",
List.of("review", "endorsement", "ingest"))
)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void findSections() throws Exception {
// We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))
// Match only that a section exists with a submission configuration behind
.andExpect(jsonPath("$._embedded.submissionsections", hasSize(9)))
.andExpect(jsonPath("$._embedded.submissionsections", hasSize(10)))
.andExpect(jsonPath("$._embedded.submissionsections",
Matchers.hasItem(
allOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "Service"
},
"context": {
"id": "oai:http://localhost:4000/handle:123456789/12",
"id": "http://localhost:4000/handle/123456789/9999",
"ietf:cite-as": "https://doi.org/10.5555/12345680",
"type": "sorg:AboutPage",
"url": {
Expand Down
1 change: 1 addition & 0 deletions dspace/config/dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ registry.metadata.load = openaire4-types.xml
registry.metadata.load = dspace-types.xml
registry.metadata.load = iiif-types.xml
registry.metadata.load = datacite-types.xml
registry.metadata.load = coar-types.xml


#---------------------------------------------------------------#
Expand Down

0 comments on commit ebb8985

Please sign in to comment.