Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add test upload pakai rest template

  • Loading branch information...
commit 074d537455bcb6a55e85fd2da86df837d631012f 1 parent e955dd0
Endy Muhardin authored
21 ...tful-web/src/test/java/com/artivisi/belajar/restful/ui/controller/ApplicationConfigControllerTestIT.java
View
@@ -23,11 +23,17 @@
import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import groovyx.net.http.ContentType;
import java.io.File;
+import java.util.Map;
import org.junit.Test;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
import com.artivisi.belajar.restful.domain.ApplicationConfig;
@@ -130,4 +136,19 @@ public void testUploadFile() {
.when()
.post(target+"/abc123/files");
}
+
+ @Test
+ public void testUploadPakaiRestTemplate(){
+ RestTemplate restTemplate = new RestTemplate();
+ MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
+ form.add("foto", new FileSystemResource("src/test/resources/foto-endy.jpg"));
+ form.add("Filename", "cv-endy.pdf");
+ form.add("cv", new FileSystemResource("src/test/resources/resume-endy-en.pdf"));
+ form.add("keterangan", "File Endy");
+ Map<String, String> result = restTemplate.postForObject(target+"/abc123/files", form, Map.class);
+
+ assertEquals("success", result.get("cv"));
+ assertEquals("success", result.get("foto"));
+ assertEquals("success", result.get("keterangan"));
+ }
}
BIN  belajar-restful-web/src/test/resources/foto-endy.jpg
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  belajar-restful-web/src/test/resources/resume-endy-en.pdf
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.