1818import org .mockserver .model .HttpRequest ;
1919import org .mockserver .model .HttpResponse ;
2020
21-
21+ /**
22+ * Class to test the tus-Client.
23+ */
2224public class TestTusClient extends MockServerProvider {
25+
26+ /**
27+ * Tests if the client object is set up correctly.
28+ */
2329 @ Test
2430 public void testTusClient () {
2531 TusClient client = new TusClient ();
2632 assertEquals (client .getUploadCreationURL (), null );
2733 }
2834
35+ /**
36+ * Checks if upload URLS are set correctly.
37+ * @throws MalformedURLException if the provided URL is malformed.
38+ */
2939 @ Test
3040 public void testTusClientURL () throws MalformedURLException {
3141 TusClient client = new TusClient ();
3242 client .setUploadCreationURL (creationUrl );
3343 assertEquals (client .getUploadCreationURL (), creationUrl );
3444 }
3545
46+ /**
47+ * Checks if upload URLS are set correctly.
48+ * @throws MalformedURLException if the provided URL is malformed.
49+ */
3650 @ Test
3751 public void testSetUploadCreationURL () throws MalformedURLException {
3852 TusClient client = new TusClient ();
3953 client .setUploadCreationURL (new URL ("http://tusd.tusdemo.net" ));
4054 assertEquals (client .getUploadCreationURL (), new URL ("http://tusd.tusdemo.net" ));
4155 }
4256
57+ /**
58+ * Tests if resumable uploads can be turned off and on.
59+ */
4360 @ Test
4461 public void testEnableResuming () {
4562 TusClient client = new TusClient ();
@@ -53,6 +70,11 @@ public void testEnableResuming() {
5370 assertEquals (client .resumingEnabled (), false );
5471 }
5572
73+ /**
74+ * Verifies if uploads can be created with the tus client.
75+ * @throws IOException if upload data cannot be read.
76+ * @throws ProtocolException if the upload cannot be constructed.
77+ */
5678 @ Test
5779 public void testCreateUpload () throws IOException , ProtocolException {
5880 mockServer .when (new HttpRequest ()
@@ -81,8 +103,12 @@ public void testCreateUpload() throws IOException, ProtocolException {
81103 assertEquals (uploader .getUploadURL (), new URL (mockServerURL + "/foo" ));
82104 }
83105
106+ /**
107+ * Tests if a missing location header causes an exception as expected.
108+ * @throws Exception if unreachable code has been reached.
109+ */
84110 @ Test
85- public void testCreateUploadWithMissingLocationHeader () throws IOException , Exception {
111+ public void testCreateUploadWithMissingLocationHeader () throws Exception {
86112 mockServer .when (new HttpRequest ()
87113 .withMethod ("POST" )
88114 .withPath ("/files" )
@@ -100,11 +126,15 @@ public void testCreateUploadWithMissingLocationHeader() throws IOException, Exce
100126 try {
101127 TusUploader uploader = client .createUpload (upload );
102128 throw new Exception ("unreachable code reached" );
103- } catch (ProtocolException e ) {
129+ } catch (ProtocolException e ) {
104130 assertEquals (e .getMessage (), "missing upload URL in response for creating upload" );
105131 }
106132 }
107133
134+ /**
135+ * Tests if uploads with relative upload destinations are working.
136+ * @throws Exception
137+ */
108138 @ Test
109139 public void testCreateUploadWithRelativeLocation () throws Exception {
110140 // We need to enable strict following for POST requests first
@@ -137,14 +167,22 @@ public void testCreateUploadWithRelativeLocation() throws Exception {
137167 upload .setInputStream (new ByteArrayInputStream (new byte [10 ]));
138168 TusUploader uploader = client .createUpload (upload );
139169
140- // The upload URL must be relative to the URL of the request by which is was returned,
141- // not the upload creation URL. In most cases, there is no difference between those two
170+ // The upload URL must be relative to the URL of the request by which it was returned,
171+ // not the upload creation URL. In most cases, there is no difference between those two,
142172 // but it's still important to be correct here.
143173 assertEquals (uploader .getUploadURL (), new URL (mockServerURL + "Redirected/foo" ));
144174 }
145175
176+ /**
177+ * Tests if {@link TusClient#resumeUpload(TusUpload)} works.
178+ * @throws ResumingNotEnabledException
179+ * @throws FingerprintNotFoundException
180+ * @throws IOException
181+ * @throws ProtocolException
182+ */
146183 @ Test
147- public void testResumeUpload () throws ResumingNotEnabledException , FingerprintNotFoundException , IOException , ProtocolException {
184+ public void testResumeUpload () throws ResumingNotEnabledException , FingerprintNotFoundException , IOException ,
185+ ProtocolException {
148186 mockServer .when (new HttpRequest ()
149187 .withMethod ("HEAD" )
150188 .withPath ("/files/foo" )
@@ -169,6 +207,9 @@ public void testResumeUpload() throws ResumingNotEnabledException, FingerprintNo
169207 assertEquals (uploader .getOffset (), 3 );
170208 }
171209
210+ /**
211+ * Test Implementation for a {@link TusURLStore}.
212+ */
172213 private class TestResumeUploadStore implements TusURLStore {
173214 public void set (String fingerprint , URL url ) {
174215 assertTrue ("set method must not be called" , false );
@@ -179,7 +220,7 @@ public URL get(String fingerprint) {
179220
180221 try {
181222 return new URL (mockServerURL .toString () + "/foo" );
182- } catch (Exception e ) {}
223+ } catch (Exception e ) { }
183224 return null ;
184225 }
185226
@@ -188,6 +229,11 @@ public void remove(String fingerprint) {
188229 }
189230 }
190231
232+ /**
233+ * Tests if an upload gets started if {@link TusClient#resumeOrCreateUpload(TusUpload)} gets called.
234+ * @throws IOException
235+ * @throws ProtocolException
236+ */
191237 @ Test
192238 public void testResumeOrCreateUpload () throws IOException , ProtocolException {
193239 mockServer .when (new HttpRequest ()
@@ -210,6 +256,12 @@ public void testResumeOrCreateUpload() throws IOException, ProtocolException {
210256 assertEquals (uploader .getUploadURL (), new URL (mockServerURL + "/foo" ));
211257 }
212258
259+
260+ /**
261+ * Checks if a new upload attempt is started in case of a serverside 404-error, without having an Exception thrown.
262+ * @throws IOException
263+ * @throws ProtocolException
264+ */
213265 @ Test
214266 public void testResumeOrCreateUploadNotFound () throws IOException , ProtocolException {
215267 mockServer .when (new HttpRequest ()
@@ -245,6 +297,11 @@ public void testResumeOrCreateUploadNotFound() throws IOException, ProtocolExcep
245297 assertEquals (uploader .getUploadURL (), new URL (mockServerURL + "/foo" ));
246298 }
247299
300+ /**
301+ * Tests if {@link TusClient#beginOrResumeUploadFromURL(TusUpload, URL)} works.
302+ * @throws IOException
303+ * @throws ProtocolException
304+ */
248305 @ Test
249306 public void testBeginOrResumeUploadFromURL () throws IOException , ProtocolException {
250307 mockServer .when (new HttpRequest ()
@@ -269,6 +326,10 @@ public void testBeginOrResumeUploadFromURL() throws IOException, ProtocolExcepti
269326 assertEquals (uploader .getOffset (), 3 );
270327 }
271328
329+ /**
330+ * Tests if connections are prepared correctly, which means all header are getting set.
331+ * @throws IOException
332+ */
272333 @ Test
273334 public void testPrepareConnection () throws IOException {
274335 HttpURLConnection connection = (HttpURLConnection ) mockServerURL .openConnection ();
@@ -278,6 +339,10 @@ public void testPrepareConnection() throws IOException {
278339 assertEquals (connection .getRequestProperty ("Tus-Resumable" ), TusClient .TUS_VERSION );
279340 }
280341
342+ /**
343+ * Tests if HTTP - Headers are set correctly.
344+ * @throws IOException
345+ */
281346 @ Test
282347 public void testSetHeaders () throws IOException {
283348 HttpURLConnection connection = (HttpURLConnection ) mockServerURL .openConnection ();
@@ -298,6 +363,10 @@ public void testSetHeaders() throws IOException {
298363 assertEquals (connection .getRequestProperty ("Important" ), "yes" );
299364 }
300365
366+ /**
367+ * Tests if connection timeouts are set correctly.
368+ * @throws IOException
369+ */
301370 @ Test
302371 public void testSetConnectionTimeout () throws IOException {
303372 HttpURLConnection connection = (HttpURLConnection ) mockServerURL .openConnection ();
@@ -312,6 +381,10 @@ public void testSetConnectionTimeout() throws IOException {
312381 assertEquals (connection .getConnectTimeout (), 3000 );
313382 }
314383
384+ /**
385+ * Tests whether the connection follows redirects only after explicitly enabling this feature.
386+ * @throws Exception
387+ */
315388 @ Test
316389 public void testFollowRedirects () throws Exception {
317390 HttpURLConnection connection = (HttpURLConnection ) mockServerURL .openConnection ();
@@ -355,6 +428,11 @@ public void testFollowRedirects() throws Exception {
355428 assertEquals (uploader .getUploadURL (), new URL (mockServerURL + "/foo" ));
356429 }
357430
431+ /**
432+ * Tests if the fingerprint in the {@link TusURLStore} does not get removed after upload success.
433+ * @throws IOException
434+ * @throws ProtocolException
435+ */
358436 @ Test
359437 public void testRemoveFingerprintOnSuccessDisabled () throws IOException , ProtocolException {
360438
@@ -376,6 +454,12 @@ public void testRemoveFingerprintOnSuccessDisabled() throws IOException, Protoco
376454
377455 }
378456
457+ /**
458+ * Tests if the fingerprint in the {@link TusURLStore} does get removed after upload success,
459+ * after this feature has been enabled via the {@link TusClient#enableRemoveFingerprintOnSuccess()} - method.
460+ * @throws IOException
461+ * @throws ProtocolException
462+ */
379463 @ Test
380464 public void testRemoveFingerprintOnSuccessEnabled () throws IOException , ProtocolException {
381465
0 commit comments