2020
2121import java .io .File ;
2222import org .junit .Before ;
23+ import org .junit .Rule ;
2324import org .junit .Test ;
25+ import org .junit .rules .TemporaryFolder ;
2426import org .junit .runner .RunWith ;
2527import org .junit .runners .JUnit4 ;
2628
2729@ RunWith (JUnit4 .class )
2830public final class ClassPathUtilsTest {
2931 private static final String PATH_SEPARATOR = System .getProperty ("path.separator" );
32+ private String runtimeLocation = null ;
33+ @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ();
3034
3135 @ Before
32- public void setUp () {
36+ public void setUp () throws Exception {
3337 System .clearProperty ("use.jetty93" );
3438 System .clearProperty ("use.jetty94" );
3539 System .clearProperty ("use.java11" );
3640 System .clearProperty ("classpath.runtime-impl" );
3741 System .clearProperty ("use.mavenjars" );
3842 System .clearProperty ("classpath.appengine-api-legacy" );
43+ System .clearProperty ("classpath.connector-j" );
44+ runtimeLocation = temporaryFolder .getRoot ().getAbsolutePath ();
45+ System .setProperty ("classpath.runtimebase" , runtimeLocation );
46+ }
3947
40- System .setProperty ("classpath.runtimebase" , "/tmp" );
48+ private void createJava8Environment () throws Exception {
49+ // Only Java8 runtime has the native launcher. This file is used to determine which env
50+ // must be used.
51+ temporaryFolder .newFile ("java_runtime_launcher" );
4152 }
4253
4354 @ Test
4455 public void verifyDefaultPropertiesAreConfigured () throws Exception {
56+ createJava8Environment ();
4557 ClassPathUtils cpu = new ClassPathUtils ();
4658 assertThat (cpu .getConnectorJUrls ()).hasLength (1 );
4759 assertThat (System .getProperty ("classpath.runtime-impl" ))
4860 .isEqualTo (
49- "/tmp/runtime-impl.jar"
61+ runtimeLocation
62+ + "/runtime-impl.jar"
5063 + PATH_SEPARATOR
51- + "/tmp/frozen_debugger.jar"
64+ + runtimeLocation
65+ + "/frozen_debugger.jar"
5266 + PATH_SEPARATOR
53- + "/tmp/runtime-impl-third-party.jar"
67+ + runtimeLocation
68+ + "/runtime-impl-third-party.jar"
5469 + PATH_SEPARATOR
55- + "/tmp/runtime-appengine-api.jar" );
70+ + runtimeLocation
71+ + "/runtime-appengine-api.jar" );
5672
57- assertThat (System .getProperty ("classpath.runtime-shared" )).isEqualTo ("/tmp/runtime-shared.jar" );
73+ assertThat (System .getProperty ("classpath.runtime-shared" ))
74+ .isEqualTo (runtimeLocation + "/runtime-shared.jar" );
5875 assertThat (System .getProperty ("classpath.connector-j" ))
59- .isEqualTo ("/tmp/jdbc-mysql-connector.jar" );
60- assertThat (System .getProperty ("classpath.api-map" )).isEqualTo ("1.0=/tmp/appengine-api.jar" );
76+ .isEqualTo (runtimeLocation + "/jdbc-mysql-connector.jar" );
77+
78+ assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
79+ .isEqualTo (runtimeLocation + "/appengine-api.jar" );
6180 }
6281
6382 @ Test
6483 public void verifyJava11PropertiesAreConfigured () throws Exception {
65- System . setProperty ( "use.java11" , "true" );
84+ // we do not call createJava8Environment() so expect java11+
6685 ClassPathUtils cpu = new ClassPathUtils ();
67- assertThat (cpu .getConnectorJUrls ()).hasLength (1 );
86+ assertThat (cpu .getConnectorJUrls ()).hasLength (0 );
6887 assertThat (System .getProperty ("classpath.runtime-impl" ))
6988 .isEqualTo (
70- "/tmp/runtime-impl11.jar"
71- + PATH_SEPARATOR
72- + "/tmp/runtime-impl-third-party.jar"
89+ runtimeLocation
90+ + "/runtime-impl.jar"
7391 + PATH_SEPARATOR
74- + "/tmp/runtime-appengine-api.jar" );
92+ + runtimeLocation
93+ + "/appengine-api-1.0-sdk.jar" );
7594
76- assertThat (System .getProperty ("classpath.runtime-shared" )).isEqualTo ("/tmp/runtime-shared.jar" );
77- assertThat (System .getProperty ("classpath.connector-j" ))
78- .isEqualTo ("/tmp/jdbc-mysql-connector.jar" );
79- assertThat (System .getProperty ("classpath.api-map" )).isEqualTo ("1.0=/tmp/appengine-api.jar" );
95+ assertThat (System .getProperty ("classpath.runtime-shared" ))
96+ .isEqualTo (runtimeLocation + "/runtime-shared.jar" );
97+ assertThat (System .getProperty ("classpath.connector-j" )).isNull ();
98+
99+ assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
100+ .isEqualTo (runtimeLocation + "/appengine-api-1.0-sdk.jar" );
80101 }
81102
82103 @ Test
83104 public void verifyJetty93PropertiesAreConfigured () throws Exception {
105+ createJava8Environment ();
84106 System .setProperty ("use.jetty93" , "true" );
85107 ClassPathUtils cpu = new ClassPathUtils ();
86108 assertThat (cpu .getConnectorJUrls ()).hasLength (1 );
87109 assertThat (System .getProperty ("classpath.runtime-impl" ))
88110 .isEqualTo (
89- "/tmp/runtime-impl.jar"
111+ runtimeLocation
112+ + "/runtime-impl.jar"
90113 + PATH_SEPARATOR
91- + "/tmp/frozen_debugger.jar"
114+ + runtimeLocation
115+ + "/frozen_debugger.jar"
92116 + PATH_SEPARATOR
93- + "/tmp/runtime-impl-third-party.jar"
117+ + runtimeLocation
118+ + "/runtime-impl-third-party.jar"
94119 + PATH_SEPARATOR
95- + "/tmp/runtime-appengine-api.jar" );
120+ + runtimeLocation
121+ + "/runtime-appengine-api.jar" );
96122
97- assertThat (System .getProperty ("classpath.runtime-shared" )).isEqualTo ("/tmp/runtime-shared.jar" );
123+ assertThat (System .getProperty ("classpath.runtime-shared" ))
124+ .isEqualTo (runtimeLocation + "/runtime-shared.jar" );
98125 assertThat (System .getProperty ("classpath.connector-j" ))
99- .isEqualTo ("/tmp/jdbc-mysql-connector.jar" );
100- assertThat (System .getProperty ("classpath.api-map" )).isEqualTo ("1.0=/tmp/appengine-api.jar" );
126+ .isEqualTo (runtimeLocation + "/jdbc-mysql-connector.jar" );
127+
128+ assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
129+ .isEqualTo (runtimeLocation + "/appengine-api.jar" );
101130 }
102131
103132 @ Test
104133 public void verifyJetty93WinsOverJetty94PropertiesAreConfigured () throws Exception {
134+ createJava8Environment ();
105135 // Set both of them and verify that 9.3 is winning:
106136 System .setProperty ("use.jetty93" , "true" );
107137 System .setProperty ("use.jetty94" , "true" );
@@ -112,99 +142,128 @@ public void verifyJetty93WinsOverJetty94PropertiesAreConfigured() throws Excepti
112142 assertThat (Boolean .getBoolean ("use.jetty94" )).isFalse ();
113143 assertThat (System .getProperty ("classpath.runtime-impl" ))
114144 .isEqualTo (
115- "/tmp/runtime-impl.jar"
145+ runtimeLocation
146+ + "/runtime-impl.jar"
116147 + PATH_SEPARATOR
117- + "/tmp/frozen_debugger.jar"
148+ + runtimeLocation
149+ + "/frozen_debugger.jar"
118150 + PATH_SEPARATOR
119- + "/tmp/runtime-impl-third-party.jar"
151+ + runtimeLocation
152+ + "/runtime-impl-third-party.jar"
120153 + PATH_SEPARATOR
121- + "/tmp/runtime-appengine-api.jar" );
154+ + runtimeLocation
155+ + "/runtime-appengine-api.jar" );
122156
123- assertThat (System .getProperty ("classpath.runtime-shared" )).isEqualTo ("/tmp/runtime-shared.jar" );
157+ assertThat (System .getProperty ("classpath.runtime-shared" ))
158+ .isEqualTo (runtimeLocation + "/runtime-shared.jar" );
124159 assertThat (System .getProperty ("classpath.connector-j" ))
125- .isEqualTo ("/tmp/jdbc-mysql-connector.jar" );
126- assertThat (System .getProperty ("classpath.api-map" )).isEqualTo ("1.0=/tmp/appengine-api.jar" );
160+ .isEqualTo (runtimeLocation + "/jdbc-mysql-connector.jar" );
161+
162+ assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
163+ .isEqualTo (runtimeLocation + "/appengine-api.jar" );
127164 }
128165
129166 @ Test
130167 public void verifyJetty94PropertiesAreConfigured () throws Exception {
131168
169+ createJava8Environment ();
132170 System .setProperty ("use.jetty94" , "true" );
133171 ClassPathUtils cpu = new ClassPathUtils ();
134172 assertThat (cpu .getConnectorJUrls ()).hasLength (1 );
135173 assertThat (System .getProperty ("classpath.runtime-impl" ))
136174 .isEqualTo (
137- "/tmp/runtime-impl.jar"
175+ runtimeLocation
176+ + "/runtime-impl.jar"
138177 + PATH_SEPARATOR
139- + "/tmp/runtime-impl-jetty94.jar"
178+ + runtimeLocation
179+ + "/runtime-impl-jetty94.jar"
140180 + PATH_SEPARATOR
141- + "/tmp/frozen_debugger.jar"
181+ + runtimeLocation
182+ + "/frozen_debugger.jar"
142183 + PATH_SEPARATOR
143- + "/tmp/runtime-impl-third-party-jetty94.jar"
184+ + runtimeLocation
185+ + "/runtime-impl-third-party-jetty94.jar"
144186 + PATH_SEPARATOR
145- + "/tmp/appengine-api-1.0-sdk.jar"
187+ + runtimeLocation
188+ + "/appengine-api-1.0-sdk.jar"
146189 + PATH_SEPARATOR
147- + "/tmp/runtime-appengine-api.jar" );
190+ + runtimeLocation
191+ + "/runtime-appengine-api.jar" );
148192
149- assertThat (System .getProperty ("classpath.runtime-shared" )).isEqualTo ("/tmp/runtime-shared.jar" );
193+ assertThat (System .getProperty ("classpath.runtime-shared" ))
194+ .isEqualTo (runtimeLocation + "/runtime-shared.jar" );
150195 assertThat (System .getProperty ("classpath.connector-j" ))
151- .isEqualTo ("/tmp/jdbc-mysql-connector.jar" );
152- assertThat (System .getProperty ("classpath.api-map" )).isEqualTo ("1.0=/tmp/appengine-api.jar" );
196+ .isEqualTo (runtimeLocation + "/jdbc-mysql-connector.jar" );
197+
198+ assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
199+ .isEqualTo (runtimeLocation + "/appengine-api.jar" );
153200 }
154201
155202 @ Test
156203 public void verifyMavenJarsPropertiesAreConfigured () throws Exception {
204+ createJava8Environment ();
157205 System .setProperty ("use.jetty94" , "true" );
158206 System .setProperty ("use.mavenjars" , "true" );
159207
160208 ClassPathUtils cpu = new ClassPathUtils (new File ("/my_app_root" ));
161209 assertThat (cpu .getConnectorJUrls ()).hasLength (1 );
162210 assertThat (System .getProperty ("classpath.runtime-impl" ))
163211 .isEqualTo (
164- "/tmp/jars/runtime-impl.jar"
212+ runtimeLocation
213+ + "/jars/runtime-impl.jar"
165214 + PATH_SEPARATOR
166- + "/tmp/jars/appengine-api-1.0-sdk.jar"
215+ + runtimeLocation
216+ + "/jars/appengine-api-1.0-sdk.jar"
167217 + PATH_SEPARATOR
168- + "/tmp/frozen_debugger.jar" );
218+ + runtimeLocation
219+ + "/frozen_debugger.jar" );
169220
170221 assertThat (System .getProperty ("classpath.runtime-shared" ))
171- .isEqualTo ("/tmp /jars/runtime-shared.jar" );
222+ .isEqualTo (runtimeLocation + " /jars/runtime-shared.jar" );
172223 assertThat (System .getProperty ("classpath.connector-j" ))
173- .isEqualTo ("/tmp/jdbc-mysql-connector.jar" );
174- assertThat (System .getProperty ("classpath.api-map" ))
175- .isEqualTo ("1.0=/tmp/jars/appengine-api-1.0-sdk.jar" );
224+ .isEqualTo (runtimeLocation + "/jdbc-mysql-connector.jar" );
225+
226+ assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
227+ .isEqualTo ("/my_app_root" + runtimeLocation + "/jars/appengine-api-1.0-sdk.jar" );
176228 assertThat (System .getProperty ("classpath.appengine-api-legacy" ))
177- .isEqualTo ("/tmp /jars/appengine-api-legacy.jar" );
229+ .isEqualTo (runtimeLocation + " /jars/appengine-api-legacy.jar" );
178230
179231 assertThat (cpu .getAppengineApiLegacyJar ().getAbsolutePath ())
180- .isEqualTo ("/my_app_root/tmp /jars/appengine-api-legacy.jar" );
232+ .isEqualTo ("/my_app_root" + runtimeLocation + " /jars/appengine-api-legacy.jar" );
181233 assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
182- .isEqualTo ("/my_app_root/tmp/jars/appengine-api-1.0-sdk.jar" );
183-
234+ .isEqualTo ("/my_app_root" + runtimeLocation + "/jars/appengine-api-1.0-sdk.jar" );
184235 }
185236
186237 @ Test
187238 public void verifyJetty93WinsOverMavenPropertiesAreConfigured () throws Exception {
239+ createJava8Environment ();
188240 // Set both of them and verify that 9.3 is winning:
189241 System .setProperty ("use.jetty93" , "true" );
190242 System .setProperty ("use.mavenjars" , "true" );
191243 ClassPathUtils cpu = new ClassPathUtils ();
192244 assertThat (cpu .getConnectorJUrls ()).hasLength (1 );
193245 assertThat (System .getProperty ("classpath.runtime-impl" ))
194246 .isEqualTo (
195- "/tmp/runtime-impl.jar"
247+ runtimeLocation
248+ + "/runtime-impl.jar"
196249 + PATH_SEPARATOR
197- + "/tmp/frozen_debugger.jar"
250+ + runtimeLocation
251+ + "/frozen_debugger.jar"
198252 + PATH_SEPARATOR
199- + "/tmp/runtime-impl-third-party.jar"
253+ + runtimeLocation
254+ + "/runtime-impl-third-party.jar"
200255 + PATH_SEPARATOR
201- + "/tmp/runtime-appengine-api.jar" );
256+ + runtimeLocation
257+ + "/runtime-appengine-api.jar" );
202258
203- assertThat (System .getProperty ("classpath.runtime-shared" )).isEqualTo ("/tmp/runtime-shared.jar" );
259+ assertThat (System .getProperty ("classpath.runtime-shared" ))
260+ .isEqualTo (runtimeLocation + "/runtime-shared.jar" );
204261 assertThat (System .getProperty ("classpath.connector-j" ))
205- .isEqualTo ("/tmp/jdbc-mysql-connector.jar" );
206- assertThat (System .getProperty ("classpath.api-map" )).isEqualTo ("1.0=/tmp/appengine-api.jar" );
207- assertThat (System .getProperty ("classpath.appengine-api-legacy" ))
208- .isNull ();
262+ .isEqualTo (runtimeLocation + "/jdbc-mysql-connector.jar" );
263+
264+ assertThat (cpu .getApiJarForVersion ("1.0" ).getAbsolutePath ())
265+ .isEqualTo (runtimeLocation + "/appengine-api.jar" );
266+
267+ assertThat (System .getProperty ("classpath.appengine-api-legacy" )).isNull ();
209268 }
210269}
0 commit comments