[CST-12108] fix failed tests

This commit is contained in:
Mykhaylo Boychuk
2023-12-04 12:03:54 +01:00
parent 481f0de80a
commit b642aee9f4
3 changed files with 81 additions and 51 deletions

View File

@@ -0,0 +1,30 @@
/**
* 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() { }
}

View File

@@ -32,6 +32,7 @@ import org.dspace.content.QAEvent;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.handle.HandleServiceImpl;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.qaevent.service.BrokerClientFactory; import org.dspace.qaevent.service.BrokerClientFactory;
import org.dspace.qaevent.service.QAEventService; import org.dspace.qaevent.service.QAEventService;
@@ -105,7 +106,7 @@ public class OpenaireEventsImport
jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
DSpace dspace = new DSpace(); DSpace dspace = new DSpace();
handleService = dspace.getSingletonService(HandleService.class); handleService = dspace.getSingletonService(HandleServiceImpl.class);
qaEventService = dspace.getSingletonService(QAEventService.class); qaEventService = dspace.getSingletonService(QAEventService.class);
configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
brokerClient = BrokerClientFactory.getInstance().getBrokerClient(); brokerClient = BrokerClientFactory.getInstance().getBrokerClient();

View File

@@ -15,6 +15,7 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@@ -32,6 +33,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.util.List;
import eu.dnetlib.broker.BrokerClient; import eu.dnetlib.broker.BrokerClient;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@@ -46,6 +48,8 @@ import org.dspace.content.Item;
import org.dspace.content.QAEvent; import org.dspace.content.QAEvent;
import org.dspace.matcher.QASourceMatcher; import org.dspace.matcher.QASourceMatcher;
import org.dspace.matcher.QATopicMatcher; 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.BrokerClientFactory;
import org.dspace.qaevent.service.QAEventService; import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.impl.BrokerClientFactoryImpl; import org.dspace.qaevent.service.impl.BrokerClientFactoryImpl;
@@ -142,7 +146,6 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testManyEventsImportFromFile() throws Exception { public void testManyEventsImportFromFile() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -163,14 +166,14 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
"Trying to read the QA events from the provided file", "Trying to read the QA events from the provided file",
"Found 5 events in the given file")); "Found 5 events in the given file"));
assertThat(qaEventService.findAllSources(context, 0, 20), contains(QASourceMatcher.with(OPENAIRE_SOURCE, 5L))); assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 5L)));
assertThat(qaEventService.findAllTopics(context, 0, 20), containsInAnyOrder( List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L)));
QATopicMatcher.with("ENRICH/MORE/PID", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));
QATopicMatcher.with("ENRICH/MISSING/PID", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L)));
QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L))); assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L)));
String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\"," String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\","
+ "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\"," + "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\","
@@ -191,7 +194,6 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d))); abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d)));
verifyNoInteractions(mockBrokerClient); verifyNoInteractions(mockBrokerClient);
} }
@Test @Test
@@ -210,23 +212,22 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
assertThat(handler.getErrorMessages(), empty()); assertThat(handler.getErrorMessages(), empty());
assertThat(handler.getWarningMessages(), assertThat(handler.getWarningMessages(),
contains("An error occurs storing the event with id b4e09c71312cd7c397969f56c900823f: " contains("An error occurs storing the event with id 406fb9c5656c7f11cac8995abb746887: "
+ "Skipped event b4e09c71312cd7c397969f56c900823f related to the oai record " + "Skipped event 406fb9c5656c7f11cac8995abb746887 related to the oai record "
+ "oai:www.openstarts.units.it:123456789/99998 as the record was not found", + "oai:www.openstarts.units.it:123456789/99998 as the record was not found",
"An error occurs storing the event with id d050d2c4399c6c6ccf27d52d479d26e4: " "An error occurs storing the event with id eafd747feee49cca7603d30ba4e768dc: "
+ "Skipped event d050d2c4399c6c6ccf27d52d479d26e4 related to the oai record " + "Skipped event eafd747feee49cca7603d30ba4e768dc related to the oai record "
+ "oai:www.openstarts.units.it:123456789/99998 as the record was not found")); + "oai:www.openstarts.units.it:123456789/99998 as the record was not found"));
assertThat(handler.getInfoMessages(), contains( assertThat(handler.getInfoMessages(), contains(
"Trying to read the QA events from the provided file", "Trying to read the QA events from the provided file",
"Found 5 events in the given file")); "Found 5 events in the given file"));
assertThat(qaEventService.findAllSources(context, 0, 20), contains(QASourceMatcher.with(OPENAIRE_SOURCE, 3L))); assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 3L)));
assertThat(qaEventService.findAllTopics(context, 0, 20), containsInAnyOrder( List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L)));
QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
QATopicMatcher.with("ENRICH/MORE/PID", 1L) assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));
));
String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}"; String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}";
@@ -236,7 +237,6 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d))); abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d)));
verifyNoInteractions(mockBrokerClient); verifyNoInteractions(mockBrokerClient);
} }
@Test @Test
@@ -256,25 +256,26 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
assertThat(handler.getErrorMessages(), empty()); assertThat(handler.getErrorMessages(), empty());
assertThat(handler.getWarningMessages(), assertThat(handler.getWarningMessages(),
contains("Event for topic ENRICH/MORE/UNKNOWN is not allowed in the qaevents.cfg")); contains("An error occurs storing the event with id 8307aa56769deba961faed7162d91aab:"
+ " Skipped event 8307aa56769deba961faed7162d91aab related to the oai record"
+ " oai:www.openstarts.units.it:123456789/99998 as the record was not found"));
assertThat(handler.getInfoMessages(), contains( assertThat(handler.getInfoMessages(), contains(
"Trying to read the QA events from the provided file", "Trying to read the QA events from the provided file",
"Found 2 events in the given file")); "Found 2 events in the given file"));
assertThat(qaEventService.findAllSources(context, 0, 20), contains(QASourceMatcher.with(OPENAIRE_SOURCE, 1L))); assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 1L)));
assertThat(qaEventService.findAllTopics(context, 0, 20), 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\"}"; String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}";
assertThat(qaEventService.findEventsByTopic(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20), assertThat(qaEventService.findEventsByTopic(context, OPENAIRE_SOURCE,
contains( QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20), contains(
pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/999991", secondItem, "Test Publication 2", 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); verifyNoInteractions(mockBrokerClient);
} }
@Test @Test
@@ -337,14 +338,14 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
"Found 0 events from the subscription sub2", "Found 0 events from the subscription sub2",
"Found 2 events from the subscription sub3")); "Found 2 events from the subscription sub3"));
assertThat(qaEventService.findAllSources(context, 0, 20), contains(QASourceMatcher.with(OPENAIRE_SOURCE, 6L))); assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 6L)));
assertThat(qaEventService.findAllTopics(context, 0, 20), containsInAnyOrder( List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L)));
QATopicMatcher.with("ENRICH/MORE/PID", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));
QATopicMatcher.with("ENRICH/MISSING/PID", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L)));
QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 2L))); assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 2L)));
String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\"," String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\","
+ "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\"," + "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\","
@@ -403,7 +404,6 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testImportFromOpenaireBrokerWithErrorDuringEventsDownload() throws Exception { public void testImportFromOpenaireBrokerWithErrorDuringEventsDownload() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -443,19 +443,19 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
"Found 0 events from the subscription sub2", "Found 0 events from the subscription sub2",
"Found 2 events from the subscription sub3")); "Found 2 events from the subscription sub3"));
assertThat(qaEventService.findAllSources(context, 0, 20), contains(QASourceMatcher.with(OPENAIRE_SOURCE, 6L))); assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 6L)));
assertThat(qaEventService.findAllTopics(context, 0, 20), containsInAnyOrder( List<QATopic> topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20);
QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L)));
QATopicMatcher.with("ENRICH/MISSING/PID", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L)));
QATopicMatcher.with("ENRICH/MORE/PID", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L)));
QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L), assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L)));
QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 2L))); assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 2L)));
assertThat(qaEventService.findEventsByTopic(context, OPENAIRE_SOURCE, "ENRICH/MORE/PROJECT", 0, 20), assertThat(qaEventService.findEventsByTopic(context, OPENAIRE_SOURCE,
hasSize(1)); QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 0, 20), hasSize(1));
assertThat(qaEventService.findEventsByTopic(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20), assertThat(qaEventService.findEventsByTopic(context, OPENAIRE_SOURCE,
hasSize(2)); QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20), hasSize(2));
verify(mockBrokerClient).listSubscriptions(openaireURL, "user@test.com"); verify(mockBrokerClient).listSubscriptions(openaireURL, "user@test.com");
verify(mockBrokerClient).downloadEvents(eq(openaireURL), eq("sub1"), any()); verify(mockBrokerClient).downloadEvents(eq(openaireURL), eq("sub1"), any());
@@ -463,7 +463,6 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
verify(mockBrokerClient).downloadEvents(eq(openaireURL), eq("sub3"), any()); verify(mockBrokerClient).downloadEvents(eq(openaireURL), eq("sub3"), any());
verifyNoMoreInteractions(mockBrokerClient); verifyNoMoreInteractions(mockBrokerClient);
} }
private Item createItem(String title, String handle) { private Item createItem(String title, String handle) {