Search in sources :

Example 96 with Buffer

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());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) JksOptions(io.vertx.core.net.JksOptions) Test(org.junit.Test)

Example 97 with Buffer

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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 98 with Buffer

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());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 99 with Buffer

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());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 100 with Buffer

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();
}
Also used : Arrays(java.util.Arrays) MessageDigest(java.security.MessageDigest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cert(io.vertx.test.core.tls.Cert) WebSocketHandshakeException(io.netty.handler.codec.http.websocketx.WebSocketHandshakeException) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestUtils(io.vertx.test.core.TestUtils) Map(java.util.Map) ReadStream(io.vertx.core.streams.ReadStream) AsyncResult(io.vertx.core.AsyncResult) ConcurrentHashSet(io.vertx.core.impl.ConcurrentHashSet) java.util.concurrent(java.util.concurrent) Vertx(io.vertx.core.Vertx) Set(java.util.Set) Test(org.junit.Test) Future(io.vertx.core.Future) io.vertx.core.http(io.vertx.core.http) Consumer(java.util.function.Consumer) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) DeploymentOptions(io.vertx.core.DeploymentOptions) NetServer(io.vertx.core.net.NetServer) AbstractVerticle(io.vertx.core.AbstractVerticle) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Handler(io.vertx.core.Handler) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Collections(java.util.Collections) NetSocket(io.vertx.core.net.NetSocket) Trust(io.vertx.test.core.tls.Trust) Buffer(io.vertx.core.buffer.Buffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

Buffer (io.vertx.core.buffer.Buffer)1052 Test (org.junit.Test)604 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)256 Future (io.vertx.core.Future)253 AtomicReference (java.util.concurrent.atomic.AtomicReference)237 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)235 Handler (io.vertx.core.Handler)230 Vertx (io.vertx.core.Vertx)185 TestUtils (io.vertx.test.core.TestUtils)177 JsonObject (io.vertx.core.json.JsonObject)172 TimeUnit (java.util.concurrent.TimeUnit)161 CountDownLatch (java.util.concurrent.CountDownLatch)153 List (java.util.List)152 Consumer (java.util.function.Consumer)149 Function (java.util.function.Function)142 ReadStream (io.vertx.core.streams.ReadStream)139 Context (io.vertx.core.Context)135 ArrayList (java.util.ArrayList)132 MultiMap (io.vertx.core.MultiMap)130 Assume (org.junit.Assume)130