1 /* 2 * Copyright (C) 2014 Square, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.squareup.okhttp.internal.framed; 17 18 import com.squareup.okhttp.internal.framed.hpackjson.Case; 19 import com.squareup.okhttp.internal.framed.hpackjson.Story; 20 import okio.Buffer; 21 import org.junit.Test; 22 import org.junit.runner.RunWith; 23 import org.junit.runners.Parameterized; 24 25 import java.util.Collection; 26 27 /** 28 * Tests for round-tripping headers through hpack.. 29 */ 30 // TODO: update hpack-test-case with the output of our encoder. 31 // This test will hide complementary bugs in the encoder and decoder, 32 // We should test that the encoder is producing responses that are 33 // d] 34 @RunWith(Parameterized.class) 35 public class HpackRoundTripTest extends HpackDecodeTestBase { 36 37 private static final String[] RAW_DATA = { "raw-data" }; 38 39 @Parameterized.Parameters(name="{0}") 40 public static Collection<Story[]> getStories() throws Exception { 41 return createStories(RAW_DATA); 42 } 43 44 private Buffer bytesOut = new Buffer(); 45 private Hpack.Writer hpackWriter = new Hpack.Writer(bytesOut); 46 47 public HpackRoundTripTest(Story story) { 48 super(story); 49 } 50 51 @Test 52 public void testRoundTrip() throws Exception { 53 Story story = getStory().clone(); 54 // Mutate cases in base class. 55 for (Case caze : story.getCases()) { 56 hpackWriter.writeHeaders(caze.getHeaders()); 57 caze.setWire(bytesOut.readByteString()); 58 } 59 60 testDecoder(story); 61 } 62 63 } 64