package geniusweb.actions; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import java.util.UUID; import org.junit.Test; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; public class FileLocationTest { private final ObjectMapper jackson = new ObjectMapper(); private FileLocation fileloc = new FileLocation(); private String filelocstr = "\"" + fileloc.getUUIDString() + "\""; private String uuidstr = "b871e65c-e7fe-4664-b607-cb31898cc3ac"; private FileLocation fileloc2 = new FileLocation(UUID.fromString(uuidstr)); @Test public void isUsable() throws IOException { File file = fileloc.getFile(); assertFalse(file.exists()); assertTrue(file.createNewFile()); assertTrue(file.canRead()); assertTrue(file.canWrite()); } @Test public void serializeTest() throws JsonProcessingException { System.out.println(jackson.writeValueAsString(fileloc)); assertEquals(filelocstr, jackson.writeValueAsString(fileloc)); } @Test public void deserializTest() throws IOException { FileLocation loc = jackson.readValue(filelocstr, FileLocation.class); assertEquals(fileloc, loc); } @Test(expected = JsonParseException.class) public void deserializeTestInjectinon() throws JsonParseException, JsonMappingException, IOException { jackson.readValue("bla/../..", FileLocation.class); } @Test(expected = JsonParseException.class) public void deserializeTestInjection2() throws JsonParseException, JsonMappingException, IOException { jackson.readValue("~/blabla", FileLocation.class); } @Test(expected = JsonParseException.class) public void deserializeTestInjection3() throws JsonParseException, JsonMappingException, IOException { jackson.readValue("C:\\Windows", FileLocation.class); } }