use of io.vertx.core.Context in project hono by eclipse.
the class FileBasedRegistrationServiceTest method testPeriodicSafeJobIsNotScheduledIfSavingIfDisabled.
/**
* Verifies that setting the <em>saveToFile</em> configuration property to <em>false</em> prevents
* the registration service to write its content to the file system periodically.
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testPeriodicSafeJobIsNotScheduledIfSavingIfDisabled(final TestContext ctx) {
props.setSaveToFile(false);
when(fileSystem.existsBlocking(props.getFilename())).thenReturn(Boolean.TRUE);
doAnswer(invocation -> {
Handler handler = invocation.getArgument(1);
handler.handle(Future.failedFuture("malformed file"));
return null;
}).when(fileSystem).readFile(eq(props.getFilename()), any(Handler.class));
Async startup = ctx.async();
Future<Void> startupTracker = Future.future();
startupTracker.setHandler(ctx.asyncAssertSuccess(done -> {
startup.complete();
}));
registrationService.doStart(startupTracker);
startup.await();
verify(vertx, never()).setPeriodic(anyLong(), any(Handler.class));
}
use of io.vertx.core.Context in project hono by eclipse.
the class FileBasedTenantServiceTest method testRemoveTenantsSucceeds.
/**
* Verifies that the service removes tenants for a given tenantId.
*
* @param ctx The vert.x test context.
*/
@Test
public void testRemoveTenantsSucceeds(final TestContext ctx) {
final Async add = ctx.async();
addTenant(svc, ctx, add, "tenant");
add.await();
svc.remove("tenant", ctx.asyncAssertSuccess(s -> {
assertThat(s.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
assertTenantDoesNotExist(svc, "tenant", ctx);
}));
}
use of io.vertx.core.Context in project hono by eclipse.
the class FileBasedTenantServiceTest method testUpdateTenantsFailsIfModificationIsDisabled.
/**
* Verifies that the <em>modificationEnabled</em> property prevents updating an existing entry.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUpdateTenantsFailsIfModificationIsDisabled(final TestContext ctx) {
// GIVEN a service containing a set of tenants
// that has been configured to not allow modification of entries
props.setModificationEnabled(false);
// WHEN trying to update the tenant
svc.update("tenant", new JsonObject(), ctx.asyncAssertSuccess(s -> {
// THEN the update fails
ctx.assertEquals(HttpURLConnection.HTTP_FORBIDDEN, s.getStatus());
}));
}
use of io.vertx.core.Context in project hono by eclipse.
the class FileBasedTenantServiceTest method testDoStartIgnoresMalformedJson.
/**
* Verifies that the tenant service successfully starts up even if
* the file to read tenants from contains malformed JSON.
*
* @param ctx The vert.x context.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testDoStartIgnoresMalformedJson(final TestContext ctx) {
// GIVEN a tenant service configured to read data from a file
// that contains malformed JSON
props.setFilename(FILE_NAME);
when(fileSystem.existsBlocking(FILE_NAME)).thenReturn(Boolean.TRUE);
doAnswer(invocation -> {
final Buffer data = mock(Buffer.class);
when(data.getBytes()).thenReturn("NO JSON".getBytes(StandardCharsets.UTF_8));
final Handler handler = invocation.getArgument(1);
handler.handle(Future.succeededFuture(data));
return null;
}).when(fileSystem).readFile(eq(props.getFilename()), any(Handler.class));
// WHEN starting the service
final Future<Void> startupTracker = Future.future();
startupTracker.setHandler(ctx.asyncAssertSuccess(started -> {
// THEN startup succeeds
}));
svc.doStart(startupTracker);
}
use of io.vertx.core.Context in project hono by eclipse.
the class FileBasedTenantServiceTest method testDoStartLoadsTenants.
/**
* Verifies that tenants are successfully loaded from file during startup.
*
* @param ctx The test context.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testDoStartLoadsTenants(final TestContext ctx) {
// GIVEN a service configured with a file name
props.setFilename(FILE_NAME);
when(fileSystem.existsBlocking(props.getFilename())).thenReturn(Boolean.TRUE);
doAnswer(invocation -> {
final Buffer data = DeviceRegistryTestUtils.readFile(FILE_NAME);
final Handler handler = invocation.getArgument(1);
handler.handle(Future.succeededFuture(data));
return null;
}).when(fileSystem).readFile(eq(props.getFilename()), any(Handler.class));
// WHEN the service is started
final Async startup = ctx.async();
final Future<Void> startFuture = Future.future();
startFuture.setHandler(ctx.asyncAssertSuccess(s -> {
startup.complete();
}));
svc.doStart(startFuture);
// THEN the credentials from the file are loaded
startup.await();
assertTenantExists(svc, Constants.DEFAULT_TENANT, ctx);
}
Aggregations