package it.inaf.oats.vospace.datamodel; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class NodeUtilsTest { @Test public void testGetPathFromRequestURLString() { String requestUrl = "http://localhost/vospace/nodes/a/b/c/"; assertEquals("/a/b/c", NodeUtils.getPathFromRequestURLString(requestUrl)); } @Test public void testGetPathWithSpacesFromRequestURLString() { String requestUrl = "http://localhost/vospace/nodes/a/b/c%20d%20%C3%A4+%2B.pdf"; assertEquals("/a/b/c d ä +.pdf", NodeUtils.getPathFromRequestURLString(requestUrl)); } @Test public void testEncodePathSpecialChars() { String specialChars = "ä è#+ /other/+-ò@"; assertEquals("%C3%A4%20%C3%A8%23%2B%20/other/%2B-%C3%B2%40", NodeUtils.urlEncodePath(specialChars)); } @Test public void testIllegalBrakets() { testIllegalChars(".pdf"); } @Test public void testIllegalQuestionMark() { testIllegalChars("???.pdf"); } @Test public void testIllegalQuotes() { testIllegalChars("\"'.pdf"); } @Test public void testIllegalSlashEncoded() { testIllegalChars("%2F.pdf"); } private void testIllegalChars(String illegalString) { boolean exception = false; try { NodeUtils.getPathFromRequestURLString("http://localhost/vospace/nodes/path/to/" + illegalString); } catch (IllegalArgumentException ex) { exception = true; } assertTrue(exception); } }