client.enableResuming(new TusURLMemoryStore());
@Test public void test() throws MalformedURLException { TusURLStore store = new TusURLMemoryStore(); URL url = new URL("https://master.tus.io/files/hello"); String fingerprint = "foo"; store.set(fingerprint, url); assertEquals(store.get(fingerprint), url); store.remove(fingerprint); assertEquals(store.get(fingerprint), null); } }
@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 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")); }