header1 = "text/html, application/vnd.wap.xhtml+xml, " + "application/xhtml+xml; profile=\"http: + "image/gif, image/jpeg, image/pjpeg, audio/amr, */*"; clientInfo = new ClientInfo(); PreferenceUtils.parseMediaTypes(header1, clientInfo); assertEquals(clientInfo.getAcceptedMediaTypes().get(0).getMetadata(), MediaType.TEXT_HTML); assertEquals(clientInfo.getAcceptedMediaTypes().get(0).getQuality(), 1.0F);
    public void testParsing() throws IOException {        String header1 = "Accept-Encoding,User-Agent";        String header2 = "Accept-Encoding , User-Agent";        String header3 = "Accept-Encoding,\r\tUser-Agent";        String header4 = "Accept-Encoding,\r User-Agent";        String header5 = "Accept-Encoding, \r \t User-Agent";        String[] values = new String[] { "Accept-Encoding", "User-Agent" };        testValues(header1, values);        testValues(header2, values);        testValues(header3, values);        testValues(header4, values);        testValues(header5, values);        header1 = "Accept-Encoding, Accept-Language, Accept";        header2 = "Accept-Encoding,Accept-Language,Accept";        values = new String[] { "Accept-Encoding", "Accept-Language", "Accept" };        testValues(header1, values);        testValues(header2, values);        // Test the parsing of a "Accept-encoding" header        header1 = "gzip;q=1.0, identity;q=0.5 , *;q=0";        ClientInfo clientInfo = new ClientInfo();        PreferenceUtils.parseEncodings(header1, clientInfo);        assertEquals(clientInfo.getAcceptedEncodings().get(0).getMetadata(),                Encoding.GZIP);        assertEquals(clientInfo.getAcceptedEncodings().get(0).getQuality(),                1.0F);        assertEquals(clientInfo.getAcceptedEncodings().get(1).getMetadata(),                Encoding.IDENTITY);        assertEquals(clientInfo.getAcceptedEncodings().get(1).getQuality(),                0.5F);        assertEquals(clientInfo.getAcceptedEncodings().get(2).getMetadata(),                Encoding.ALL);        assertEquals(clientInfo.getAcceptedEncodings().get(2).getQuality(), 0F);        // Test the parsing of a "Accept" header        header1 = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";        clientInfo = new ClientInfo();        PreferenceUtils.parseMediaTypes(header1, clientInfo);        assertEquals(clientInfo.getAcceptedMediaTypes().get(0).getMetadata(),                MediaType.TEXT_HTML);        assertEquals(clientInfo.getAcceptedMediaTypes().get(0).getQuality(),                1.0F);        assertEquals(clientInfo.getAcceptedMediaTypes().get(1).getMetadata(),                MediaType.IMAGE_GIF);        assertEquals(clientInfo.getAcceptedMediaTypes().get(1).getQuality(),                1.0F);        assertEquals(clientInfo.getAcceptedMediaTypes().get(2).getMetadata(),                MediaType.IMAGE_JPEG);        assertEquals(clientInfo.getAcceptedMediaTypes().get(2).getQuality(),                1.0F);        assertEquals(clientInfo.getAcceptedMediaTypes().get(3).getMetadata(),                new MediaType("*"));        assertEquals(clientInfo.getAcceptedMediaTypes().get(3).getQuality(),                0.2F);        assertEquals(clientInfo.getAcceptedMediaTypes().get(4).getMetadata(),                MediaType.ALL);        assertEquals(clientInfo.getAcceptedMediaTypes().get(4).getQuality(),                0.2F);    }