@Test(expected = EncodingException.class) public void testParsingNull() { MediaType.fromString(null); }
@Test(expected = EncodingException.class) public void testParsingEmpty() { MediaType.fromString(""); }
@Test(expected = EncodingException.class) public void testParsingNoSubType() { MediaType.fromString("something"); }
@Test(expected = EncodingException.class) public void testWrongQuoting() { MediaType.fromString("application/json ; charset= \"UTF-8"); }
@Test(expected = EncodingException.class) public void testParsingNoSubType2() { MediaType.fromString("application; charset=utf-8"); }
@Override public void testTranscoderTranscode() { MediaType personMediaType = MediaType.fromString("application/x-java-object;type=org.infinispan.test.data.Person"); Object result = transcoder.transcode(dataSrc, personMediaType, MediaType.APPLICATION_SERIALIZED_OBJECT); assertTrue(result instanceof byte[], "Must be byte[]"); Object transcodedBack = transcoder.transcode(result, MediaType.APPLICATION_SERIALIZED_OBJECT, personMediaType); assertEquals(transcodedBack, dataSrc, "Must be an equal objects"); } }
@Test public void testUnQuotedParam() { MediaType mediaType = MediaType.fromString("application/json; charset=UTF-8"); assertMediaTypeWithParam(mediaType, "application", "json", "charset", "UTF-8"); }
@Test public void testQuotedParams2() { MediaType mediaType = MediaType.fromString("application/json; charset='UTF-8'"); assertMediaTypeWithParam(mediaType, "application", "json", "charset", "UTF-8"); }
@Test public void testUnQuotedParamWithSpaces() { MediaType mediaType = MediaType.fromString("application/json ; charset= UTF-8"); assertMediaTypeWithParam(mediaType, "application", "json", "charset", "UTF-8"); }
@Test public void testParsingTypeSubType() { MediaType appJson = MediaType.fromString("application/json"); assertMediaTypeNoParams(appJson, "application", "json"); }
@Test public void testParsingEmptySpaces2() { MediaType appJson = MediaType.fromString("application/ json"); assertMediaTypeNoParams(appJson, "application", "json"); }
@Test public void testParsingEmptySpaces3() { MediaType appJson = MediaType.fromString("application / json"); assertMediaTypeNoParams(appJson, "application", "json"); }
@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 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 testParseWeight() { MediaType mediaType = MediaType.fromString("application/json ; q=0.8"); assertEquals(0.8, mediaType.getWeight(), 0.0); }
@Test public void testDefaultWeight() { MediaType mediaType = MediaType.fromString("application/json"); assertEquals(1.0, mediaType.getWeight(), 0.0); }
@Test public void testWildCard2() { MediaType mediaType = MediaType.fromString("*"); assertEquals("*", mediaType.getType()); assertEquals("*", mediaType.getSubType()); }
@Test public void testWildCard() { MediaType mediaType = MediaType.fromString("*/*"); assertEquals("*", mediaType.getType()); assertEquals("*", mediaType.getSubType()); assertTrue(mediaType.match(MediaType.TEXT_PLAIN)); assertTrue(mediaType.match(MediaType.APPLICATION_PROTOSTREAM)); }
@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")); }