Java Code Examples for io.vertx.ext.unit.TestContext#assertEquals()
The following examples show how to use
io.vertx.ext.unit.TestContext#assertEquals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSHServerTest.java From vertx-shell with Apache License 2.0 | 6 votes |
@Test public void testDifferentCharset(TestContext context) throws Exception { termHandler = term -> { term.write("\u20AC"); term.close(); }; startShell(new SSHTermOptions().setDefaultCharset("ISO_8859_1").setPort(5000).setHost("localhost").setKeyPairOptions( new JksOptions().setPath("src/test/resources/server-keystore.jks").setPassword("wibble")). setAuthOptions(new JsonObject() .put("provider", "shiro") .put("type", "PROPERTIES") .put("config", new JsonObject().put("properties_path", "classpath:test-auth.properties")))); Session session = createSession("paulo", "secret", false); session.connect(); Channel channel = session.openChannel("shell"); channel.connect(); InputStream in = channel.getInputStream(); int b = in.read(); context.assertEquals(63, b); }
Example 2
Source File: SMTPConnectionPoolTest.java From vertx-mail-client with Apache License 2.0 | 6 votes |
/** * test what happens if the server closes the connection while idle * <p> * (the close exception was sent to the errorHandler even though we returned the connection to the pool) * * @param testContext */ @Test public final void testGetConnectionClosePool(TestContext testContext) { Async async = testContext.async(); SMTPConnectionPool pool = new SMTPConnectionPool(vertx, config); testContext.assertEquals(0, pool.connCount()); pool.getConnection("hostname", result -> { if (result.succeeded()) { log.debug("got connection"); testContext.assertEquals(1, pool.connCount()); result.result().returnToPool(); testContext.assertEquals(1, pool.connCount()); stopSMTP(); // this closes our dummy server and consequently our // connection at the server end vertx.setTimer(1, v -> { pool.close(v2 -> { testContext.assertEquals(0, pool.connCount()); async.complete(); }); }); } else { log.info(result.cause()); testContext.fail(result.cause()); } }); }
Example 3
Source File: PostgresClientIT.java From raml-module-builder with Apache License 2.0 | 6 votes |
@Test public void streamGetExceptionInEndHandler(TestContext context) throws IOException, FieldException { final String tableDefiniton = "id UUID PRIMARY KEY , jsonb JSONB NOT NULL, distinct_test_field TEXT"; createTableWithPoLines(context, MOCK_POLINES_TABLE, tableDefiniton); CQLWrapper wrapper = new CQLWrapper(new CQL2PgJSON("jsonb"), "edition=First edition"); StringBuilder events = new StringBuilder(); Async async = context.async(); postgresClient.streamGet(MOCK_POLINES_TABLE, Object.class, "jsonb", wrapper, false, null, context.asyncAssertSuccess(sr -> { sr.handler(streamHandler -> { events.append("[handler]"); }); sr.endHandler(x -> { events.append("[endHandler]"); throw new NullPointerException("null"); }); sr.exceptionHandler(x -> { events.append("[exception]"); async.complete(); }); })); async.await(1000); context.assertEquals("[handler][handler][handler][endHandler][exception]", events.toString()); }
Example 4
Source File: PgUtilIT.java From raml-module-builder with Apache License 2.0 | 6 votes |
/** * Assert that response has the httpStatus and its result is a User with expected username and uuid. * uuid=null accepts any uuid. Returns the uuid of the User in response. */ private String assertStatusAndUser(TestContext testContext, AsyncResult<Response> result, int httpStatus, String username, String uuid) { testContext.assertTrue(result.succeeded(), "succeeded()"); Response response = result.result(); testContext.assertEquals(httpStatus, response.getStatus(), "status of entity=" + response.getEntity()); if (response.getEntity() == null) { testContext.fail("Expected response with a User instance but it was null"); return null; } if (! (response.getEntity() instanceof User)) { testContext.fail("Expected response with a User instance but type was " + response.getEntity().getClass().getName()); return null; } User user = (User) response.getEntity(); testContext.assertEquals(username, user.getUsername(), "getUsername()"); if (uuid != null) { testContext.assertEquals(uuid, user.getId(), "User::getId()"); } return user.getId(); }
Example 5
Source File: ExtendedQueryDataTypeCodecTestBase.java From vertx-sql-client with Apache License 2.0 | 5 votes |
private static <T> void compare(TestContext ctx, T expected, T actual) { if (expected != null && expected.getClass().isArray()) { ctx.assertNotNull(actual); ctx.assertTrue(actual.getClass().isArray()); List expectedList = Arrays.asList((Object[]) expected); List actualList = Arrays.asList((Object[]) actual); ctx.assertEquals(expectedList, actualList); } else { ctx.assertEquals(expected, actual); } }
Example 6
Source File: DeployVerticleTest.java From vertx-shell with Apache License 2.0 | 5 votes |
@Test public void testDeployWithOptionsAsEmptyJsonString(TestContext context) { String cmd = "verticle-deploy io.vertx.ext.shell.command.base.DeployVerticleTest$SomeVerticle '{}'"; String result = testDeployCmd(context, cmd); context.assertNotNull(ctx.get()); context.assertEquals(result, "Deployed " + ctx.get().deploymentID()); context.assertEquals(1, ctx.get().getInstanceCount()); }
Example 7
Source File: CustomEndpointTest.java From konduit-serving with Apache License 2.0 | 5 votes |
@Test public void inferenceVerticleCustomGet(TestContext testContext) { Response response = given().port(inferenceDeploymentResult.getActualPort()) .accept(ContentType.JSON) .get(CustomGetEndpoint.PATH) .andReturn(); testContext.assertEquals(200, response.statusCode()); testContext.assertEquals(ContentType.JSON.toString(), response.contentType()); String s = response.asString(); Data d = Data.fromJson(s); testContext.assertEquals(d, CustomGetEndpoint.output); //Test standard inference: Data input = JData.singletonList("someKey", Arrays.asList("x", "y", "z"), ValueType.STRING); response = given().port(inferenceDeploymentResult.getActualPort()) .contentType(ContentType.JSON) .accept(ContentType.JSON) .body(input.toJson()) .post(InferenceVerticleHttpTest.PREDICT_ENDPOINT) .andReturn(); s = response.asString(); d = Data.fromJson(s); assertEquals(input, d); }
Example 8
Source File: SMTPConnectionPoolTest.java From vertx-mail-client with Apache License 2.0 | 5 votes |
/** * test that we are really waiting if the connection pool is full * * @param testContext */ @Test public final void testWaitingForConnection(TestContext testContext) { final MailConfig config = configNoSSL().setMaxPoolSize(1); Async async = testContext.async(); AtomicBoolean haveGotConnection = new AtomicBoolean(false); SMTPConnectionPool pool = new SMTPConnectionPool(vertx, config); testContext.assertEquals(0, pool.connCount()); pool.getConnection("hostname", result -> { if (result.succeeded()) { log.debug("got connection 1st tme"); testContext.assertEquals(1, pool.connCount()); pool.getConnection("hostname", result2 -> { if (result.succeeded()) { haveGotConnection.set(true); log.debug("got connection 2nd time"); testContext.assertEquals(1, pool.connCount()); result2.result().returnToPool(); pool.close(v -> { testContext.assertEquals(0, pool.connCount()); async.complete(); }); } else { log.info(result2.cause()); testContext.fail(result2.cause()); } }); testContext.assertFalse(haveGotConnection.get(), "got a connection on the 2nd try already"); log.debug("didn't get a connection 2nd time yet"); result.result().returnToPool(); testContext.assertTrue(haveGotConnection.get(), "didn't get a connection on the 2nd try"); log.debug("got a connection 2nd time"); } else { log.info(result.cause()); testContext.fail(result.cause()); } }); }
Example 9
Source File: ProtonServerImplTest.java From vertx-proton with Apache License 2.0 | 5 votes |
private void doTestAsyncServerAuthenticatorTestImpl(TestContext context, boolean passAuthentication) { Async connectAsync = context.async(); AtomicBoolean connectedServer = new AtomicBoolean(); final long delay = 750; TestAsyncAuthenticator testAsyncAuthenticator = new TestAsyncAuthenticator(delay, passAuthentication); TestAsyncAuthenticatorFactory authenticatorFactory = new TestAsyncAuthenticatorFactory(testAsyncAuthenticator); ProtonServer.create(vertx).saslAuthenticatorFactory(authenticatorFactory).connectHandler(protonConnection -> { connectedServer.set(true); }).listen(server -> { final long startTime = System.currentTimeMillis(); ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), GOOD_USER, PASSWD, conResult -> { // Verify the process took expected time from auth delay. long actual = System.currentTimeMillis() - startTime; context.assertTrue(actual >= delay, "Connect completed before expected time delay elapsed! " + actual); if (passAuthentication) { context.assertTrue(conResult.succeeded(), "Expected connect to succeed"); conResult.result().disconnect(); } else { context.assertFalse(conResult.succeeded(), "Expected connect to fail"); } connectAsync.complete(); }); }); connectAsync.awaitSuccess(); if(passAuthentication) { context.assertTrue(connectedServer.get(), "Server handler should have been called"); } else { context.assertFalse(connectedServer.get(), "Server handler should not have been called"); } context.assertEquals(1, authenticatorFactory.getCreateCount(), "unexpected authenticator creation count"); }
Example 10
Source File: CassandraClientTestBase.java From vertx-cassandra-client with Apache License 2.0 | 5 votes |
protected void checkContext(TestContext testContext) { Context context = vertx.getOrCreateContext(); if (capturedContext.compareAndSet(null, context)) { context.exceptionHandler(testContext::fail); } else { testContext.assertEquals(capturedContext.get(), context); } }
Example 11
Source File: JsonRxPetStoreTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test(timeout = 2000) public void testSwaggerManager(TestContext context) { Async async = context.async(2); SwaggerManager instance = SwaggerManager.getInstance(); context.assertNotNull(instance.getSwagger()); context.assertEquals("Swagger Petstore", instance.getSwagger().getInfo().getTitle()); async.complete(); }
Example 12
Source File: HttpModuleClient2Test.java From raml-module-builder with Apache License 2.0 | 5 votes |
@Test public void testWithAbs(TestContext context) throws Exception { HttpModuleClient2 httpModuleClient2 = new HttpModuleClient2("http://localhost:" + port1, "tenant"); CompletableFuture<Response> cf = httpModuleClient2.request("/test"); Response response = cf.get(5, TimeUnit.SECONDS); context.assertNull(response.error); context.assertNull(response.exception); context.assertEquals("/test", lastPath); context.assertEquals("", lastBuffer.toString()); }
Example 13
Source File: MultilineParserTest.java From vertx-mail-client with Apache License 2.0 | 5 votes |
/** * Tests one response with multiple lines with crlf ends for each line * * Capabilities declared by SMTP server are good example here. */ @Test public void testOneResponseMultiLinesEndwithCRLF(TestContext testContext) { Async async = testContext.async(2); final String ehloBanner = "220 hello from smtp server"; final AtomicBoolean init = new AtomicBoolean(false); final String capaMessage = "250-smtp.gmail.com at your service, [209.132.188.80]\r\n" + "250-AUTH LOGIN PLAIN\r\n" + "250 PIPELINING"; final String expected = "250-smtp.gmail.com at your service, [209.132.188.80]\n" + "250-AUTH LOGIN PLAIN\n" + "250 PIPELINING"; Handler<Buffer> dataHandler = b -> { if (!init.get()) { testContext.assertEquals(ehloBanner, b.toString()); async.countDown(); } else { String message = b.toString(); testContext.assertTrue(StatusCode.isStatusOk(message)); testContext.assertEquals(expected, message); Capabilities capa = new Capabilities(); capa.parseCapabilities(message); testContext.assertTrue(capa.isCapaPipelining()); testContext.assertFalse(capa.isStartTLS()); testContext.assertEquals(2, capa.getCapaAuth().size()); testContext.assertTrue(capa.getCapaAuth().contains("LOGIN")); testContext.assertTrue(capa.getCapaAuth().contains("PLAIN")); async.countDown(); } }; MultilineParser multilineParser = new MultilineParser(dataHandler); multilineParser.setExpected(1); // simulate the ehlo banner on connection multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n")); init.set(true); multilineParser.handle(Buffer.buffer(capaMessage + "\r\n")); }
Example 14
Source File: TelnetTermServerTest.java From vertx-shell with Apache License 2.0 | 5 votes |
@Test public void testOutBinaryFalse(TestContext context) throws Exception { byte[] expected = StandardCharsets.US_ASCII.encode("€").array(); startTelnet(context, new TelnetTermOptions().setOutBinary(false), term -> { term.write("\u20AC"); }); client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false)); client.connect("localhost", server.actualPort()); InputStream in = client.getInputStream(); for (int i = 0;i < expected.length;i++) { context.assertEquals((int)expected[i], in.read()); } }
Example 15
Source File: SMTPConnectionPoolTest.java From vertx-mail-client with Apache License 2.0 | 5 votes |
/** * test that pool.close doesn't close active connections before the operation is finished * * @param testContext */ @Test public final void testClosePoolWaitsToCloseActive(TestContext testContext) { final MailConfig config = configNoSSL().setMaxPoolSize(1); Async async = testContext.async(); SMTPConnectionPool pool = new SMTPConnectionPool(vertx, config); testContext.assertEquals(0, pool.connCount()); pool.getConnection("hostname", result -> { if (result.succeeded()) { log.debug("got connection"); testContext.assertEquals(1, pool.connCount()); pool.close(); testContext.assertEquals(1, pool.connCount()); final SMTPConnection conn = result.result(); conn.returnToPool(); vertx.setTimer(1000, v -> { testContext.assertTrue(conn.isClosed(), "connection was not closed"); testContext.assertEquals(0, pool.connCount()); log.debug("connection is closed"); async.complete(); }); } else { log.info(result.cause()); testContext.fail(result.cause()); } }); }
Example 16
Source File: DB2PreparedQueryCachedTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Test @Override public void testPrepareError(TestContext ctx) { msgVerifier = (err) -> { ctx.assertEquals("The object '" + rule.options().getUser().toUpperCase() + ".DOES_NOT_EXIST' provided is not defined", err.getMessage()); }; super.testPrepareError(ctx); }
Example 17
Source File: CleanupTest.java From vertx-kafka-client with Apache License 2.0 | 4 votes |
private void assertNoThreads(TestContext ctx, String match) { ctx.assertEquals(0, countThreads(match)); }
Example 18
Source File: ProtonClientSslTest.java From vertx-proton with Apache License 2.0 | 4 votes |
private void doHostnameVerificationTestImpl(TestContext context, boolean verifyHost) throws Exception { Async async = context.async(); // Create a server that accept a connection and expects a client connection+session+receiver ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(true); PfxOptions serverPfxOptions = new PfxOptions().setPath(WRONG_HOST_KEYSTORE).setPassword(PASSWORD); serverOptions.setPfxKeyCertOptions(serverPfxOptions); protonServer = createServer(serverOptions, this::handleClientConnectionSessionReceiverOpen); // Connect the client and open a receiver to verify the connection works ProtonClientOptions clientOptions = new ProtonClientOptions(); clientOptions.setSsl(true); PfxOptions clientPfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD); clientOptions.setPfxTrustOptions(clientPfxOptions); // Verify/update the hostname verification settings context.assertEquals(VERIFY_HTTPS, clientOptions.getHostnameVerificationAlgorithm(), "expected host verification to be on by default"); if (!verifyHost) { clientOptions.setHostnameVerificationAlgorithm(NO_VERIFY); } ProtonClient client = ProtonClient.create(vertx); client.connect(clientOptions, "localhost", protonServer.actualPort(), res -> { if (verifyHost) { // Expect connect to fail as server cert hostname doesn't match. context.assertFalse(res.succeeded(), "expected connect to fail"); LOG.trace("Connect failed"); async.complete(); } else { // Expect connect to succeed as verification is disabled context.assertTrue(res.succeeded(), "expected connect to succeed"); LOG.trace("Connect succeeded"); ProtonConnection connection = res.result(); connection.open(); ProtonReceiver receiver = connection.createReceiver("some-address"); receiver.openHandler(recvResult -> { context.assertTrue(recvResult.succeeded()); LOG.trace("Client receiver open"); async.complete(); }).open(); } }); async.awaitSuccess(); }
Example 19
Source File: SchemaRegistrarTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 4 votes |
@Test @Ignore("Need to rewrite test so it waits for the results of CompositeFuture in publishAll calls") public void should_Manage_Schema_Registration_And_Close_Properly2(TestContext context) { Async async = context.async(6); context.assertNotNull(schemaRegistrar.getPublisherId()); schemaRegistrar = SchemaRegistrar.create(vertx, "thePublisherId"); context.assertEquals("thePublisherId", schemaRegistrar.getPublisherId()); ServiceDiscovery discovery = schemaRegistrar.getOrCreateDiscovery(options); context.assertNotNull(discovery); context.assertNotNull(schemaRegistrar.registrations()); context.assertEquals(0, schemaRegistrar.registrations().size()); // Publish 1 schemaPublisher.publish(options, droidsSchema, rh -> { context.assertTrue(rh.succeeded()); context.assertEquals(1, schemaPublisher.registeredSchemas().size()); async.countDown(); // Publish 2 schemaPublisher.publish(options, starWarsSchema, rh2 -> { context.assertTrue(rh2.succeeded()); context.assertEquals(2, schemaPublisher.registeredSchemas().size()); async.countDown(); // Re-publish 1 and 2. No change, already published schemaPublisher.publish(options, droidsSchema, rh3 -> { context.assertTrue(rh3.succeeded()); context.assertEquals(2, schemaPublisher.registeredSchemas().size()); async.countDown(); // Publish 1 and 2 to different repository. Creates 2 new registrations 1' and 2' schemaPublisher.publishAll( new ServiceDiscoveryOptions(options).setName("theOtherRegistry"), rh4 -> { context.assertTrue(rh4.succeeded()); context.assertEquals(4, schemaPublisher.registeredSchemas().size()); async.countDown(); // Unpublish 1. Discovery still in use schemaPublisher.unpublish(schemaPublisher.registeredSchemas().get(0), rh5 -> { context.assertTrue(rh5.succeeded()); context.assertEquals(3, schemaPublisher.registeredSchemas().size()); context.assertEquals(2, schemaPublisher.managedDiscoveries().size()); async.countDown(); // Unpublish 2. Discovery now closed schemaPublisher.unpublish(schemaPublisher.registeredSchemas().get(0), rh6 -> { context.assertTrue(rh6.succeeded()); context.assertEquals(2, schemaPublisher.registeredSchemas().size()); context.assertEquals(1, schemaPublisher.managedDiscoveries().size()); async.countDown(); }); }); }, starWarsSchema, droidsSchema); }); }); }); }
Example 20
Source File: CompositeIdTest.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
private void assertThatPigsAreEqual(TestContext context, GuineaPig expected, GuineaPig actual) { context.assertNotNull( actual ); context.assertEquals( expected.getId(), actual.getId() ); context.assertEquals( expected.getName(), actual.getName() ); context.assertEquals( expected.getWeight(), actual.getWeight() ); }