3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.httpinvoker
;
13 import java
.io
.FileInputStream
;
14 import java
.io
.InputStream
;
16 import java
.util
.Properties
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.eclipse
.core
.runtime
.FileLocator
;
20 import org
.eclipse
.core
.runtime
.Platform
;
21 import org
.junit
.BeforeClass
;
22 import org
.osgi
.framework
.Bundle
;
23 import org
.unitils
.UnitilsJUnit4
;
30 public abstract class TestConfig
extends UnitilsJUnit4
{
32 private static final Logger logger
= Logger
.getLogger(TestConfig
.class);
34 private final static String DEFAULT_USER
= "admin";
35 private final static String DEFAULT_PASSWORD
= "00000";
36 private final static int DEFAULT_HTTP_PORT
= 9090;
37 private final static String DEFAULT_CONTEXT_PATH
= "";
38 private final static String DEFAULT_SOURCE_NAME
= "default";
39 private final static String DEFAULT_HOST
= "localhost";
41 private static String userHomeKey
= "user.home";
43 protected static String user
= DEFAULT_USER
;
44 protected static String password
= DEFAULT_PASSWORD
;
45 protected static int httpPort
= DEFAULT_HTTP_PORT
;
46 protected static String contextPath
= DEFAULT_CONTEXT_PATH
;
47 protected static String sourceName
= DEFAULT_SOURCE_NAME
;
48 protected static String host
= DEFAULT_HOST
;
51 public static void initializeTestConfig() {
53 String userHomeDirPath
;
54 Bundle bundle
= Platform
.getBundle("eu.etaxonomy.taxeditor.test");
56 URL userHomeDirURL
= bundle
.getEntry("src/test/resources");
57 File userHomeDir
= new File(FileLocator
.resolve(userHomeDirURL
).toURI());
58 userHomeDirPath
= userHomeDir
.getAbsolutePath();
60 URL serverPropertiesURL
= bundle
.getEntry("src/test/resources/server.properties");
61 File serverPropertiesFile
= new File(FileLocator
.resolve(serverPropertiesURL
).toURI());
62 InputStream inputStream
= new FileInputStream(serverPropertiesFile
);
64 Properties prop
= new Properties();
66 prop
.load(inputStream
);
70 logger
.warn("Setting user.home to " + userHomeDirPath
);
71 System
.setProperty(userHomeKey
, userHomeDirPath
);
74 if(prop
.getProperty("user") != null) {
75 user
= prop
.getProperty("user");
78 if(prop
.getProperty("password") != null) {
79 password
= prop
.getProperty("password");
82 if(prop
.getProperty("httpPort") != null) {
83 httpPort
= Integer
.valueOf(prop
.getProperty("httpPort"));
86 if(prop
.getProperty("contextPath") != null) {
87 contextPath
= prop
.getProperty("contextPath");
90 } catch (Exception e
) {
92 // Assert.fail("Server failed to start. Reason : " + e.getMessage());