Skip to content

Commit

Permalink
Merged in CST-12406-introduce-constants (pull request DSpace#1298)
Browse files Browse the repository at this point in the history
CST-12406 instroduce constants first implementation and test fixes
  • Loading branch information
frabacche committed Nov 16, 2023
2 parents af0686d + 20f668a commit d313a98
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 167 deletions.
29 changes: 29 additions & 0 deletions dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.qaevent;

/**
* Constants for Quality Assurance configurations to be used into cfg and xml spring.
*
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
*
*/
public class QANotifyPatterns {
public static final String TOPIC_ENRICH_MORE_PROJECT = "ENRICH/MORE/PROJECT";
public static final String TOPIC_ENRICH_MISSING_PROJECT = "ENRICH/MISSING/PROJECT";
public static final String TOPIC_ENRICH_MISSING_ABSTRACT = "ENRICH/MISSING/ABSTRACT";
public static final String TOPIC_ENRICH_MORE_REVIEW = "ENRICH/MORE/REVIEW";
public static final String TOPIC_ENRICH_MORE_ENDORSEMENT = "ENRICH/MORE/ENDORSEMENT";
public static final String TOPIC_ENRICH_MORE_PID = "ENRICH/MORE/PID";
public static final String TOPIC_ENRICH_MISSING_PID = "ENRICH/MISSING/PID";

/**
* Default constructor
*/
private QANotifyPatterns() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.dspace.content.QAEvent;
import org.dspace.matcher.QASourceMatcher;
import org.dspace.matcher.QATopicMatcher;
import org.dspace.qaevent.QANotifyPatterns;
import org.dspace.qaevent.QATopic;
import org.dspace.qaevent.service.BrokerClientFactory;
import org.dspace.qaevent.service.QAEventService;
Expand All @@ -57,6 +58,7 @@
import org.junit.Before;
import org.junit.Test;


/**
* Integration tests for {@link OpenaireEventsImport}.
*
Expand Down Expand Up @@ -171,30 +173,33 @@ public void testManyEventsImportFromFile() throws Exception {
);

List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PID", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L)));

String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\","
+ "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\","
+ "\"projects[0].jurisdiction\":\"EU\","
+ "\"projects[0].openaireId\":\"40|corda__h2020::6e32f5eb912688f2424c68b851483ea4\","
+ "\"projects[0].title\":\"Tracking Papyrus and Parchment Paths\"}";

assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MORE/PROJECT", 0, 20),
assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 0, 20),
contains(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99998", firstItem,
"Egypt, crossroad of translations and literary interweavings", projectMessage,
"ENRICH/MORE/PROJECT", 1.00d)));
QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1.00d)));

String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}";

assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20),
assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20),
contains(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999", secondItem, "Test Publication",
abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d)));
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999",
secondItem, "Test Publication",
abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d)));

verifyNoInteractions(mockBrokerClient);

Expand Down Expand Up @@ -229,16 +234,17 @@ public void testManyEventsImportFromFileWithUnknownHandle() throws Exception {
assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 3L)));

List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));

String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}";

assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20),
assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20),
contains(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999", item, "Test Publication",
abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d)));
abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d)));

verifyNoInteractions(mockBrokerClient);

Expand Down Expand Up @@ -269,14 +275,15 @@ public void testManyEventsImportFromFileWithUnknownTopic() throws Exception {
assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 1L)));

assertThat(qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20),
contains(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L)));
contains(QATopicMatcher.with(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L)));

String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}";

assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20),
assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20),
contains(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/999991", secondItem, "Test Publication 2",
abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d)));
abstractMessage, org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d)));

verifyNoInteractions(mockBrokerClient);

Expand Down Expand Up @@ -345,34 +352,35 @@ public void testImportFromOpenaireBroker() throws Exception {
assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 6L)));

List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PID", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 2L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 2L)));

String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\","
+ "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\","
+ "\"projects[0].jurisdiction\":\"EU\","
+ "\"projects[0].openaireId\":\"40|corda__h2020::6e32f5eb912688f2424c68b851483ea4\","
+ "\"projects[0].title\":\"Tracking Papyrus and Parchment Paths\"}";

assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MORE/PROJECT", 0, 20),
assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 0, 20),
contains(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99998", firstItem,
"Egypt, crossroad of translations and literary interweavings", projectMessage,
"ENRICH/MORE/PROJECT", 1.00d)));
QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1.00d)));

String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}";

List<QAEvent> eventList = qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
"ENRICH/MISSING/ABSTRACT", 0, 20);
QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20);
assertThat(eventList, hasItem(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999", secondItem, "Test Publication",
abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d)));
abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d)));
assertThat(eventList, hasItem(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/999991", thirdItem, "Test Publication 2",
abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d)));
abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d)));

verify(mockBrokerClient).listSubscriptions(openaireURL, "[email protected]");
verify(mockBrokerClient).downloadEvents(eq(openaireURL), eq("sub1"), any());
Expand Down Expand Up @@ -454,15 +462,17 @@ public void testImportFromOpenaireBrokerWithErrorDuringEventsDownload() throws E
assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 6L)));

List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PID", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 2L)));

assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MORE/PROJECT", 0, 20),
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 2L)));

assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 0, 20),
hasSize(1));
assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20),
assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE,
QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20),
hasSize(2));

verify(mockBrokerClient).listSubscriptions(openaireURL, "[email protected]");
Expand All @@ -489,7 +499,7 @@ public void testImportFromFileEventMoreReview() throws Exception {
ScriptLauncher.handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl);

assertThat(qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20), contains(
QATopicMatcher.with("ENRICH/MORE/REVIEW", 1L)));
QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW, 1L)));

assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 1L)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.dspace.content.Item;
import org.dspace.matcher.QASourceMatcher;
import org.dspace.matcher.QATopicMatcher;
import org.dspace.qaevent.QANotifyPatterns;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.services.ConfigurationService;
import org.dspace.utils.DSpace;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void ldnInboxAnnounceReviewTest() throws Exception {
assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(COAR_NOTIFY, 1L)));

assertThat(qaEventService.findAllTopicsBySource(context, COAR_NOTIFY, 0, 20), contains(
QATopicMatcher.with("ENRICH/MORE/REVIEW", 1L)));
QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW, 1L)));

}

Expand Down
Loading

0 comments on commit d313a98

Please sign in to comment.