Merge "Update Changes and README (closes #128)"
diff --git a/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java b/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
index 9caace7..d83c434 100644
--- a/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
+++ b/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
@@ -11,6 +11,7 @@
import java.io.*;
import java.lang.String;
import java.util.Properties;
+
import org.tinylog.Logger;
public class ExWSConf {
@@ -41,45 +42,72 @@
return VERSION;
}
}
- // Load properties from file
- public static Properties properties (String propFile) {
+
+ /*
+ * Sets properties to null
+ * Is needed for testing purposes.
+ */
+ public static void clearProp(){
+ prop = null;
+ }
- if (prop != null)
- return prop;
-
- if (propFile == null)
- propFile = "exportPlugin.conf";
-
- InputStream iFile;
+ /**
+ *Loads properties from a UTF-8 encoded file
+ */
+ public static Properties loadProp(Properties aprop, String file){
+
+ InputStream diFile;
+ if(aprop == null){
+ aprop = new Properties();
+ }
+
try {
-
- iFile = new FileInputStream(propFile);
- prop = new Properties();
- prop.load(
+ diFile = new FileInputStream(file);
+ aprop.load(
new BufferedReader(
- new InputStreamReader(iFile, "UTF-8")
- )
- );
+ new InputStreamReader(diFile, "UTF-8")
+ )
+ );
}
catch (IOException t) {
- try {
- iFile = ExWSConf.class.getClassLoader()
- .getResourceAsStream(propFile);
+ try {
+ diFile = ExWSConf.class.getClassLoader()
+ .getResourceAsStream(file);
- if (iFile == null) {
- Logger.error("Unable to load properties.");
- return null;
- };
-
- prop = new Properties();
- prop.load(iFile);
- iFile.close();
- }
- catch (IOException e) {
- Logger.error(e);
+ if (diFile == null) {
+ Logger.error("Unable to load properties.");
return null;
};
+
+ aprop.load(diFile);
+ diFile.close();
+ }
+ catch (IOException e) {
+ Logger.error(e);
+ return null;
};
+ }
+ return aprop;
+ }
+
+ /*
+ * Returns export properties
+ * The properties in exportPlugin.conf are the default properties
+ * which can be overwritten by the properties in propFile.
+ */
+ public static Properties properties (String propFile) {
+
+ if (prop != null)
+ return prop;
+
+ Properties defaultProp = loadProp(null, "exportPlugin.conf");
+ prop = new Properties(defaultProp);
+
+ if (propFile != null){
+ loadProp(prop, propFile);
+ }
+
return prop;
};
+
}
diff --git a/src/test/java/de/ids_mannheim/korap/plkexport/ExWSConfTest.java b/src/test/java/de/ids_mannheim/korap/plkexport/ExWSConfTest.java
new file mode 100644
index 0000000..fb4a210
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/plkexport/ExWSConfTest.java
@@ -0,0 +1,40 @@
+package de.ids_mannheim.korap.plkexport;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Properties;
+
+import org.junit.Test;
+
+import de.ids_mannheim.korap.plkexport.ExWSConf;
+
+public class ExWSConfTest {
+
+ /**
+ * Test the return of properties.
+ * If no property file is passed, the default properties
+ * should be loaded. If there is a property file, the properties in
+ * this file should additionall be loaded. Default properties should be
+ * overwritten if they exist in both file.
+ */
+ @Test
+ public void testExportWsOverlProp () {
+ // No property file
+ ExWSConf.clearProp();
+ Properties properties = ExWSConf.properties(null);
+ assertEquals("localhost", (properties.getProperty("server.host")));
+ assertEquals("1024", (properties.getProperty("server.port")));
+ assertEquals("dummdidumm.ids-mannheim.de", properties.getProperty("asset.host"));
+ assertEquals("5", properties.getProperty("conf.page_size"));
+ //Property file
+ ExWSConf.clearProp();
+ Properties propsec = ExWSConf.properties("exportPluginSec.conf");
+ assertEquals("localhost", (propsec.getProperty("server.host")));
+ assertEquals("1024", (propsec.getProperty("server.port")));
+ assertEquals("korap.ids-mannheim.de", propsec.getProperty("api.host"));
+ assertEquals("55", propsec.getProperty("conf.page_size"));
+ assertEquals("ajlakjldkjf", propsec.getProperty("rtf.trail"));
+ }
+
+}
+
diff --git a/src/test/resources/exportPlugin.conf b/src/test/resources/exportPlugin.conf
new file mode 100644
index 0000000..2171cbd
--- /dev/null
+++ b/src/test/resources/exportPlugin.conf
@@ -0,0 +1,46 @@
+# Export configuration file for testing purposes
+# Needs to be converted using
+# $ native2ascii -encoding UTF-8 \
+# exportPlugin.conf exportPlugin.conf
+
+# Server Configuration
+server.port=1024
+server.host=localhost
+server.scheme=https
+
+# API Configuration
+api.port=443
+api.host=korap.ids-mannheim.de
+api.scheme=https
+
+# Overwrite to set source to a string,
+# especially useful when run behind a proxy.
+# api.source = korap.ids-mannheim.de
+
+# Asset Configuration
+asset.host=dummdidumm.ids-mannheim.de
+asset.scheme=https
+
+# Default configuration
+conf.page_size=5
+
+# Maximum hits to be exported
+# TODO:
+# Maybe we need a distinction between
+# users at the IDS and external users
+# See also:
+# https://www.ids-mannheim.de/cosmas2/script-app/hilfe/sitzung.html
+conf.max_exp_limit=10000
+
+# The file directory to serve from
+# conf.file_dir=./files/
+# Defaults to the system's temp directory
+
+conf.default_hitc = 100
+
+#####################
+# RTF configuration #
+#####################
+
+rtf.footnote = @ Leibniz-Institut f\u00fcr Deutsche Sprache, Mannheim
+rtf.trail = ajlakjldkjf
\ No newline at end of file
diff --git a/src/test/resources/exportPluginSec.conf b/src/test/resources/exportPluginSec.conf
new file mode 100644
index 0000000..abaed38
--- /dev/null
+++ b/src/test/resources/exportPluginSec.conf
@@ -0,0 +1,14 @@
+# Additional export configuration file for testing purposes
+
+# Needs to be converted using
+# $ native2ascii -encoding UTF-8 \
+# exportPlugin.conf exportPlugin.conf
+
+
+# API Configuration
+api.host=korap.ids-mannheim.de
+
+# Default configuration
+conf.page_size=55
+
+new.prop = new