Skip to content

Commit

Permalink
Add MockDatabase index to Kitodo - DataManagement
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Sep 6, 2024
1 parent 3c07660 commit ecbe5bb
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Kitodo-DataManagement/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
</dependency>
<dependency>
<groupId>org.opensearch</groupId>
<artifactId>opensearch</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opensearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
Expand Down
22 changes: 22 additions & 0 deletions Kitodo-DataManagement/src/test/java/org/kitodo/ExtendedNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/
package org.kitodo;

import java.util.Collection;
import org.opensearch.env.Environment;
import org.opensearch.node.Node;
import org.opensearch.plugins.Plugin;

public class ExtendedNode extends Node {
ExtendedNode(Environment initialEnvironment, Collection<Class<? extends Plugin>> classpathPlugins) {
super(initialEnvironment, classpathPlugins, true);
}
}
63 changes: 63 additions & 0 deletions Kitodo-DataManagement/src/test/java/org/kitodo/MockDatabase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/
package org.kitodo;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import org.apache.commons.io.FileUtils;
import org.kitodo.config.ConfigMain;
import org.opensearch.common.settings.Settings;
import org.opensearch.env.Environment;
import org.opensearch.node.Node;
import org.opensearch.transport.Netty4Plugin;

public class MockDatabase {

private static Node node;
private static final String HTTP_TRANSPORT_PORT = "9305";
private static final String TARGET = "target";

public static void startNode() throws Exception {
final String nodeName = "index";
final String port = ConfigMain.getParameter("elasticsearch.port", "9205");
Environment environment = prepareEnvironment(port, nodeName, Paths.get("target", "classes"));
removeOldDataDirectories("target/" + nodeName);
node = new ExtendedNode(environment, Collections.singleton(Netty4Plugin.class));
node.start();
}

public static void stopNode() throws Exception {
node.close();
node = null;
}

private static void removeOldDataDirectories(String dataDirectory) throws Exception {
File dataDir = new File(dataDirectory);
if (dataDir.exists()) {
FileUtils.deleteDirectory(dataDir);
}
}

private static Environment prepareEnvironment(String httpPort, String nodeName, Path configPath) {
Settings settings = Settings.builder().put("node.name", nodeName)
.put("path.data", TARGET)
.put("path.logs", TARGET)
.put("path.home", TARGET)
.put("http.type", "netty4")
.put("http.port", httpPort)
.put("transport.tcp.port", HTTP_TRANSPORT_PORT)
.put("transport.type", "netty4")
.put("action.auto_create_index", "false").build();
return new Environment(settings, configPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.Authority;
import org.kitodo.data.database.exceptions.DAOException;

public class AuthorityDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.Client;
import org.kitodo.data.database.exceptions.DAOException;

public class ClientDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.DataEditorSetting;
import org.kitodo.data.database.exceptions.DAOException;


public class DataEditorSettingDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.Docket;
import org.kitodo.data.database.exceptions.DAOException;

public class DocketDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.Filter;
import org.kitodo.data.database.exceptions.DAOException;

public class FilterDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.LdapGroup;
import org.kitodo.data.database.exceptions.DAOException;

public class LdapGroupDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.LdapServer;
import org.kitodo.data.database.exceptions.DAOException;

public class LdapServerDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.Property;
import org.kitodo.data.database.enums.PropertyType;
import org.kitodo.data.database.exceptions.DAOException;

public class PropertyDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.Role;
import org.kitodo.data.database.exceptions.DAOException;

public class RoleDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.kitodo.MockDatabase;
import org.kitodo.data.database.beans.Ruleset;
import org.kitodo.data.database.exceptions.DAOException;

public class RulesetDaoIT {

@BeforeClass
public static void setUp() throws Exception {
MockDatabase.startNode();
}

@AfterClass
public static void tearDown() throws Exception {
MockDatabase.stopNode();
}

@Rule
public final ExpectedException exception = ExpectedException.none();

Expand Down
Loading

0 comments on commit ecbe5bb

Please sign in to comment.