27
27
import java .util .Collection ;
28
28
import java .util .List ;
29
29
import java .util .Properties ;
30
-
31
30
import org .apache .commons .io .FileUtils ;
32
31
import org .jdom .Document ;
33
32
import org .jdom .Element ;
40
39
import org .junit .Before ;
41
40
import org .junit .BeforeClass ;
42
41
import org .junit .Test ;
43
-
44
42
import org .silverpeas .applicationbuilder .XmlDocument ;
45
43
import org .silverpeas .file .GestionVariables ;
44
+ import org .silverpeas .test .SystemInitializationForTests ;
46
45
47
46
import static java .io .File .separatorChar ;
47
+
48
48
import static org .silverpeas .SilverpeasSettings .SilverpeasSettings .*;
49
49
50
50
/**
53
53
*/
54
54
public class SilverpeasSettingsTest {
55
55
56
- private static final String resourcesDir = System .getProperty ("basedir" ) + separatorChar +
57
- "target" + separatorChar + "test-classes" + separatorChar ;
56
+ private static final String OPERATING_SYSTEM = System .getProperty ("os.name" ).toLowerCase ();
57
+ private static final String SILVERPEAS_HOME = "silverpeas.home" ;
58
+ private static String resourcesDir ;
58
59
59
60
public SilverpeasSettingsTest () {
60
61
}
61
62
62
63
@ BeforeClass
63
64
public static void setUpClass () throws Exception {
64
- System .setProperty ("silverpeas.home" , resourcesDir );
65
- System .setProperty ("SILVERPEAS_HOME" , resourcesDir );
66
- System .setProperty ("JBOSS_HOME" , resourcesDir );
65
+ SystemInitializationForTests .initialize ();
66
+ resourcesDir = System .getProperty (SILVERPEAS_HOME );
67
67
}
68
68
69
69
@ AfterClass
@@ -87,11 +87,11 @@ public void tearDown() {
87
87
public void testLoadGlobalVariables () throws Exception {
88
88
SAXBuilder builder = new SAXBuilder ();
89
89
Document doc = builder .build (new File (
90
- resourcesDir + "expected" + separatorChar + "MergedSettings.xml" ));
90
+ resourcesDir + File . separatorChar + "expected" + separatorChar + "MergedSettings.xml" ));
91
91
// Get the root element
92
92
Element root = doc .getRootElement ();
93
93
GestionVariables gv = SilverpeasSettings .loadGlobalVariables (new File (
94
- resourcesDir + "expected" ), root );
94
+ resourcesDir + File . separatorChar + "expected" ), root );
95
95
Assert .assertEquals ("test@silverpeas.com" , gv .getValue ("ADMIN_EMAIL" ));
96
96
Assert .assertEquals ("http://www.silverpeas.com" , gv .getValue ("URL_SERVER" ));
97
97
Assert .assertEquals ("5432" , gv .getValue ("SQL_LISTEN_PORT_POSTGRES" ));
@@ -100,7 +100,7 @@ public void testLoadGlobalVariables() throws Exception {
100
100
101
101
@ Test
102
102
public void testLoadConfiguration () throws Exception {
103
- File dir = new File (resourcesDir + "xml" );
103
+ File dir = new File (resourcesDir + File . separatorChar + "xml" );
104
104
GestionVariables properties = SilverpeasSettings .loadConfiguration (dir );
105
105
Assert .assertEquals ("c:/toto" , properties .getValue ("SILVERPEAS_HOME" ));
106
106
Assert .assertEquals ("http://localhost:8000" , properties .getValue ("URL_SERVER" ));
@@ -115,15 +115,15 @@ public void testLoadConfiguration() throws Exception {
115
115
*/
116
116
@ Test
117
117
public void testMergeConfigurationFiles () throws Exception {
118
- File dirXml = new File (resourcesDir + "xml" );
118
+ File dirXml = new File (resourcesDir + File . separatorChar + "xml" );
119
119
XmlDocument fileXml = new XmlDocument (dirXml , SilverpeasSettings .SILVERPEAS_SETTINGS );
120
120
fileXml .load ();
121
121
SilverpeasSettings .mergeConfigurationFiles (fileXml , dirXml );
122
122
fileXml .setOutputEncoding ("UTF-8" );
123
123
XMLOutputter output = new XMLOutputter (Format .getPrettyFormat ());
124
124
125
- File tempDir = new File (System .getProperty ("basedir" ) + separatorChar + "target" +
126
- separatorChar + "temp" );
125
+ File tempDir = new File (System .getProperty ("basedir" ) + separatorChar + "target" + separatorChar
126
+ + "temp" );
127
127
tempDir .mkdirs ();
128
128
File mergedFile = new File (tempDir , "merge_result.xml" );
129
129
OutputStream out = new FileOutputStream (mergedFile );
@@ -132,8 +132,8 @@ public void testMergeConfigurationFiles() throws Exception {
132
132
@ SuppressWarnings ("unchecked" )
133
133
List <String > resultLines = FileUtils .readLines (mergedFile , "UTF-8" );
134
134
@ SuppressWarnings ("unchecked" )
135
- List <String > expectedtLines = FileUtils .readLines (new File (resourcesDir + "expected" +
136
- separatorChar + "MergedSettings.xml" ), "UTF-8" );
135
+ List <String > expectedtLines = FileUtils .readLines (new File (resourcesDir + File . separatorChar
136
+ + "expected" + separatorChar + "MergedSettings.xml" ), "UTF-8" );
137
137
Assert .assertNotNull (resultLines );
138
138
Assert .assertEquals (expectedtLines .size (), resultLines .size ());
139
139
for (int i = 0 ; i < resultLines .size (); i ++) {
@@ -145,9 +145,9 @@ public void testMergeConfigurationFiles() throws Exception {
145
145
public void xmlFileTransformation () throws Exception {
146
146
GestionVariables gestion = new GestionVariables (new Properties ());
147
147
gestion .addVariable ("JBOSS_LISTEN_PORT" , "9500" );
148
- gestion .addVariable ("SILVERPEAS_DATA_HOME_DEPENDANT" , resourcesDir + "data" );
149
- gestion .addVariable ("SILVERPEAS_HOME_DEPENDANT" , resourcesDir + "toto" );
150
- String dir = resourcesDir + "transform" + separatorChar ;
148
+ gestion .addVariable ("SILVERPEAS_DATA_HOME_DEPENDANT" , resourcesDir + "/ data" );
149
+ gestion .addVariable ("SILVERPEAS_HOME_DEPENDANT" , resourcesDir + "/ toto" );
150
+ String dir = resourcesDir + File . separatorChar + "transform" + separatorChar ;
151
151
Element element = new Element (XML_FILE_TAG );
152
152
element .setAttribute (FILE_NAME_ATTRIB , "jbossweb-tomcat55.sar/server.xml" );
153
153
Collection <Element > values = new ArrayList <Element >(2 );
@@ -159,29 +159,32 @@ public void xmlFileTransformation() throws Exception {
159
159
values = new ArrayList <Element >(2 );
160
160
values .add (getValueElement ("@docBase" , "${SILVERPEAS_DATA_HOME_DEPENDANT}/data/weblib" ));
161
161
values .add (getValueElement ("@path" , "/weblib" ));
162
- element .addContent (getParameterElement ("/Server/Service[@name='jboss.web']/Engine[@name='jboss.web']/" +
163
- "Host[@name='localhost']/Context[@path='/weblib']" , "update" , values ));
162
+ element .
163
+ addContent (getParameterElement ("/Server/Service[@name='jboss.web']/Engine[@name='jboss.web']/"
164
+ + "Host[@name='localhost']/Context[@path='/weblib']" , "update" , values ));
164
165
values = new ArrayList <Element >(2 );
165
166
values .add (getValueElement ("@docBase" , "${SILVERPEAS_DATA_HOME_DEPENDANT}/data/website" ));
166
167
values .add (getValueElement ("@path" , "/website" ));
167
- element .addContent (getParameterElement ("//Service[@name='jboss.web']/Engine[@name='jboss.web']" +
168
- "/Host[@name='localhost']/Context[@path='/website']" , "update" , values ));
168
+ element .addContent (getParameterElement ("//Service[@name='jboss.web']/Engine[@name='jboss.web']"
169
+ + "/Host[@name='localhost']/Context[@path='/website']" , "update" , values ));
169
170
values = new ArrayList <Element >(2 );
170
171
values .add (getValueElement ("@docBase" , "${SILVERPEAS_HOME_DEPENDANT}/help/fr" ));
171
172
values .add (getValueElement ("@path" , "/help_fr" ));
172
- element .addContent (getParameterElement ("/Server/Service[@name='jboss.web']/Engine[@name='jboss.web']/" +
173
- "Host[@name='localhost']/Context[@path='/help_fr']" , "update" , values ));
173
+ element .
174
+ addContent (getParameterElement ("/Server/Service[@name='jboss.web']/Engine[@name='jboss.web']/"
175
+ + "Host[@name='localhost']/Context[@path='/help_fr']" , "update" , values ));
174
176
xmlfile (dir , element , gestion );
175
177
@ SuppressWarnings ("unchecked" )
176
- List <String > resultLines = FileUtils .readLines (new File (resourcesDir + "transform" +
177
- separatorChar + "jbossweb-tomcat55.sar" + separatorChar + "server.xml" ), "UTF-8" );
178
+ List <String > resultLines = FileUtils .readLines (new File (resourcesDir + File .separatorChar
179
+ + "transform" + separatorChar + "jbossweb-tomcat55.sar" + separatorChar + "server.xml" ),
180
+ "UTF-8" );
178
181
@ SuppressWarnings ("unchecked" )
179
- List <String > expectedtLines = FileUtils .readLines (new File (resourcesDir + "expected_transform" +
180
- separatorChar + "server.xml" ), "UTF-8" );
182
+ List <String > expectedtLines = FileUtils .readLines (new File (resourcesDir + File . separatorChar
183
+ + "expected_transform" + separatorChar + "server.xml" ), "UTF-8" );
181
184
Assert .assertNotNull (resultLines );
182
185
Assert .assertEquals (expectedtLines .size (), resultLines .size ());
183
186
for (int i = 0 ; i < resultLines .size (); i ++) {
184
- Assert .assertEquals (expectedtLines .get (i ), resultLines .get (i ));
187
+ Assert .assertEquals (replaceInvalidWindowsChars ( expectedtLines .get (i ) ), resultLines .get (i ));
185
188
}
186
189
}
187
190
@@ -199,4 +202,13 @@ protected Element getParameterElement(String key, String mode, Collection<Elemen
199
202
element .setContent (values );
200
203
return element ;
201
204
}
205
+
206
+ protected String replaceInvalidWindowsChars (String path ) {
207
+ String fixedPath = path ;
208
+ if (OPERATING_SYSTEM .contains ("win" ) && path .contains ("\\ " )) {
209
+ // we are in windows and in some version of this os ${basedir} add two \ after the drive label
210
+ fixedPath = path .replace ("\\ \\ " , "\\ " );
211
+ }
212
+ return fixedPath ;
213
+ }
202
214
}
0 commit comments