本文整理汇总了Java中io.vertx.ext.unit.TestContext类的典型用法代码示例。如果您正苦于以下问题:Java TestContext类的具体用法?Java TestContext怎么用?Java TestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestContext类属于io.vertx.ext.unit包,在下文中一共展示了TestContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepare
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Before
public void prepare(TestContext context) {
vertx = Vertx.vertx();
JsonObject dbConf = new JsonObject()
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true") // <1>
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4);
vertx.deployVerticle(new WikiDatabaseVerticle(),
new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess());
vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess());
webClient = WebClient.create(vertx, new WebClientOptions()
.setDefaultHost("localhost")
.setDefaultPort(8080));
}
示例2: noContextTokenTest
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void noContextTokenTest(TestContext context) {
// call and check response
final Async async = context.async();
client.getNow("/context/token", response -> {
context.assertEquals(400, response.statusCode());
response.handler(body -> {
context.assertEquals("Can't provide @Context of type: class com.zandero.rest.test.data.Token", body.toString());
async.complete();
});
});
}
示例3: testCustomInput_2
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testCustomInput_2(TestContext context) {
RestRouter.getReaders()
.register(List.class,
CustomWordListReader.class); // all arguments that are List<> go through this reader ... (reader returns List<String> as output)
Router router = RestRouter.register(vertx, TestReaderRest.class);
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(PORT);
// call and check response
final Async async = context.async();
client.post("/read/registered", response -> {
context.assertEquals(200, response.statusCode());
response.handler(body -> {
context.assertEquals("brown,dog,fox,jumps,over,quick,red,the", body.toString()); // returns sorted list of unique words
async.complete();
});
}).end("The quick brown fox jumps over the red dog!");
}
示例4: shouldUseDefaultValuesWhenAParameterIsNotSet
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void shouldUseDefaultValuesWhenAParameterIsNotSet(TestContext context) {
Async async = context.async();
vertx.eventBus().consumer("project.requested").handler(message -> {
message.reply(new JsonObject().put("archivePath", "src/test/resources/starter.zip"));
});
webClient.get("/api/starter.zip").sendJson(new JsonObject(), response -> {
if (response.succeeded()) {
assertThat(response.result().statusCode(), is(200));
async.complete();
} else {
context.fail(response.cause());
async.complete();
}
});
}
示例5: testLogoutPerformedBecauseLocalLogoutIsFalseButMultipleProfiles
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testLogoutPerformedBecauseLocalLogoutIsFalseButMultipleProfiles(final TestContext testContext) {
final Map<String, TestProfile> profiles = new HashMap<>();
profiles.put(NAME, TestProfile.from(TEST_CREDENTIALS));
profiles.put(VALUE, TestProfile.from(TEST_CREDENTIALS));
final Clients<AsyncClient<? extends Credentials, ? extends TestProfile>, AsyncAuthorizationGenerator<TestProfile>> clients = new Clients<>();
when(config.getClients()).thenReturn(clients);
final Async async = testContext.async();
asyncLogoutLogic = new DefaultAsyncLogoutLogic<>(config, httpActionAdapter, null, null, false, false, false);
final CompletableFuture<Object> resultFuture = addProfilesToContext(profiles)
.thenCompose(v -> asyncLogoutLogic.perform(webContext));
assertSuccessfulEvaluation(assertProfilesCount(resultFuture, 0), o -> {
assertThat(buffer.toString(), is(""));
assertThat(status.get(), is(200));
}, async);
}
示例6: testNoMatchRest
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testNoMatchRest(TestContext context) {
// call and check response
final Async async = context.async();
client.get("/rest/bla", response -> {
context.assertEquals(404, response.statusCode());
response.handler(body -> {
context.assertEquals("REST endpoint: '/rest/bla' not found!", body.toString());
async.complete();
});
}).putHeader("Accept", "application/json").end();
}
示例7: testTLS
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testTLS(TestContext ctx) {
Async async = ctx.async();
PgConnectOptions options = new PgConnectOptions(PgTestBase.options)
.setSsl(true)
.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server.crt"));
PgClient.connect(vertx, new PgConnectOptions(options).setSsl(true).setTrustAll(true), ctx.asyncAssertSuccess(conn -> {
ctx.assertTrue(conn.isSSL());
conn.query("SELECT * FROM Fortune WHERE id=1", ctx.asyncAssertSuccess(result -> {
ctx.assertEquals(1, result.size());
Tuple row = result.iterator().next();
ctx.assertEquals(1, row.getInteger(0));
ctx.assertEquals("fortune: No such file or directory", row.getString(1));
async.complete();
}));
}));
}
示例8: testSubSimpleRegExWithMultipleVariables
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testSubSimpleRegExWithMultipleVariables(TestContext context) {
// call and check response
final Async async = context.async();
client.getNow("/sub/regEx/ena/2/tri", response -> {
context.assertEquals(200, response.statusCode());
response.handler(body -> {
context.assertEquals("{one=ena, two=2, three=tri}", body.toString());
async.complete();
});
});
}
示例9: testGetNonExistentContext
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testGetNonExistentContext(TestContext context) {
// call and check response
final Async async = context.async();
client.getNow("/context/unknown", response -> {
context.assertEquals(400, response.statusCode());
response.handler(body -> {
context.assertEquals("Can't provide @Context of type: interface javax.ws.rs.core.Request", body.toString());
async.complete();
});
});
}
示例10: featherCallInjectedServiceRestTest
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void featherCallInjectedServiceRestTest(TestContext context) {
startWith(new FeatherInjectionProvider(), context);
final Async async = context.async();
client.getNow("/getInstance/dummy", response -> {
context.assertEquals(200, response.statusCode());
response.handler(body -> {
context.assertEquals("I'm so dummy!", body.toString());
async.complete();
});
});
}
示例11: testInsertEpisodeView
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testInsertEpisodeView(TestContext ctx) throws Exception {
JsonObject data = new JsonObject()
.put("seriesId", 42009)
.put("episodeId", 1188308)
.put("seasonId", "52595fb3760ee346619586ed");
database.insertEpisodeView("[email protected]", data.encode()).rxSetHandler()
.doOnError(ctx::fail).toBlocking().value();
JsonArray episodes = localDatabase.queryBlocking("SELECT * FROM Series WHERE Username = ?", new JsonArray()
.add("[email protected]"));
assertThat(episodes.size(), is(1));
JsonObject episode = episodes.getJsonObject(0);
assertThat(episode.getInteger("SeriesId"), is(data.getInteger("seriesId")));
assertThat(episode.getInteger("EpisodeId"), is(data.getInteger("episodeId")));
assertThat(episode.getString("SeasonId"), is(data.getString("seasonId")));
}
示例12: testRegEx
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testRegEx(TestContext context) {
// call and check response
final Async async = context.async();
client.getNow("/regEx/1/minus/2", response -> {
context.assertEquals(200, response.statusCode());
response.handler(body -> {
context.assertEquals("-1", body.toString());
async.complete();
});
});
}
示例13: testQueryStreamCloseCursor
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testQueryStreamCloseCursor(TestContext ctx) {
Async async = ctx.async();
PgClient.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> {
conn.query("BEGIN", ctx.asyncAssertSuccess(begin -> {
conn.prepare("SELECT * FROM Fortune WHERE id=$1 OR id=$2 OR id=$3 OR id=$4 OR id=$5 OR id=$6", ctx.asyncAssertSuccess(ps -> {
PgCursor stream = ps.cursor(Tuple.of(1, 8, 4, 11, 2, 9));
stream.read(4, ctx.asyncAssertSuccess(result -> {
ctx.assertEquals(4, result.size());
stream.close(ctx.asyncAssertSuccess(v1 -> {
ps.close(ctx.asyncAssertSuccess(v2 -> {
async.complete();
}));
}));
}));
}));
}));
}));
}
示例14: guiceCallInjectedServiceRestTest
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void guiceCallInjectedServiceRestTest(TestContext context) {
startWith(new GuiceInjectionProvider(), context);
final Async async = context.async();
client.getNow("/getInstance/dummy", response -> {
context.assertEquals(200, response.statusCode());
response.handler(body -> {
context.assertEquals("I'm so dummy!", body.toString());
async.complete();
});
});
}
示例15: testNotify
import io.vertx.ext.unit.TestContext; //导入依赖的package包/类
@Test
public void testNotify(TestContext ctx) {
Async async = ctx.async(2);
PgClient.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.query("LISTEN the_channel", ctx.asyncAssertSuccess(result1 -> {
conn.notificationHandler(notification -> {
ctx.assertEquals("the_channel", notification.getChannel());
ctx.assertEquals("the message", notification.getPayload());
async.countDown();
});
conn.query("NOTIFY the_channel, 'the message'", ctx.asyncAssertSuccess(result2 -> {
async.countDown();
}));
}));
}));
}