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();
}
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;
}
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;
}
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);
}
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);
}
Aggregations