source: events/src/test/java/geniusweb/actions/FileLocationTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 20 months ago

Fixed small issues in domaineditor.

File size: 2.0 KB
Line 
1package geniusweb.actions;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.io.File;
8import java.io.IOException;
9import java.util.UUID;
10
11import org.junit.Test;
12
13import com.fasterxml.jackson.core.JsonParseException;
14import com.fasterxml.jackson.core.JsonProcessingException;
15import com.fasterxml.jackson.databind.JsonMappingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18public 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}
Note: See TracBrowser for help on using the repository browser.