コード例 #1
0
 @Test
 public void shouldUseSpecifieDefaultCharsetProperty() {
   List<Header> headers = new ArrayList<Header>();
   headers.add(new RestData.Header("Content-Type", "application/json"));
   Config c = Config.getConfig();
   c.add("restfixture.content.handlers.map", confMap());
   c.add("restfixture.content.default.charset", "MY-CHARSET");
   ContentType.config(c);
   assertEquals(ContentType.parseCharset(headers), "MY-CHARSET");
 }
コード例 #2
0
 @Test
 public void shouldSetupInternalStateFromConfig() {
   StringBuffer configEntry = new StringBuffer();
   configEntry.append("application/x-html=xml<br/>\n");
   Config c = Config.getConfig();
   c.add("restfixture.content.handlers.map", configEntry.toString());
   ContentType.config(c);
   assertEquals(ContentType.XML, ContentType.typeFor("application/x-html"));
   assertEquals(ContentType.XML, ContentType.typeFor("default"));
 }
コード例 #3
0
 @Test
 public void
     shouldUseDefaultSystemCharsetIfCharsetNotParseableAndDefaultNotSpecifiedViaProperty() {
   List<Header> headers = new ArrayList<Header>();
   headers.add(new RestData.Header("Content-Type", "application/json"));
   Config c = Config.getConfig();
   c.add("restfixture.content.handlers.map", confMap());
   c.add("restfixture.content.default.charset", null);
   ContentType.config(c);
   assertEquals(ContentType.parseCharset(headers), Charset.defaultCharset().name());
 }
コード例 #4
0
  @Test
  public void shouldSetupTheContentTypeToAdaptersMapViaConfig() {

    Config c = Config.getConfig();
    c.add("restfixture.content.handlers.map", confMap());
    c.add("restfixture.content.default.charset", "MY-CHARSET");
    ContentType.config(c);

    List<Header> headers = new ArrayList<Header>();
    headers.add(new RestData.Header("Content-Type", "application/json"));
    assertEquals(ContentType.JSON, ContentType.parse(headers));
    headers.set(0, new RestData.Header("Content-Type", "application/xml; charset=iso12344"));
    assertEquals(ContentType.XML, ContentType.parse(headers));
    headers.set(0, new RestData.Header("Content-Type", "application/xhtml"));
    assertEquals(ContentType.XML, ContentType.parse(headers));
    headers.set(0, new RestData.Header("Content-Type", "application/my-app-xml"));
    assertEquals(ContentType.XML, ContentType.parse(headers));
    headers.set(0, new RestData.Header("Content-Type", "text/plain"));
    assertEquals(ContentType.JSON, ContentType.parse(headers));

    // overrides "default"
    headers.set(0, new RestData.Header("Content-Type", "unhandled"));
    assertEquals(ContentType.TEXT, ContentType.parse(headers));
  }