Skip to content

Commit

Permalink
Merge pull request kitodo#6018 from effective-webwork/import-service-…
Browse files Browse the repository at this point in the history
…selenium-tests

Import service Selenium test
  • Loading branch information
solth authored Apr 4, 2024
2 parents 26a97fd + 624f3b4 commit 5be1123
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 73 deletions.
36 changes: 28 additions & 8 deletions Kitodo/src/test/java/org/kitodo/MockDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import org.kitodo.production.services.ServiceManager;
import org.kitodo.production.workflow.model.Converter;
import org.kitodo.test.utils.ProcessTestUtils;
import org.kitodo.test.utils.TestConstants;

import static com.xebialabs.restito.builder.stub.StubHttp.whenHttp;
import static com.xebialabs.restito.semantics.Condition.get;
Expand Down Expand Up @@ -136,6 +137,7 @@ public class MockDatabase {
public static final String HIERARCHY_CHILD_TO_KEEP = "HierarchyChildToKeep";
public static final String HIERARCHY_CHILD_TO_REMOVE = "HierarchyChildToRemove";
public static final String HIERARCHY_CHILD_TO_ADD = "HierarchyChildToAdd";
public static final int PORT = 8888;

public static void startDatabaseServer() throws SQLException {
tcpServer = Server.createTcpServer().start();
Expand Down Expand Up @@ -1685,7 +1687,7 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti

// add GBV import configuration, including id and default search fields
ImportConfiguration gbvConfiguration = new ImportConfiguration();
gbvConfiguration.setTitle("GBV");
gbvConfiguration.setTitle(TestConstants.GBV);
gbvConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name());
gbvConfiguration.setInterfaceType(SearchInterfaceType.SRU.name());
gbvConfiguration.setSruVersion("1.2");
Expand All @@ -1709,28 +1711,28 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti

// add Kalliope import configuration, including id search field
ImportConfiguration kalliopeConfiguration = new ImportConfiguration();
kalliopeConfiguration.setTitle("Kalliope");
kalliopeConfiguration.setTitle(TestConstants.KALLIOPE);
kalliopeConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name());
kalliopeConfiguration.setInterfaceType(SearchInterfaceType.SRU.name());
kalliopeConfiguration.setSruVersion("1.2");
kalliopeConfiguration.setSruRecordSchema("mods");
kalliopeConfiguration.setHost("localhost");
kalliopeConfiguration.setScheme("http");
kalliopeConfiguration.setPath("/sru");
kalliopeConfiguration.setPort(8888);
kalliopeConfiguration.setPort(PORT);
kalliopeConfiguration.setPrestructuredImport(false);
kalliopeConfiguration.setReturnFormat(FileFormat.XML.name());
kalliopeConfiguration.setMetadataFormat(MetadataFormat.MODS.name());
kalliopeConfiguration.setMappingFiles(Collections.singletonList(ServiceManager.getMappingFileService()
.getById(1)));

SearchField idSearchFieldKalliope = new SearchField();
idSearchFieldKalliope.setValue("ead.id");
idSearchFieldKalliope.setValue(TestConstants.EAD_ID);
idSearchFieldKalliope.setLabel("Identifier");
idSearchFieldKalliope.setImportConfiguration(kalliopeConfiguration);

SearchField parentIdSearchFieldKalliope = new SearchField();
parentIdSearchFieldKalliope.setValue("context.ead.id");
parentIdSearchFieldKalliope.setValue(TestConstants.EAD_PARENT_ID);
parentIdSearchFieldKalliope.setLabel("Parent ID");
parentIdSearchFieldKalliope.setImportConfiguration(kalliopeConfiguration);

Expand All @@ -1747,15 +1749,16 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti

