use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method fragmentAppendParamTest.
@Test
public void fragmentAppendParamTest() {
// https://gitee.com/dromara/hutool/issues/I49KAL#note_8060874
String url = "https://www.hutool.cn/#/a/b";
final UrlBuilder builder = UrlBuilder.ofHttp(url);
builder.setFragment(builder.getFragment() + "?timestamp=1640391380204");
Assert.assertEquals("https://www.hutool.cn/#/a/b?timestamp=1640391380204", builder.toString());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method ofSpecialTest.
@Test
public void ofSpecialTest() {
// 测试不规范的或者无需解码的字符串是否成功解码
final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("http", builder.getScheme());
Assert.assertEquals("www.hutool.cn", builder.getHost());
Assert.assertEquals("aaa", builder.getPath().getSegment(0));
Assert.assertEquals("bbb", builder.getPath().getSegment(1));
Assert.assertEquals("张三", builder.getQuery().get("a"));
Assert.assertEquals("%四", builder.getQuery().get("b"));
Assert.assertEquals("frag1", builder.getFragment());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method blankEncodeTest.
@Test
public void blankEncodeTest() {
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://a.com/aaa bbb.html", CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("http://a.com/aaa%20bbb.html", urlBuilder.toString());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method ofTest.
@Test
public void ofTest() {
final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb/?a=1&b=2#frag1", CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("http", builder.getScheme());
Assert.assertEquals("www.hutool.cn", builder.getHost());
Assert.assertEquals("aaa", builder.getPath().getSegment(0));
Assert.assertEquals("bbb", builder.getPath().getSegment(1));
Assert.assertEquals("1", builder.getQuery().get("a"));
Assert.assertEquals("2", builder.getQuery().get("b"));
Assert.assertEquals("frag1", builder.getFragment());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method ofWithBlankTest.
@Test
public void ofWithBlankTest() {
final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("http", builder.getScheme());
Assert.assertEquals("www.hutool.cn", builder.getHost());
Assert.assertEquals("aaa", builder.getPath().getSegment(0));
Assert.assertEquals("bbb", builder.getPath().getSegment(1));
Assert.assertEquals("张三", builder.getQuery().get("a"));
Assert.assertEquals("李四", builder.getQuery().get("b"));
Assert.assertEquals("frag1", builder.getFragment());
}
Aggregations