use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientTest method testPut.
public void testPut() throws URISyntaxException, Exception {
try (Processor p = new Processor()) {
final AtomicBoolean done = new AtomicBoolean();
p.addBasicPlugin(new ProgressPlugin() {
@Override
public Task startTask(final String name, int size) {
System.out.println("start " + name);
return new Task() {
@Override
public void worked(int units) {
System.out.println("worked " + name + " " + units);
}
@Override
public void done(String message, Throwable e) {
System.out.println("done " + name + " " + message + " " + e);
done.set(true);
}
@Override
public boolean isCanceled() {
return false;
}
};
}
});
try (HttpClient c = new HttpClient()) {
c.setRegistry(p);
TaggedData go = c.build().verb("PUT").upload("hello").asTag().go(httpServer.getBaseURI("put"));
go.getInputStream().close();
assertEquals(200, go.getResponseCode());
assertTrue(done.get());
}
}
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientTest method testModifiedWithEtag.
public void testModifiedWithEtag() throws Exception {
try (HttpClient hc = new HttpClient()) {
TaggedData data = hc.build().get(TaggedData.class).ifNoneMatch("0000").go(httpServer.getBaseURI("etag/1234/0"));
assertNotNull(data);
assertEquals("1234", data.getTag());
assertEquals(200, data.getResponseCode());
}
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientTest method testFetch.
public void testFetch() throws Exception {
try (HttpClient hc = new HttpClient()) {
String text = hc.build().get(String.class).go(httpServer.getBaseURI("get"));
assertNotNull(text);
assertTrue(text.startsWith("{"));
}
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientTest method testNotModifiedSince.
public void testNotModifiedSince() throws Exception {
try (HttpClient hc = new HttpClient()) {
TaggedData data = hc.build().get(TaggedData.class).ifNoneMatch("*").ifModifiedSince(20000).go(httpServer.getBaseURI("etag/1234/10000"));
assertNotNull(data);
assertEquals("1234", data.getTag());
assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, data.getResponseCode());
}
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientTest method testNotModifiedSinceAtSameTime.
public void testNotModifiedSinceAtSameTime() throws Exception {
try (HttpClient hc = new HttpClient()) {
TaggedData data = hc.build().get(TaggedData.class).ifNoneMatch("*").ifModifiedSince(20000).go(httpServer.getBaseURI("etag/1234/20000"));
assertNotNull(data);
assertEquals("1234", data.getTag());
assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, data.getResponseCode());
}
}
Aggregations