Esempio n. 1
0
  @Test
  public void unparse_no_parameters() throws Exception {
    ContentType contentType = new ContentType();

    contentType.setBaseType("text");
    contentType.setSubType("html");

    assertEquals(contentType.unparse(), "text/html");
  }
Esempio n. 2
0
  @Test
  public void unparse_with_parameters() throws Exception {
    ContentType contentType = new ContentType();

    contentType.setBaseType("text");
    contentType.setSubType("html");
    contentType.setParameter("charset", "utf-8");

    assertEquals(contentType.unparse(), "text/html;charset=utf-8");
  }
Esempio n. 3
0
  @Test
  public void parse_without_parameters() throws Exception {
    ContentType contentType = new ContentType("text/html");

    assertEquals(contentType.getBaseType(), "text");

    assertEquals(contentType.getSubType(), "html");

    assertEquals(contentType.getMimeType(), "text/html");

    assertTrue(contentType.getParameterNames().isEmpty());
  }
  public void processResultValue(JSONArray value) throws IOException {
    PrintWriter pw = response.getPrintWriter(contentType.toString());

    value.print(pw, compactJSON);

    pw.close();
  }
Esempio n. 5
0
  @Test
  public void to_string_is_unparse() {
    ContentType contentType = new ContentType();

    contentType.setBaseType("text");
    contentType.setSubType("html");
    contentType.setParameter("charset", "utf-8");

    assertEquals(contentType.toString(), contentType.unparse());
  }
Esempio n. 6
0
  @Test
  public void simple_equals() {
    ContentType master = new ContentType("text/html");

    assertFalse(master.equals(null));
    assertFalse(master.equals(this));
    assertTrue(master.equals(master));
    assertTrue(master.equals(new ContentType("text/html")));
    assertFalse(master.equals(new ContentType("foo/bar")));
    assertFalse(master.equals(new ContentType("text/plain")));
  }
Esempio n. 7
0
  @Test
  public void equals_with_parameters() {
    ContentType master = new ContentType("text/html;charset=utf-8");

    assertFalse(master.equals(new ContentType("text/html")));
    assertTrue(master.equals(new ContentType("text/html;charset=utf-8")));
    assertFalse(master.equals(new ContentType("text/html;charset=utf-8;foo=bar")));

    // Check that keys are case insensitive

    assertTrue(master.equals(new ContentType("text/html;Charset=utf-8")));

    master = new ContentType("text/html;foo=bar;biff=bazz");

    assertTrue(master.equals(new ContentType("text/html;foo=bar;biff=bazz")));
    assertTrue(master.equals(new ContentType("text/html;Foo=bar;Biff=bazz")));
    assertTrue(master.equals(new ContentType("text/html;biff=bazz;foo=bar")));
  }
Esempio n. 8
0
  @Test
  public void parse_with_parameters() throws Exception {
    ContentType contentType = new ContentType("text/html;charset=utf-8");

    assertEquals(contentType.getBaseType(), "text");

    assertEquals(contentType.getSubType(), "html");

    assertEquals(contentType.getMimeType(), "text/html");

    List<String> parameterNames = contentType.getParameterNames();
    assertEquals(parameterNames.size(), 1);

    assertEquals(parameterNames.get(0), "charset");

    assertEquals(contentType.getCharset(), "utf-8");

    String nonexistant = contentType.getParameter("nonexistant");
    assertTrue(nonexistant == null);
  }