// add K10Plus import configuration, including id search field
ImportConfiguration k10plusConfiguration = new ImportConfiguration();
k10plusConfiguration.setTitle("K10Plus");
k10plusConfiguration.setTitle(TestConstants.K10PLUS);
k10plusConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name());
k10plusConfiguration.setInterfaceType(SearchInterfaceType.SRU.name());
k10plusConfiguration.setSruVersion("1.1");
k10plusConfiguration.setSruRecordSchema("picaxml");
k10plusConfiguration.setHost("localhost");
k10plusConfiguration.setScheme("http");
k10plusConfiguration.setPath("/sru");
k10plusConfiguration.setPort(8888);
k10plusConfiguration.setPort(PORT);
k10plusConfiguration.setDefaultImportDepth(1);
k10plusConfiguration.setPrestructuredImport(false);
k10plusConfiguration.setReturnFormat(FileFormat.XML.name());
k10plusConfiguration.setMetadataFormat(MetadataFormat.PICA.name());
Expand Down Expand Up @@ -1807,7 +1810,7 @@ public static void insertImportconfigurationWithCustomUrlParameters() throws DAO
customConfiguration.setHost("localhost");
customConfiguration.setScheme("http");
customConfiguration.setPath("/custom");
customConfiguration.setPort(8888);
customConfiguration.setPort(PORT);
customConfiguration.setPrestructuredImport(false);
customConfiguration.setReturnFormat(FileFormat.XML.name());
customConfiguration.setMetadataFormat(MetadataFormat.PICA.name());
Expand Down Expand Up @@ -2165,6 +2168,23 @@ public static Process addProcess(String processTitle, int projectId, int templat
* @param numberOfRecords URL parameter containing maximum number of records associated with this endpoint
* @throws IOException when reading the response file fails
*/
public static void addRestEndPointForSru(StubServer server, String query, String filePath, String format,
int startRecord, int numberOfRecords)
throws IOException {
try (InputStream inputStream = Files.newInputStream(Paths.get(filePath))) {
String serverResponse = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
whenHttp(server)
.match(get("/sru"),
parameter("operation", "searchRetrieve"),
parameter("recordSchema", format),
parameter("startRecord", String.valueOf(startRecord)),
parameter("maximumRecords", String.valueOf(numberOfRecords)),
parameter("query", query))
.then(Action.ok(), Action.contentType("text/xml"), Action.stringContent(serverResponse));
}

}

public static void addRestEndPointForSru(StubServer server, String query, String filePath, String format,
int numberOfRecords)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
import org.kitodo.SecurityTestUtils;
import org.kitodo.production.helper.TempProcess;
import org.kitodo.production.services.ServiceManager;
import org.kitodo.test.utils.TestConstants;

public class CatalogImportIT {

private static StubServer server;
private static final int PORT = 8888;
private static final String HITLIST_RECORD_PATH = "src/test/resources/importRecords/importHitlist.xml";
private static final String CHILD_RECORD_PATH = "src/test/resources/importRecords/importChildRecord.xml";
private static final String PARENT_RECORD_PATH = "src/test/resources/importRecords/importParentRecord.xml";
private static final String CHILD_RECORD_ID = "1";
private static final String PARENT_RECORD_ID = "2";
private static final int PROJECT_ID = 1;
Expand Down Expand Up @@ -67,8 +65,8 @@ public void shouldImportProcessHierarchy() throws Exception {

private static void setupServer() throws IOException {
server = new StubServer(PORT).run();
MockDatabase.addRestEndPointForSru(server, "ead.id=" + CHILD_RECORD_ID, CHILD_RECORD_PATH, "mods", 1);
MockDatabase.addRestEndPointForSru(server, "ead.id=" + PARENT_RECORD_ID, PARENT_RECORD_PATH, "mods", 1);
MockDatabase.addRestEndPointForSru(server, "ead.title=test", HITLIST_RECORD_PATH, "mods",10);
MockDatabase.addRestEndPointForSru(server, "ead.id=" + CHILD_RECORD_ID, TestConstants.CHILD_RECORD_PATH, "mods", 1);
MockDatabase.addRestEndPointForSru(server, "ead.id=" + PARENT_RECORD_ID, TestConstants.PARENT_RECORD_PATH, "mods", 1);
MockDatabase.addRestEndPointForSru(server, "ead.title=test", TestConstants.HITLIST_RECORD_PATH, "mods",10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.kitodo.production.helper.Helper;
import org.kitodo.production.services.ServiceManager;
import org.kitodo.production.services.data.ImportService;
import org.kitodo.test.utils.TestConstants;

public class ImportServiceTest {

Expand Down Expand Up @@ -181,8 +182,8 @@ private ImportConfiguration createImportConfiguration(SearchInterfaceType interf
private List<SearchField> createSearchFields(ImportConfiguration importConfiguration) {
List<SearchField> SearchFields = new ArrayList<>();
SearchFields.add(addSearchField(TITLE, "ead.tit", importConfiguration, true));
SearchFields.add(addSearchField(RECORD_ID, "ead.id", importConfiguration, true));
SearchFields.add(addSearchField(PARENT_ID, "context.ead.id", importConfiguration, false));
SearchFields.add(addSearchField(RECORD_ID, TestConstants.EAD_ID, importConfiguration, true));
SearchFields.add(addSearchField(PARENT_ID, TestConstants.EAD_PARENT_ID, importConfiguration, false));
importConfiguration.setSearchFields(SearchFields);
return SearchFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.kitodo.production.helper.XMLUtils;
import org.kitodo.production.services.ServiceManager;
import org.kitodo.test.utils.ProcessTestUtils;
import org.kitodo.test.utils.TestConstants;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -104,16 +105,13 @@ public class ImportServiceIT {
private static final List<String> CHILD_RECORD_IDS = Arrays.asList("9991", "9992", "9993");
private static final String KALLIOPE_RECORD_ID = "999";
private static final String CUSTOM_INTERFACE_RECORD_ID = "12345";
private static final int PORT = 8888;
private static final int TEMPLATE_ID = 1;
private static final int PROJECT_ID = 1;
private static final int RULESET_ID = 1;
private static final int EXPECTED_NR_OF_CHILDREN = 23;
private static final String PICA_XML = "picaxml";
private static final String MODS = "mods";
private static final String PICA_PPN = "pica.ppn";
private static final String PICA_PARENT_ID = "pica.parentId";
private static final String EAD_PARENT_ID = "context.ead.id";
private static final String firstProcess = "First process";
private static final String TEST_PROCESS_TITLE = "Testtitel";
private static final String KITODO = "kitodo";
Expand All @@ -136,7 +134,7 @@ public static void prepareDatabase() throws Exception {
SecurityTestUtils.addUserDataToSecurityContext(userOne, 1);
return !processService.findByTitle(firstProcess).isEmpty();
});
server = new StubServer(PORT).run();
server = new StubServer(MockDatabase.PORT).run();
setupServer();
}

Expand Down Expand Up @@ -527,9 +525,9 @@ private static void setupServer() throws IOException {
// REST endpoint for testing failed import of child records
MockDatabase.addRestEndPointForSru(server, PICA_PARENT_ID + "=" + RECORD_ID, TEST_FILE_PATH_NUMBER_OF_HITS, PICA_XML, 1);
// REST endpoint for testing successful import of child records
MockDatabase.addRestEndPointForSru(server, EAD_PARENT_ID + "=" + KALLIOPE_RECORD_ID, CHILD_RECORDS_PATH, MODS, 3);
MockDatabase.addRestEndPointForSru(server, TestConstants.EAD_PARENT_ID + "=" + KALLIOPE_RECORD_ID, CHILD_RECORDS_PATH, TestConstants.MODS, 3);
// REST endpoint for testing retrieval of child records given existing parent process
MockDatabase.addRestEndPointForSru(server, EAD_PARENT_ID + "=" + PARENT_RECORD_CATALOG_ID, CHILD_RECORDS_PATH, MODS,3);
MockDatabase.addRestEndPointForSru(server, TestConstants.EAD_PARENT_ID + "=" + PARENT_RECORD_CATALOG_ID, CHILD_RECORDS_PATH, TestConstants.MODS,3);
// REST endpoint for successful import from custom search interface
MockDatabase.addRestEndPointForCustom(server, TEST_FILE_SUCCESS_RESPONSE_PATH, CUSTOM_INTERFACE_RECORD_ID,
"firstValue");
Expand Down
42 changes: 29 additions & 13 deletions Kitodo/src/test/java/org/kitodo/selenium/AddingST.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import com.xebialabs.restito.server.StubServer;
import org.apache.commons.lang3.SystemUtils;
import org.junit.After;
import org.junit.AfterClass;
Expand Down Expand Up @@ -60,6 +63,7 @@

public class AddingST extends BaseTestSelenium {

private static StubServer server;
private static ProcessesPage processesPage;
private static ProjectsPage projectsPage;
private static UsersPage usersPage;
Expand All @@ -68,6 +72,9 @@ public class AddingST extends BaseTestSelenium {
private static ImportConfigurationEditPage importConfigurationEditPage;
private static final String TEST_METADATA_FILE = "testMetadataFileServiceTest.xml";
private static int secondProcessId = -1;
private static final String PICA_PPN = "pica.ppn";
private static final String PICA_XML = "picaxml";
private static final String TEST_FILE_PATH = "src/test/resources/sruTestRecord.xml";

@BeforeClass
public static void setup() throws Exception {
Expand All @@ -88,6 +95,13 @@ public static void setup() throws Exception {
}
assertTrue("Should find exactly one second process!", secondProcessId > 0);
ProcessTestUtils.copyTestMetadataFile(secondProcessId, TEST_METADATA_FILE);
server = new StubServer(MockDatabase.PORT).run();
setupServer();
}

private static void setupServer() throws IOException {
// REST endpoint for testing metadata import
MockDatabase.addRestEndPointForSru(server, PICA_PPN + "=test", TEST_FILE_PATH, PICA_XML, 1);
}

/**
Expand All @@ -97,6 +111,7 @@ public static void setup() throws Exception {
@AfterClass
public static void removeUnsuitableParentTestProcess() throws DAOException {
ProcessTestUtils.removeTestProcess(secondProcessId);
server.stop();
}

@Before
Expand Down Expand Up @@ -158,12 +173,10 @@ public void addProcessesTest() throws Exception {
assertTrue("Created Process was not listed at processes table!", processAvailable);

ProcessService processService = ServiceManager.getProcessService();
// TODO: make processService.findByTitle(generatedTitle) work
int recordNumber = 1;
Process generatedProcess;
do {
generatedProcess = processService.getById(recordNumber++);
} while (!generatedTitle.equals(generatedProcess.getTitle()));
Optional<Process> optionalProcess = processService.getAll().stream().filter(process -> generatedTitle
.equals(process.getTitle())).findAny();
assertTrue("Generated process not found in database", optionalProcess.isPresent());
Process generatedProcess = optionalProcess.get();
assertNull("Created Process unexpectedly got a parent!", generatedProcess.getParent());

projectsPage.createNewProcess();
Expand All @@ -173,12 +186,12 @@ public void addProcessesTest() throws Exception {
boolean childProcessAvailable = processesPage.getProcessTitles().contains(generatedChildTitle);
assertTrue("Created Process was not listed at processes table!", childProcessAvailable);

// TODO: make processService.findByTitle(generatedChildTitle) work
Process generatedChildProcess;
do {
generatedChildProcess = processService.getById(recordNumber++);
} while (!generatedChildTitle.equals(generatedChildProcess.getTitle()));
Optional<Process> optionalChildProcess = processService.getAll().stream().filter(process -> generatedChildTitle
.equals(process.getTitle())).findAny();
assertTrue("Generated child process not found in database", optionalChildProcess.isPresent());
Process generatedChildProcess = optionalChildProcess.get();
assertEquals("Created Process has a wrong parent!", generatedProcess, generatedChildProcess.getParent());
ProcessTestUtils.removeTestProcess(generatedProcess.getId());
}

@Test
Expand All @@ -189,10 +202,9 @@ public void addProcessAsChildNotPossible() throws Exception {
Pages.getProcessFromTemplatePage().cancel();
}

@Ignore
@Test
public void addProcessFromCatalogTest() throws Exception {
assumeTrue(!SystemUtils.IS_OS_WINDOWS && !SystemUtils.IS_OS_MAC);
assumeTrue(!SystemUtils.IS_OS_WINDOWS);

projectsPage.createNewProcess();
assertEquals("Header for create new process is incorrect", "Einen neuen Vorgang anlegen (Produktionsvorlage: 'First template')",
Expand All @@ -201,6 +213,10 @@ public void addProcessFromCatalogTest() throws Exception {
String generatedTitle = Pages.getProcessFromTemplatePage().createProcessFromCatalog();
boolean processAvailable = processesPage.getProcessTitles().contains(generatedTitle);
assertTrue("Created Process was not listed at processes table!", processAvailable);
int index = processesPage.getProcessTitles().indexOf(generatedTitle);
assertTrue("Process table does not contain ID or new process", index >= 0);
int processId = Integer.parseInt(processesPage.getProcessIds().get(index));
ProcessTestUtils.removeTestProcess(processId);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.kitodo.selenium.testframework.Browser;
import org.kitodo.selenium.testframework.Pages;
import org.kitodo.selenium.testframework.pages.ProjectsPage;
import org.openqa.selenium.By;

public class ConfigConversionST extends BaseTestSelenium {

Expand Down Expand Up @@ -61,7 +62,12 @@ public void shouldImportCatalogConfigurations() throws Exception {
assertEquals(MODS_2_KITODO, importConfigurationsTab.getMappingFileTitle());
importConfigurationsTab.selectInputFormatMods();
importConfigurationsTab.selectOutputFormatKitodo();
importConfigurationsTab.clickMappingFileOkButton();
await("Wait for 'confirm mapping' button to be enabled")
.pollDelay(1, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.atMost(5, TimeUnit.SECONDS).ignoreExceptions()
.until(() -> Browser.getDriver().findElement(By.id("mappingFileFormatsForm:ok")).isEnabled());
Browser.getDriver().findElement(By.id("mappingFileFormatsForm:ok")).click();

await("Wait for 'Results' dialog to be displayed")
.atMost(5, TimeUnit.SECONDS)
Expand Down
Loading

0 comments on commit 5be1123

Please sign in to comment.