PageRenderTime 30ms CodeModel.GetById 23ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/sitebricks-client/src/test/java/com/google/sitebricks/client/transport/RawTransportTest.java

http://github.com/dhanji/sitebricks
Java | 39 lines | 28 code | 7 blank | 4 comment | 0 complexity | 5ccab45ed7986f7d03eadeb51295bb01 MD5 | raw file
 1package com.google.sitebricks.client.transport;
 2
 3import org.testng.annotations.DataProvider;
 4import org.testng.annotations.Test;
 5
 6import java.io.ByteArrayInputStream;
 7import java.io.ByteArrayOutputStream;
 8import java.io.IOException;
 9
10/**
11 * Unit test for the various transports supported out of the box.
12 */
13public class RawTransportTest {
14  private static final String TEXT_DATA = "text";
15
16  @DataProvider(name = TEXT_DATA)
17  public Object[][] textData() {
18    return new Object[][] {
19        { "Hello there 2793847!@(*&#(!*@&#ASDJFA <SAAC<>M??X{." },
20        { "\\ \n \n \t \n \0 oaijsdfoijasdoifjao;sidjf19823749872w34*@(#$*&BMBMB" },
21        { "19827981273981723981729387192837912873912873" },
22        { "                                                      " },
23        { getClass().toString() },
24        { System.getProperties().toString()  },
25    };
26  }
27
28  @Test(dataProvider = TEXT_DATA)
29  public final void textTransport(String data) throws IOException {
30    ByteArrayOutputStream out = new ByteArrayOutputStream();
31    new ByteArrayTransport().out(out, byte[].class, data.getBytes());
32
33    // Convert back from byte array to string.
34    String in = new String(new ByteArrayTransport()
35        .in(new ByteArrayInputStream(out.toByteArray()), byte[].class));
36
37    assert data.equals(in) : "Text transport was not balanced";
38  }
39}