@Test public void testParsingTypeSubType() { MediaType appJson = MediaType.fromString("application/json"); assertMediaTypeNoParams(appJson, "application", "json"); }
@Test public void testQuotedParams2() { MediaType mediaType = MediaType.fromString("application/json; charset='UTF-8'"); assertMediaTypeWithParam(mediaType, "application", "json", "charset", "UTF-8"); }
private void assertMediaTypeWithParam(MediaType mediaType, String type, String subType, String paramName, String paramValue) { assertMediaTypeWithParams(mediaType, type, subType, new String[]{paramName}, new String[]{paramValue}); }
@Test public void testToString() { assertEquals("application/xml", new MediaType("application", "xml", createMap(new MapEntry("q", "0.9"))).toString()); assertEquals("text/csv", new MediaType("text", "csv").toString()); assertEquals("foo/bar; a=2", new MediaType("foo", "bar", createMap(new MapEntry("a", "2"))).toString()); assertEquals("foo/bar; a=2; b=1; c=2", new MediaType("foo", "bar", createMap(new MapEntry("a", "2"), new MapEntry("b", "1"), new MapEntry("c", "2"))).toString()); assertEquals("a/b; p=1", MediaType.fromString("a/b; p=1; q=2;").toStringExcludingParam("q")); }
@Test public void testParsingEmptySpaces2() { MediaType appJson = MediaType.fromString("application/ json"); assertMediaTypeNoParams(appJson, "application", "json"); }
@Test public void testUnQuotedParamWithSpaces() { MediaType mediaType = MediaType.fromString("application/json ; charset= UTF-8"); assertMediaTypeWithParam(mediaType, "application", "json", "charset", "UTF-8"); }
@Test public void testMultipleParameters() { MediaType mediaType = MediaType.fromString("application/json ; charset=UTF-8; param1=value1; param2 = value2"); assertMediaTypeWithParams(mediaType, "application", "json", new String[]{"charset", "param1", "param2"}, new String[]{"UTF-8", "value1", "value2"}); }
@Test public void testParsingEmptySpaces3() { MediaType appJson = MediaType.fromString("application / json"); assertMediaTypeNoParams(appJson, "application", "json"); }
@Test public void testUnQuotedParam() { MediaType mediaType = MediaType.fromString("application/json; charset=UTF-8"); assertMediaTypeWithParam(mediaType, "application", "json", "charset", "UTF-8"); }
@Test public void testParsingEmptySpaces() { MediaType appJson = MediaType.fromString("application /json"); assertMediaTypeNoParams(appJson, "application", "json"); }
@Test public void testQuotedParams() { MediaType mediaType = MediaType.fromString("application/json; charset=\"UTF-8\""); assertMediaTypeWithParam(mediaType, "application", "json", "charset", "UTF-8"); }
@Test public void testMediaTypeExternalizerNoId() throws Exception { ObjectInOut inOutOrig = new ObjectInOut(); MediaType.MediaTypeExternalizer mediaTypeExternalizer = new MediaType.MediaTypeExternalizer(); mediaTypeExternalizer.writeObject(inOutOrig, MediaType.APPLICATION_XML); MediaType mediaType = mediaTypeExternalizer.readObject(inOutOrig); assertMediaTypeNoParams(mediaType, "application", "xml"); }
@Test public void testMediaTypeExternalizerId() throws Exception { ObjectInOut inOutOrig = new ObjectInOut(); MediaType.MediaTypeExternalizer mediaTypeExternalizer = new MediaType.MediaTypeExternalizer(); mediaTypeExternalizer.writeObject(inOutOrig, MediaType.TEXT_PLAIN); MediaType mediaType = mediaTypeExternalizer.readObject(inOutOrig); assertMediaTypeNoParams(mediaType, "text", "plain"); }