use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class KeyStoreTest method testCopyJKSOptions.
@Test
public void testCopyJKSOptions() throws Exception {
JksOptions options = new JksOptions();
String password = TestUtils.randomAlphaString(100);
String path = TestUtils.randomAlphaString(100);
Buffer value = Buffer.buffer(TestUtils.randomAlphaString(100));
options.setPassword(password);
options.setPath(path);
options.setValue(value);
options = new JksOptions(options);
assertEquals(password, options.getPassword());
assertEquals(path, options.getPath());
assertEquals(value, options.getValue());
options = new JksOptions(options.toJson());
assertEquals(password, options.getPassword());
assertEquals(path, options.getPath());
assertEquals(value, options.getValue());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class KeyStoreTest method testPKCS12Value.
@Test
public void testPKCS12Value() throws Exception {
PfxOptions options = Cert.SERVER_PKCS12.get();
Buffer store = vertx.fileSystem().readFileBlocking(options.getPath());
options.setPath(null).setValue(store);
testKeyStore(options);
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class KeyStoreTest method testCopyKeyCertOptions.
@Test
public void testCopyKeyCertOptions() throws Exception {
PemKeyCertOptions options = new PemKeyCertOptions(new JsonObject());
String keyPath = TestUtils.randomAlphaString(100);
Buffer keyValue = Buffer.buffer(TestUtils.randomAlphaString(100));
String certPath = TestUtils.randomAlphaString(100);
Buffer certValue = Buffer.buffer(TestUtils.randomAlphaString(100));
options.setKeyPath(keyPath);
options.setKeyValue(keyValue);
options.setCertPath(certPath);
options.setCertValue(certValue);
options = new PemKeyCertOptions(options);
assertEquals(keyPath, options.getKeyPath());
assertEquals(keyValue, options.getKeyValue());
assertEquals(certPath, options.getCertPath());
assertEquals(certValue, options.getCertValue());
options = new PemKeyCertOptions(options.toJson());
assertEquals(keyPath, options.getKeyPath());
assertEquals(keyValue, options.getKeyValue());
assertEquals(certPath, options.getCertPath());
assertEquals(certValue, options.getCertValue());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class KeyStoreTest method testCopyPKCS12Options.
@Test
public void testCopyPKCS12Options() throws Exception {
PfxOptions options = new PfxOptions();
String password = TestUtils.randomAlphaString(100);
String path = TestUtils.randomAlphaString(100);
Buffer value = Buffer.buffer(TestUtils.randomAlphaString(100));
options.setPassword(password);
options.setPath(path);
options.setValue(value);
options = new PfxOptions(options);
assertEquals(password, options.getPassword());
assertEquals(path, options.getPath());
assertEquals(value, options.getValue());
options = new PfxOptions(options.toJson());
assertEquals(password, options.getPassword());
assertEquals(path, options.getPath());
assertEquals(value, options.getValue());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class WebsocketTest method testWSFrames.
private void testWSFrames(boolean binary, WebsocketVersion version) throws Exception {
String path = "/some/path";
String query = "foo=bar&wibble=eek";
String uri = path + "?" + query;
// version 0 doesn't support continuations so we just send 1 frame per message
int frames = version == WebsocketVersion.V00 ? 1 : 10;
server = vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT)).websocketHandler(ws -> {
assertEquals(uri, ws.uri());
assertEquals(path, ws.path());
assertEquals(query, ws.query());
assertEquals("upgrade", ws.headers().get("Connection"));
AtomicInteger count = new AtomicInteger();
ws.frameHandler(frame -> {
if (count.get() == 0) {
if (binary) {
assertTrue(frame.isBinary());
assertFalse(frame.isText());
} else {
assertFalse(frame.isBinary());
assertTrue(frame.isText());
}
assertFalse(frame.isContinuation());
} else {
assertFalse(frame.isBinary());
assertFalse(frame.isText());
assertTrue(frame.isContinuation());
}
if (count.get() == frames - 1) {
assertTrue(frame.isFinal());
} else {
assertFalse(frame.isFinal());
}
ws.writeFrame(frame);
if (count.incrementAndGet() == frames) {
count.set(0);
}
});
});
server.listen(ar -> {
assertTrue(ar.succeeded());
int bsize = 100;
int msgs = 10;
client.websocket(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path + "?" + query, null, version, ws -> {
final List<Buffer> sent = new ArrayList<>();
final List<Buffer> received = new ArrayList<>();
AtomicReference<Buffer> currentReceived = new AtomicReference<>(Buffer.buffer());
ws.frameHandler(frame -> {
currentReceived.get().appendBuffer(frame.binaryData());
if (frame.isFinal()) {
received.add(currentReceived.get());
currentReceived.set(Buffer.buffer());
}
if (received.size() == msgs) {
int pos = 0;
for (Buffer rec : received) {
assertEquals(rec, sent.get(pos++));
}
testComplete();
}
});
AtomicReference<Buffer> currentSent = new AtomicReference<>(Buffer.buffer());
for (int i = 0; i < msgs; i++) {
for (int j = 0; j < frames; j++) {
Buffer buff;
WebSocketFrame frame;
if (binary) {
buff = Buffer.buffer(TestUtils.randomByteArray(bsize));
if (j == 0) {
frame = WebSocketFrame.binaryFrame(buff, false);
} else {
frame = WebSocketFrame.continuationFrame(buff, j == frames - 1);
}
} else {
String str = TestUtils.randomAlphaString(bsize);
buff = Buffer.buffer(str);
if (j == 0) {
frame = WebSocketFrame.textFrame(str, false);
} else {
frame = WebSocketFrame.continuationFrame(buff, j == frames - 1);
}
}
currentSent.get().appendBuffer(buff);
ws.writeFrame(frame);
if (j == frames - 1) {
sent.add(currentSent.get());
currentSent.set(Buffer.buffer());
}
}
}
});
});
await();
}
Aggregations