Search in sources :

Example 41 with MultiMap

use of io.vertx.core.MultiMap in project vert.x by eclipse.

the class HttpTest method testFormUploadAttributes2.

@Test
public void testFormUploadAttributes2() throws Exception {
    AtomicInteger attributeCount = new AtomicInteger();
    server.requestHandler(req -> {
        if (req.method() == HttpMethod.POST) {
            assertEquals(req.path(), "/form");
            req.setExpectMultipart(true);
            req.uploadHandler(event -> event.handler(buffer -> {
                fail("Should not get here");
            }));
            req.endHandler(v -> {
                MultiMap attrs = req.formAttributes();
                attributeCount.set(attrs.size());
                assertEquals("junit-testUserAlias", attrs.get("origin"));
                assertEquals("admin@foo.bar", attrs.get("login"));
                assertEquals("admin", attrs.get("pass word"));
                req.response().end();
            });
        }
    });
    server.listen(onSuccess(s -> {
        HttpClientRequest req = client.request(HttpMethod.POST, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/form", resp -> {
            assertEquals(200, resp.statusCode());
            resp.bodyHandler(body -> {
                assertEquals(0, body.length());
            });
            assertEquals(3, attributeCount.get());
            testComplete();
        });
        Buffer buffer = Buffer.buffer();
        buffer.appendString("origin=junit-testUserAlias&login=admin%40foo.bar&pass+word=admin");
        req.headers().set("content-length", String.valueOf(buffer.length()));
        req.headers().set("content-type", "application/x-www-form-urlencoded");
        req.write(buffer).end();
    }));
    await();
}
Also used : VertxException(io.vertx.core.VertxException) MultiMap(io.vertx.core.MultiMap) TimeoutException(java.util.concurrent.TimeoutException) Context(io.vertx.core.Context) InetAddress(java.net.InetAddress) HttpFrame(io.vertx.core.http.HttpFrame) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) UUID(java.util.UUID) Future(io.vertx.core.Future) FileNotFoundException(java.io.FileNotFoundException) Nullable(io.vertx.codegen.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpServerResponse(io.vertx.core.http.HttpServerResponse) AbstractVerticle(io.vertx.core.AbstractVerticle) WorkerContext(io.vertx.core.impl.WorkerContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) IntStream(java.util.stream.IntStream) HeadersAdaptor(io.vertx.core.http.impl.HeadersAdaptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) OutputStreamWriter(java.io.OutputStreamWriter) Assume(org.junit.Assume) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) BufferedWriter(java.io.BufferedWriter) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) EventLoopContext(io.vertx.core.impl.EventLoopContext) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) DeploymentOptions(io.vertx.core.DeploymentOptions) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) TemporaryFolder(org.junit.rules.TemporaryFolder) TestUtils.assertIllegalArgumentException(io.vertx.test.core.TestUtils.assertIllegalArgumentException) Buffer(io.vertx.core.buffer.Buffer) MultiMap(io.vertx.core.MultiMap) HttpClientRequest(io.vertx.core.http.HttpClientRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 42 with MultiMap

use of io.vertx.core.MultiMap in project vert.x by eclipse.

the class HttpTest method getHeaders.

protected static MultiMap getHeaders(int num) {
    Map<String, String> map = genMap(num);
    MultiMap headers = new HeadersAdaptor(new DefaultHttpHeaders());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        headers.add(entry.getKey(), entry.getValue());
    }
    return headers;
}
Also used : MultiMap(io.vertx.core.MultiMap) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HeadersAdaptor(io.vertx.core.http.impl.HeadersAdaptor) MultiMap(io.vertx.core.MultiMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 43 with MultiMap

use of io.vertx.core.MultiMap in project java-chassis by ServiceComb.

the class VertxToServletMockRequest method getParameterMap.

@Override
public Map<String, String[]> getParameterMap() {
    Map<String, String[]> paramMap = new HashMap<>();
    MultiMap map = this.vertxRequest.params();
    for (String name : map.names()) {
        List<String> valueList = map.getAll(name);
        paramMap.put(name, (String[]) map.getAll(name).toArray(new String[valueList.size()]));
    }
    return paramMap;
}
Also used : MultiMap(io.vertx.core.MultiMap) HashMap(java.util.HashMap)

Example 44 with MultiMap

use of io.vertx.core.MultiMap in project java-chassis by ServiceComb.

the class TestRestVertxHttpRequest method testGetQueryParam.

@Test
public void testGetQueryParam() {
    boolean status = true;
    try {
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "request", httpServerRequest);
        MultiMap multiMap = Mockito.mock(MultiMap.class);
        Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
        List<String> stringList = new ArrayList<String>();
        stringList.add("sters");
        Mockito.when(multiMap.getAll("key")).thenReturn(stringList);
        String[] str = instance.getQueryParam("key");
        Assert.assertEquals("sters", str[0]);
    } catch (Exception ex) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : MultiMap(io.vertx.core.MultiMap) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 45 with MultiMap

use of io.vertx.core.MultiMap in project java-chassis by ServiceComb.

the class TestRestVertxHttpRequest method testGetHeaderParam.

@Test
public void testGetHeaderParam() {
    boolean status = false;
    try {
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "request", httpServerRequest);
        MultiMap multiMap = Mockito.mock(MultiMap.class);
        Mockito.when(httpServerRequest.headers()).thenReturn(multiMap);
        @SuppressWarnings({ "unchecked" }) Iterator<Entry<String, String>> iterator = Mockito.mock(Iterator.class);
        Mockito.when(multiMap.iterator()).thenReturn(iterator);
        Mockito.when(iterator.hasNext()).thenReturn(true).thenReturn(false);
        Assert.assertNotNull(instance.getHeaderParam("key"));
    } catch (Exception ex) {
        status = true;
    }
    Assert.assertTrue(status);
}
Also used : MultiMap(io.vertx.core.MultiMap) Entry(java.util.Map.Entry) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Test(org.junit.Test)

Aggregations

MultiMap (io.vertx.core.MultiMap)89 Test (org.junit.Test)77 CaseInsensitiveHeaders (io.vertx.core.http.CaseInsensitiveHeaders)61 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)19 Map (java.util.Map)12 Buffer (io.vertx.core.buffer.Buffer)9 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)8 Handler (io.vertx.core.Handler)8 VertxException (io.vertx.core.VertxException)8 HttpClientRequest (io.vertx.core.http.HttpClientRequest)8 HttpMethod (io.vertx.core.http.HttpMethod)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)8 HeadersAdaptor (io.vertx.core.http.impl.HeadersAdaptor)8 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)7 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)7 Nullable (io.vertx.codegen.annotations.Nullable)7 AbstractVerticle (io.vertx.core.AbstractVerticle)7 AsyncResult (io.vertx.core.AsyncResult)7 Context (io.vertx.core.Context)7