c466672e2262a9bc0e649f599422100d6d1d774c
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / httpinvoker / TestConfig.java
1 /**
2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.httpinvoker;
10
11 import java.io.File;
12 import java.io.FileInputStream;
13 import java.io.InputStream;
14 import java.net.URL;
15 import java.util.Properties;
16
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;
23
24 /**
25 * @author cmathew
26 * @date 11 Nov 2015
27 *
28 */
29 public abstract class TestConfig extends UnitilsJUnit4 {
30
31 private static final Logger logger = Logger.getLogger(TestConfig.class);
32
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";
39
40 private static String userHomeKey = "user.home";
41
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;
48
49 @BeforeClass
50 public static void initializeTestConfig() {
51 try {
52 String userHomeDirPath;
53 Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.test");
54
55 URL userHomeDirURL = bundle.getEntry("src/test/resources");
56 File userHomeDir = new File(FileLocator.resolve(userHomeDirURL).toURI());
57 userHomeDirPath = userHomeDir.getAbsolutePath();
58
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);
62
63 Properties prop = new Properties();
64
65 prop.load(inputStream);
66 inputStream.close();
67
68
69 logger.warn("Setting user.home to " + userHomeDirPath);
70 System.setProperty(userHomeKey, userHomeDirPath);
71
72
73 if(prop.getProperty("user") != null) {
74 user = prop.getProperty("user");
75 }
76
77 if(prop.getProperty("password") != null) {
78 password = prop.getProperty("password");
79 }
80
81 if(prop.getProperty("httpPort") != null) {
82 httpPort = Integer.valueOf(prop.getProperty("httpPort"));
83 }
84
85 if(prop.getProperty("contextPath") != null) {
86 contextPath = prop.getProperty("contextPath");
87 }
88
89 } catch (Exception e) {
90 e.printStackTrace();
91 // Assert.fail("Server failed to start. Reason : " + e.getMessage());
92 }
93 }
94
95 }