8 |
8 |
*/
|
9 |
9 |
package eu.etaxonomy.taxeditor.httpinvoker;
|
10 |
10 |
|
|
11 |
import java.io.File;
|
11 |
12 |
import java.io.InputStream;
|
12 |
13 |
import java.lang.reflect.Field;
|
|
14 |
import java.net.URL;
|
13 |
15 |
import java.util.Map;
|
14 |
16 |
import java.util.Properties;
|
15 |
17 |
|
16 |
18 |
import org.apache.log4j.Logger;
|
|
19 |
import org.eclipse.core.runtime.FileLocator;
|
|
20 |
import org.eclipse.core.runtime.Platform;
|
17 |
21 |
import org.junit.AfterClass;
|
18 |
22 |
import org.junit.Assert;
|
19 |
23 |
import org.junit.BeforeClass;
|
20 |
24 |
import org.junit.Test;
|
|
25 |
import org.osgi.framework.Bundle;
|
21 |
26 |
import org.springframework.core.io.ClassPathResource;
|
22 |
27 |
import org.springframework.core.io.Resource;
|
23 |
28 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
... | ... | |
58 |
63 |
public static final Resource SERVER_PROPERTIES_FILE =
|
59 |
64 |
new ClassPathResource("server.properties");
|
60 |
65 |
|
|
66 |
public static final Resource EDITOR_DATASOURCES_FILE =
|
|
67 |
new ClassPathResource(".cdmLibrary/writableResources/cdm.datasources.xml");
|
|
68 |
|
61 |
69 |
private static CdmApplicationRemoteController remoteApplicationController;
|
62 |
70 |
private static ICdmRemoteSource cdmRemoteSource;
|
63 |
71 |
private static CdmPersistentRemoteSource remotePersistentSource;
|
... | ... | |
70 |
78 |
private final static String DEFAULT_USER = "admin";
|
71 |
79 |
private final static String DEFAULT_PASSWORD = "00000";
|
72 |
80 |
|
|
81 |
private static String userHomeKey = "user.home";
|
|
82 |
|
73 |
83 |
private static String user = DEFAULT_USER;
|
74 |
84 |
private static String password = DEFAULT_PASSWORD;
|
75 |
85 |
|
76 |
86 |
@BeforeClass
|
77 |
87 |
public static void initializeBaseRemotingTest() {
|
|
88 |
|
78 |
89 |
//NOTE: Run this the cdmTest H2 DB whenever it needs to be
|
79 |
|
// recreated e.g. after a model change
|
80 |
|
DatabaseUnitils.disableConstraints();
|
|
90 |
// recreated e.g. after a model change
|
|
91 |
DatabaseUnitils.disableConstraints();
|
81 |
92 |
|
|
93 |
try {
|
|
94 |
String userHomeDirPath;
|
|
95 |
Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.test");
|
|
96 |
// if bundle is null then we are running as junit test in eclipse
|
|
97 |
if(bundle == null) {
|
|
98 |
userHomeDirPath = EDITOR_DATASOURCES_FILE.getFile().getParentFile().getParentFile().getParent();
|
|
99 |
} else {
|
|
100 |
// ... else we are running in maven which requires loading the dir via the
|
|
101 |
// classpath bundle
|
|
102 |
URL userHomeDirURL = bundle.getEntry("src/test/resources");
|
|
103 |
File userHomeDir = new File(FileLocator.resolve(userHomeDirURL).toURI());
|
|
104 |
userHomeDirPath = userHomeDir.getAbsolutePath();
|
|
105 |
}
|
82 |
106 |
|
83 |
|
useManagedServer = (System.getProperty("use.managed.server") == null) ? useManagedServer : Boolean.valueOf(System.getProperty("use.managed.server"));
|
84 |
|
if(useManagedServer) {
|
85 |
|
try {
|
86 |
|
CDMServer cdmServer = CDMServer.getInstance();
|
87 |
|
Properties prop = new Properties();
|
88 |
|
InputStream inputStream = SERVER_PROPERTIES_FILE.getInputStream();
|
89 |
107 |
|
90 |
|
if (inputStream != null) {
|
91 |
|
prop.load(inputStream);
|
92 |
|
}
|
|
108 |
logger.info("Setting user.home to " + userHomeDirPath);
|
|
109 |
System.setProperty(userHomeKey, userHomeDirPath);
|
93 |
110 |
|
94 |
|
if(prop.getProperty("httpPort") != null) {
|
95 |
|
cdmServer.setHttpPort(Integer.valueOf(prop.getProperty("httpPort")));
|
96 |
|
}
|
|
111 |
CDMServer cdmServer = CDMServer.getInstance();
|
97 |
112 |
|
98 |
|
if(prop.getProperty("stopPort") != null) {
|
99 |
|
cdmServer.setStopPort(Integer.valueOf(prop.getProperty("stopPort")));
|
100 |
|
}
|
101 |
113 |
|
102 |
|
if(prop.getProperty("stopKey") != null) {
|
103 |
|
cdmServer.setStopKey(prop.getProperty("stopKey"));
|
104 |
|
}
|
|
114 |
Properties prop = new Properties();
|
|
115 |
InputStream inputStream = SERVER_PROPERTIES_FILE.getInputStream();
|
105 |
116 |
|
106 |
|
if(prop.getProperty("user") != null) {
|
107 |
|
user = prop.getProperty("user");
|
108 |
|
}
|
|
117 |
if (inputStream != null) {
|
|
118 |
prop.load(inputStream);
|
|
119 |
inputStream.close();
|
|
120 |
}
|
109 |
121 |
|
110 |
|
if(prop.getProperty("password") != null) {
|
111 |
|
password = prop.getProperty("password");
|
112 |
|
}
|
|
122 |
if(prop.getProperty("httpPort") != null) {
|
|
123 |
cdmServer.setHttpPort(Integer.valueOf(prop.getProperty("httpPort")));
|
|
124 |
}
|
113 |
125 |
|
114 |
|
cdmServer.start();
|
115 |
|
} catch (Exception e) {
|
116 |
|
e.printStackTrace();
|
117 |
|
Assert.fail("Server failed to start. Reason : " + e.getMessage());
|
|
126 |
if(prop.getProperty("stopPort") != null) {
|
|
127 |
cdmServer.setStopPort(Integer.valueOf(prop.getProperty("stopPort")));
|
118 |
128 |
}
|
119 |
129 |
|
120 |
|
initializeController(CDMServer.getInstance().getName(),
|
121 |
|
CDMServer.getInstance().getHost(),
|
122 |
|
CDMServer.getInstance().getPort(),
|
123 |
|
CDMServer.getInstance().getContextPath(),
|
124 |
|
NomenclaturalCode.ICNAFP,
|
125 |
|
user,
|
126 |
|
password);
|
127 |
|
}
|
|
130 |
if(prop.getProperty("stopKey") != null) {
|
|
131 |
cdmServer.setStopKey(prop.getProperty("stopKey"));
|
|
132 |
}
|
|
133 |
|
|
134 |
if(prop.getProperty("user") != null) {
|
|
135 |
user = prop.getProperty("user");
|
|
136 |
}
|
128 |
137 |
|
|
138 |
if(prop.getProperty("password") != null) {
|
|
139 |
password = prop.getProperty("password");
|
|
140 |
}
|
129 |
141 |
|
|
142 |
cdmServer.start();
|
|
143 |
initializeController(CDMServer.getInstance().getName(),
|
|
144 |
CDMServer.getInstance().getHost(),
|
|
145 |
CDMServer.getInstance().getPort(),
|
|
146 |
CDMServer.getInstance().getContextPath(),
|
|
147 |
NomenclaturalCode.ICNAFP,
|
|
148 |
user,
|
|
149 |
password);
|
|
150 |
} catch (Exception e) {
|
|
151 |
e.printStackTrace();
|
|
152 |
// Assert.fail("Server failed to start. Reason : " + e.getMessage());
|
|
153 |
}
|
130 |
154 |
}
|
131 |
155 |
|
132 |
156 |
|
133 |
157 |
@Test
|
134 |
158 |
public void disableConstraints() {
|
135 |
|
// To be run on the src/test/resources/h2/cdmTest h2 db after
|
136 |
|
// updating the unitils.properties 'database.url' property
|
137 |
|
DatabaseUnitils.disableConstraints();
|
|
159 |
// To be run on the src/test/resources/h2/cdmTest h2 db after
|
|
160 |
// updating the unitils.properties 'database.url' property
|
|
161 |
DatabaseUnitils.disableConstraints();
|
138 |
162 |
}
|
139 |
163 |
|
140 |
164 |
|
... | ... | |
181 |
205 |
}
|
182 |
206 |
|
183 |
207 |
protected static ICdmEntitySessionManager getCdmEntitySessionManager() {
|
184 |
|
return cdmEntitySessionManager;
|
|
208 |
return cdmEntitySessionManager;
|
185 |
209 |
}
|
186 |
210 |
|
187 |
211 |
|
188 |
212 |
protected static CdmEntitySession getSession(ICdmEntitySessionEnabled sessionOwner) {
|
189 |
|
Map<ICdmEntitySessionEnabled, CdmEntitySession> ownerSessionMap =
|
190 |
|
(Map<ICdmEntitySessionEnabled, CdmEntitySession>) getFieldValueViaReflection(cdmEntitySessionManager, "ownerSessionMap");
|
191 |
|
return ownerSessionMap.get(sessionOwner);
|
|
213 |
Map<ICdmEntitySessionEnabled, CdmEntitySession> ownerSessionMap =
|
|
214 |
(Map<ICdmEntitySessionEnabled, CdmEntitySession>) getFieldValueViaReflection(cdmEntitySessionManager, "ownerSessionMap");
|
|
215 |
return ownerSessionMap.get(sessionOwner);
|
192 |
216 |
}
|
193 |
217 |
|
194 |
218 |
protected static CdmTransientEntityCacher getActiveSession() {
|
195 |
|
return (CdmTransientEntityCacher) getFieldValueViaReflection(cdmEntitySessionManager, "activeSession");
|
|
219 |
return (CdmTransientEntityCacher) getFieldValueViaReflection(cdmEntitySessionManager, "activeSession");
|
196 |
220 |
}
|
197 |
221 |
|
198 |
222 |
protected static CdmTransientEntityCacher getCacher(ICdmEntitySessionEnabled sessionOwner) {
|
199 |
|
return (CdmTransientEntityCacher) getFieldValueViaReflection(getSession(sessionOwner), "cdmTransientEntityCacher");
|
|
223 |
return (CdmTransientEntityCacher) getFieldValueViaReflection(getSession(sessionOwner), "cdmTransientEntityCacher");
|
200 |
224 |
}
|
201 |
225 |
|
202 |
226 |
@AfterClass
|
fixed issues with resource loading for maven int tests