コード例 #1
0
 @Test // SPR-11970
 public void fromUriStringNoPathWithReservedCharInQuery() {
   UriComponents result =
       UriComponentsBuilder.fromUriString("http://example.com?foo=bar@baz").build();
   assertTrue(StringUtils.isEmpty(result.getUserInfo()));
   assertEquals("example.com", result.getHost());
   assertTrue(result.getQueryParams().containsKey("foo"));
   assertEquals("bar@baz", result.getQueryParams().getFirst("foo"));
 }
コード例 #2
0
 @Test
 public void queryParamWithoutValueWithEquals() throws Exception {
   UriComponents uriComponents =
       UriComponentsBuilder.fromUriString("http://example.com/foo?bar=").build();
   assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar="));
   assertThat(uriComponents.getQueryParams().get("bar").get(0), equalTo(""));
 }
コード例 #3
0
  @Test // SPR-9832
  public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxException {
    String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR";
    UriComponents result = UriComponentsBuilder.fromUriString(uri).build();

    assertEquals("q=1USD=?EUR", result.getQuery());
    assertEquals("1USD=?EUR", result.getQueryParams().getFirst("q"));
  }
コード例 #4
0
  @Test
  public void emptyQueryParam() throws URISyntaxException {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    UriComponents result = builder.queryParam("baz").build();

    assertEquals("baz", result.getQuery());
    MultiValueMap<String, String> expectedQueryParams = new LinkedMultiValueMap<>(2);
    expectedQueryParams.add("baz", null);
    assertEquals(expectedQueryParams, result.getQueryParams());
  }
コード例 #5
0
  @Test
  public void fromUriString() {
    UriComponents result =
        UriComponentsBuilder.fromUriString("http://www.ietf.org/rfc/rfc3986.txt").build();
    assertEquals("http", result.getScheme());
    assertNull(result.getUserInfo());
    assertEquals("www.ietf.org", result.getHost());
    assertEquals(-1, result.getPort());
    assertEquals("/rfc/rfc3986.txt", result.getPath());
    assertEquals(Arrays.asList("rfc", "rfc3986.txt"), result.getPathSegments());
    assertNull(result.getQuery());
    assertNull(result.getFragment());

    result =
        UriComponentsBuilder.fromUriString(
                "http://*****:*****@java.sun.com:80/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)")
            .build();
    assertEquals("http", result.getScheme());
    assertEquals("arjen:foobar", result.getUserInfo());
    assertEquals("java.sun.com", result.getHost());
    assertEquals(80, result.getPort());
    assertEquals("/javase/6/docs/api/java/util/BitSet.html", result.getPath());
    assertEquals("foo=bar", result.getQuery());
    MultiValueMap<String, String> expectedQueryParams = new LinkedMultiValueMap<>(1);
    expectedQueryParams.add("foo", "bar");
    assertEquals(expectedQueryParams, result.getQueryParams());
    assertEquals("and(java.util.BitSet)", result.getFragment());

    result = UriComponentsBuilder.fromUriString("mailto:[email protected]#baz").build();
    assertEquals("mailto", result.getScheme());
    assertNull(result.getUserInfo());
    assertNull(result.getHost());
    assertEquals(-1, result.getPort());
    assertEquals("*****@*****.**", result.getSchemeSpecificPart());
    assertNull(result.getPath());
    assertNull(result.getQuery());
    assertEquals("baz", result.getFragment());

    result = UriComponentsBuilder.fromUriString("docs/guide/collections/designfaq.html#28").build();
    assertNull(result.getScheme());
    assertNull(result.getUserInfo());
    assertNull(result.getHost());
    assertEquals(-1, result.getPort());
    assertEquals("docs/guide/collections/designfaq.html", result.getPath());
    assertNull(result.getQuery());
    assertEquals("28", result.getFragment());
  }