[47] | 1 | package geniusweb.actions;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 | import static org.junit.Assert.assertFalse;
|
---|
| 5 | import static org.junit.Assert.assertTrue;
|
---|
| 6 |
|
---|
| 7 | import java.io.File;
|
---|
| 8 | import java.io.IOException;
|
---|
| 9 | import java.util.UUID;
|
---|
| 10 |
|
---|
| 11 | import org.junit.Test;
|
---|
| 12 |
|
---|
| 13 | import com.fasterxml.jackson.core.JsonParseException;
|
---|
| 14 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
| 15 | import com.fasterxml.jackson.databind.JsonMappingException;
|
---|
| 16 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
| 17 |
|
---|
| 18 | public class FileLocationTest {
|
---|
| 19 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
| 20 | private FileLocation fileloc = new FileLocation();
|
---|
| 21 | private String filelocstr = "\"" + fileloc.getUUIDString() + "\"";
|
---|
| 22 |
|
---|
| 23 | private String uuidstr = "b871e65c-e7fe-4664-b607-cb31898cc3ac";
|
---|
| 24 | private FileLocation fileloc2 = new FileLocation(UUID.fromString(uuidstr));
|
---|
| 25 |
|
---|
| 26 | @Test
|
---|
| 27 | public void isUsable() throws IOException {
|
---|
| 28 | File file = fileloc.getFile();
|
---|
| 29 | assertFalse(file.exists());
|
---|
| 30 | assertTrue(file.createNewFile());
|
---|
| 31 | assertTrue(file.canRead());
|
---|
| 32 | assertTrue(file.canWrite());
|
---|
| 33 |
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | @Test
|
---|
| 37 | public void serializeTest() throws JsonProcessingException {
|
---|
| 38 | System.out.println(jackson.writeValueAsString(fileloc));
|
---|
| 39 | assertEquals(filelocstr, jackson.writeValueAsString(fileloc));
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @Test
|
---|
| 43 | public void deserializTest() throws IOException {
|
---|
| 44 | FileLocation loc = jackson.readValue(filelocstr, FileLocation.class);
|
---|
| 45 | assertEquals(fileloc, loc);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | @Test(expected = JsonParseException.class)
|
---|
| 49 | public void deserializeTestInjectinon()
|
---|
| 50 | throws JsonParseException, JsonMappingException, IOException {
|
---|
| 51 | jackson.readValue("bla/../..", FileLocation.class);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | @Test(expected = JsonParseException.class)
|
---|
| 55 | public void deserializeTestInjection2()
|
---|
| 56 | throws JsonParseException, JsonMappingException, IOException {
|
---|
| 57 | jackson.readValue("~/blabla", FileLocation.class);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | @Test(expected = JsonParseException.class)
|
---|
| 61 | public void deserializeTestInjection3()
|
---|
| 62 | throws JsonParseException, JsonMappingException, IOException {
|
---|
| 63 | jackson.readValue("C:\\Windows", FileLocation.class);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | } |
---|