Code example for URI

Methods: getHost, getPath, getPort, getScheme, toString

0
 
public class SourceTextRetrieverTest extends TestCase {
 
    public void testURLTextRetriever() throws EvaluatorException { 
        try { 
            URI uri = new URI("http://host:9000/path");
            EvaluatorContext context = new EvaluatorContext(uri.toString(), null);
 
            URLTextRetriever txtRtvr = new URLTextRetriever();
            assertEquals(uri.toString(), txtRtvr.getSourceText(context));
 
            txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.host.name());
            assertEquals(uri.getHost(), txtRtvr.getSourceText(context));
 
            txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.port.name());
            assertEquals(String.valueOf(uri.getPort()), txtRtvr.getSourceText(context));
 
            txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.protocol.name());
            assertEquals(uri.getScheme(), txtRtvr.getSourceText(context));
 
            txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.path.name());
            assertEquals(uri.getPath(), txtRtvr.getSourceText(context));
        } catch (URISyntaxException ignore) {
 
        } 
    }