client.enableResuming(new TusURLMemoryStore());
@Test public void testEnableResuming() { TusClient client = new TusClient(); assertEquals(client.resumingEnabled(), false); TusURLStore store = new TusURLMemoryStore(); client.enableResuming(store); assertEquals(client.resumingEnabled(), true); client.disableResuming(); assertEquals(client.resumingEnabled(), false); }
@Test public void testResumeUpload() throws ResumingNotEnabledException, FingerprintNotFoundException, IOException, ProtocolException { mockServer.when(new HttpRequest() .withMethod("HEAD") .withPath("/files/foo") .withHeader("Tus-Resumable", TusClient.TUS_VERSION)) .respond(new HttpResponse() .withStatusCode(204) .withHeader("Tus-Resumable", TusClient.TUS_VERSION) .withHeader("Upload-Offset", "3")); TusClient client = new TusClient(); client.setUploadCreationURL(mockServerURL); client.enableResuming(new TestResumeUploadStore()); TusUpload upload = new TusUpload(); upload.setSize(10); upload.setInputStream(new ByteArrayInputStream(new byte[10])); upload.setFingerprint("test-fingerprint"); TusUploader uploader = client.resumeUpload(upload); assertEquals(uploader.getUploadURL(), new URL(mockServerURL.toString() + "/foo")); assertEquals(uploader.getOffset(), 3); }
@Test public void testResumeOrCreateUploadNotFound() throws IOException, ProtocolException { mockServer.when(new HttpRequest() .withMethod("HEAD") .withPath("/files/not_found") .withHeader("Tus-Resumable", TusClient.TUS_VERSION)) .respond(new HttpResponse() .withStatusCode(404)); mockServer.when(new HttpRequest() .withMethod("POST") .withPath("/files") .withHeader("Tus-Resumable", TusClient.TUS_VERSION) .withHeader("Upload-Length", "10")) .respond(new HttpResponse() .withStatusCode(201) .withHeader("Tus-Resumable", TusClient.TUS_VERSION) .withHeader("Location", mockServerURL + "/foo")); TusClient client = new TusClient(); client.setUploadCreationURL(mockServerURL); TusURLStore store = new TusURLMemoryStore(); store.set("fingerprint", new URL(mockServerURL + "/not_found")); client.enableResuming(store); TusUpload upload = new TusUpload(); upload.setSize(10); upload.setInputStream(new ByteArrayInputStream(new byte[10])); upload.setFingerprint("fingerprint"); TusUploader uploader = client.resumeOrCreateUpload(upload); assertEquals(uploader.getUploadURL(), new URL(mockServerURL + "/foo")); }