/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

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