4 changed files with 76 additions and 1 deletions
@ -0,0 +1,6 @@ |
|||||||
|
package org.leolo.map.osm.extract.model; |
||||||
|
|
||||||
|
public enum InputType { |
||||||
|
FILE, |
||||||
|
URL; |
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
package org.leolo.map.osm.extract.util; |
||||||
|
|
||||||
|
import org.leolo.map.osm.extract.model.InputType; |
||||||
|
|
||||||
|
import java.net.MalformedURLException; |
||||||
|
import java.net.URL; |
||||||
|
import java.util.Locale; |
||||||
|
|
||||||
|
public class InputUtil { |
||||||
|
public static InputType identifyInputType(String str){ |
||||||
|
try { |
||||||
|
URL url = new URL(str); |
||||||
|
} catch (Exception e) { |
||||||
|
return InputType.FILE; |
||||||
|
} |
||||||
|
return InputType.URL; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,50 @@ |
|||||||
|
package org.leolo.map.osm.extract.test; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.leolo.map.osm.extract.model.InputType; |
||||||
|
import org.leolo.map.osm.extract.util.InputUtil; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||||
|
|
||||||
|
public class InputTypeTest { |
||||||
|
|
||||||
|
@Test void testFilePath(){ |
||||||
|
assertEquals(InputUtil.identifyInputType("abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("../abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("./abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("..\\abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("/tmp/abc.xml"), InputType.FILE); |
||||||
|
} |
||||||
|
|
||||||
|
@Test void testUPCPath(){ |
||||||
|
assertEquals(InputUtil.identifyInputType("\\\\somecomputer\\somefolder\\abc.xml"), InputType.FILE); |
||||||
|
} |
||||||
|
|
||||||
|
@Test void testURL(){ |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue