2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.httpinvoker
;
12 import java
.io
.FileInputStream
;
13 import java
.io
.InputStream
;
15 import java
.util
.Properties
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.eclipse
.core
.runtime
.FileLocator
;
19 import org
.eclipse
.core
.runtime
.Platform
;
20 import org
.junit
.BeforeClass
;
21 import org
.osgi
.framework
.Bundle
;
22 import org
.unitils
.UnitilsJUnit4
;
29 public abstract class TestConfig
extends UnitilsJUnit4
{
31 private static final Logger logger
= Logger
.getLogger(TestConfig
.class);
33 private final static String DEFAULT_USER
= "admin";
34 private final static String DEFAULT_PASSWORD
= "00000";
35 private final static int DEFAULT_HTTP_PORT
= 9090;
36 private final static String DEFAULT_CONTEXT_PATH
= "";
37 private final static String DEFAULT_SOURCE_NAME
= "default";
38 private final static String DEFAULT_HOST
= "localhost";
40 private static String userHomeKey
= "user.home";
42 protected static String user
= DEFAULT_USER
;
43 protected static String password
= DEFAULT_PASSWORD
;
44 protected static int httpPort
= DEFAULT_HTTP_PORT
;
45 protected static String contextPath
= DEFAULT_CONTEXT_PATH
;
46 protected static String sourceName
= DEFAULT_SOURCE_NAME
;
47 protected static String host
= DEFAULT_HOST
;
50 public static void initializeTestConfig() {
52 String userHomeDirPath
;
53 Bundle bundle
= Platform
.getBundle("eu.etaxonomy.taxeditor.test");
55 URL userHomeDirURL
= bundle
.getEntry("src/test/resources");
56 File userHomeDir
= new File(FileLocator
.resolve(userHomeDirURL
).toURI());
57 userHomeDirPath
= userHomeDir
.getAbsolutePath();
59 URL serverPropertiesURL
= bundle
.getEntry("src/test/resources/server.properties");
60 File serverPropertiesFile
= new File(FileLocator
.resolve(serverPropertiesURL
).toURI());
61 InputStream inputStream
= new FileInputStream(serverPropertiesFile
);
63 Properties prop
= new Properties();
65 prop
.load(inputStream
);
69 logger
.warn("Setting user.home to " + userHomeDirPath
);
70 System
.setProperty(userHomeKey
, userHomeDirPath
);
73 if(prop
.getProperty("user") != null) {
74 user
= prop
.getProperty("user");
77 if(prop
.getProperty("password") != null) {
78 password
= prop
.getProperty("password");
81 if(prop
.getProperty("httpPort") != null) {
82 httpPort
= Integer
.valueOf(prop
.getProperty("httpPort"));
85 if(prop
.getProperty("contextPath") != null) {
86 contextPath
= prop
.getProperty("contextPath");
89 } catch (Exception e
) {
91 // Assert.fail("Server failed to start. Reason : " + e.getMessage());