Project

General

Profile

Download (3.16 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.taxeditor.httpinvoker;
11

    
12
import java.io.File;
13
import java.io.FileInputStream;
14
import java.io.InputStream;
15
import java.net.URL;
16
import java.util.Properties;
17

    
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;
24

    
25
/**
26
 * @author cmathew
27
 * @date 11 Nov 2015
28
 *
29
 */
30
public abstract class TestConfig extends UnitilsJUnit4 {
31

    
32
    private static final Logger logger = Logger.getLogger(TestConfig.class);
33

    
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";
40

    
41
    private static String userHomeKey = "user.home";
42

    
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;
49

    
50
    @BeforeClass
51
    public static void initializeTestConfig() {
52
        try {
53
            String userHomeDirPath;
54
            Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.test");
55

    
56
            URL userHomeDirURL = bundle.getEntry("src/test/resources");
57
            File userHomeDir = new File(FileLocator.resolve(userHomeDirURL).toURI());
58
            userHomeDirPath = userHomeDir.getAbsolutePath();
59

    
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);
63

    
64
            Properties prop = new Properties();
65

    
66
            prop.load(inputStream);
67
            inputStream.close();
68

    
69

    
70
            logger.warn("Setting user.home to " + userHomeDirPath);
71
            System.setProperty(userHomeKey, userHomeDirPath);
72

    
73

    
74
            if(prop.getProperty("user") != null) {
75
                user = prop.getProperty("user");
76
            }
77

    
78
            if(prop.getProperty("password") != null) {
79
                password = prop.getProperty("password");
80
            }
81

    
82
            if(prop.getProperty("httpPort") != null) {
83
                httpPort = Integer.valueOf(prop.getProperty("httpPort"));
84
            }
85

    
86
            if(prop.getProperty("contextPath") != null) {
87
                contextPath = prop.getProperty("contextPath");
88
            }
89

    
90
        } catch (Exception e) {
91
            e.printStackTrace();
92
            // Assert.fail("Server failed to start. Reason : " + e.getMessage());
93
        }
94
    }
95

    
96
}
(6-6/8)