use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class HttpTestServerTest method testEncoding.
public void testEncoding() throws Exception {
try (HttpTestServer http = getHttp()) {
URL url = new URL(http.getBaseURI() + "/encoding/utf8");
String s = IO.collect(url.openStream(), "UTF-8");
assertNotNull(s);
assertEquals(9995, s.length());
url = new URL(http.getBaseURI() + "/encoding/utf16");
s = IO.collect(url.openStream(), "UTF-16");
assertNotNull(s);
assertEquals(9995, s.length());
url = new URL(http.getBaseURI() + "/encoding/ascii");
s = IO.collect(url.openStream(), "ascii");
assertNotNull(s);
assertEquals(9995, s.length());
url = new URL(http.getBaseURI() + "/encoding/ISO_8859_1");
s = IO.collect(url.openStream(), "ISO_8859_1");
assertNotNull(s);
assertEquals(9995, s.length());
}
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class HttpTestServerTest method testGzip.
public void testGzip() throws Exception {
try (HttpTestServer http = getHttp()) {
URL url = new URL(http.getBaseURI() + "/gzip");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Accept-Encoding", "gzip");
byte[] data = IO.read(con.getInputStream());
ByteArrayInputStream bin = new ByteArrayInputStream(data);
GZIPInputStream gzin = new GZIPInputStream(bin);
String s = IO.collect(gzin, "UTF-8");
System.out.println(s);
}
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class HttpTestServerTest method testSimple.
public void testSimple() throws Exception {
HttpTestServer http = getHttps();
System.out.println(http.getBaseURI());
System.out.println(Arrays.toString(http.getCertificateChain()));
assertFalse(0 == http.getAddress().getPort());
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class IndexedReposWithComms method http.
HttpTestServer http() throws Exception, IOException {
HttpTestServer.Config config = new HttpTestServer.Config();
config.host = "localhost";
HttpTestServer ht = new HS(config);
ht.start();
return ht;
}
use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.
the class IndexedReposWithComms method testBasicWorkspace.
public void testBasicWorkspace() throws Exception {
HttpTestServer ht = http();
try {
createSecureSocks5();
Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/basic"));
assertNotNull(ws);
List<URLConnector> connectors = ws.getPlugins(URLConnector.class);
assertNotNull(connectors);
assertEquals(1, connectors.size());
assertTrue(connectors.get(0) instanceof HttpClient);
HttpClient hc = (HttpClient) connectors.get(0);
InputStream connect = hc.connect(new URL(ht.getBaseURI() + "/basic-auth/user/good"));
assertNotNull(connect);
aQute.lib.io.IO.copy(connect, System.out);
connect.close();
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
} finally {
ht.close();
}
}
Aggregations