use of io.vertx.ext.mongo.MongoClient in project hono by eclipse.
the class MongoDbBasedTenantDaoTest method testCreateIndicesDropsObsoleteIndex.
/**
* Verifies that when creating indices for the Tenant collection, an existing unique index on
* <em>tenant.trusted-ca.subject-dn</em> is getting dropped.
*
* @param ctx The vert.x test context.
* @param vertx The vert.x instance to run on.
*/
@Test
public void testCreateIndicesDropsObsoleteIndex(final VertxTestContext ctx, final Vertx vertx) {
// GIVEN a set of existing indices including a unique, partial index on tenant.trusted-ca.subject-dn
final Buffer existingIndices = vertx.fileSystem().readFileBlocking("target/test-classes/indexes.json");
when(mongoClient.createIndexWithOptions(anyString(), any(JsonObject.class), any(IndexOptions.class))).thenReturn(Future.succeededFuture());
when(mongoClient.dropIndex(anyString(), anyString())).thenReturn(Future.succeededFuture());
when(mongoClient.listIndexes(anyString())).thenReturn(Future.succeededFuture(existingIndices.toJsonArray()));
// WHEN creating indices for the tenant collection
dao.createIndices().onComplete(ctx.succeeding(ok -> {
ctx.verify(() -> {
// THEN the unique index is being dropped
verify(mongoClient).dropIndex(anyString(), eq("tenant.trusted-ca.subject-dn_1"));
});
ctx.completeNow();
}));
}
use of io.vertx.ext.mongo.MongoClient in project hono by eclipse.
the class MongoDbBasedDeviceDaoTest method testUpdateSetsLastUpdate.
/**
* Verifies that the DAO sets the new version and last update time but also keeps the original
* creation date when updating a device.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUpdateSetsLastUpdate(final VertxTestContext ctx) {
final var existingRecord = DeviceDto.forRead(DeviceDto::new, "tenantId", "deviceId", new Device(), false, false, Instant.now().minusSeconds(60).truncatedTo(ChronoUnit.SECONDS), null, "initial-version");
when(mongoClient.findOneAndReplaceWithOptions(anyString(), any(JsonObject.class), any(JsonObject.class), any(FindOptions.class), any(UpdateOptions.class))).thenReturn(Future.succeededFuture(new JsonObject().put(DeviceDto.FIELD_VERSION, "new-version")));
final var dto = DeviceDto.forUpdate(() -> existingRecord, "tenantId", "deviceId", new Device(), "new-version");
dao.update(dto, Optional.of(existingRecord.getVersion()), NoopSpan.INSTANCE.context()).onComplete(ctx.succeeding(newVersion -> {
ctx.verify(() -> {
final var document = ArgumentCaptor.forClass(JsonObject.class);
verify(mongoClient).findOneAndReplaceWithOptions(eq("devices"), any(JsonObject.class), document.capture(), any(FindOptions.class), any(UpdateOptions.class));
MongoDbBasedTenantDaoTest.assertUpdateDocumentContainsStatusProperties(document.getValue(), "new-version", existingRecord.getCreationTime());
});
ctx.completeNow();
}));
}
use of io.vertx.ext.mongo.MongoClient in project hono by eclipse.
the class MongoDbBasedCredentialsDaoTest method testUpdateSetsLastUpdate.
/**
* Verifies that the DAO sets the new version and last update time but also keeps the original
* creation date when updating credentials.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUpdateSetsLastUpdate(final VertxTestContext ctx) {
final var existingRecord = CredentialsDto.forRead("tenantId", "deviceId", List.of(), Instant.now().minusSeconds(60).truncatedTo(ChronoUnit.SECONDS), null, "initial-version");
when(mongoClient.findOneAndReplaceWithOptions(anyString(), any(JsonObject.class), any(JsonObject.class), any(FindOptions.class), any(UpdateOptions.class))).thenReturn(Future.succeededFuture(new JsonObject().put(DeviceDto.FIELD_VERSION, "new-version")));
final var dto = CredentialsDto.forUpdate(() -> existingRecord, List.of(), "new-version");
dao.update(dto, Optional.of(existingRecord.getVersion()), NoopSpan.INSTANCE.context()).onComplete(ctx.succeeding(newVersion -> {
ctx.verify(() -> {
final var document = ArgumentCaptor.forClass(JsonObject.class);
verify(mongoClient).findOneAndReplaceWithOptions(eq("credentials"), any(JsonObject.class), document.capture(), any(FindOptions.class), any(UpdateOptions.class));
MongoDbBasedTenantDaoTest.assertUpdateDocumentContainsStatusProperties(document.getValue(), "new-version", existingRecord.getCreationTime());
});
ctx.completeNow();
}));
}
use of io.vertx.ext.mongo.MongoClient in project hono by eclipse.
the class MongoDbBasedTenantDaoTest method testUpdateSetsLastUpdate.
/**
* Verifies that the DAO sets the new version and last update time but also keeps the original
* creation date when updating a tenant.
*
* @param ctx The vert.x test context.
*/
@Test
public void testUpdateSetsLastUpdate(final VertxTestContext ctx) {
final var existingRecord = TenantDto.forRead("tenantId", new Tenant(), Instant.now().minusSeconds(60).truncatedTo(ChronoUnit.SECONDS), null, "initial-version");
when(mongoClient.findOneAndReplaceWithOptions(anyString(), any(JsonObject.class), any(JsonObject.class), any(FindOptions.class), any(UpdateOptions.class))).thenReturn(Future.succeededFuture(new JsonObject().put(TenantDto.FIELD_VERSION, "new-version")));
final var dto = TenantDto.forUpdate(() -> existingRecord, new Tenant(), "new-version");
dao.update(dto, Optional.of(existingRecord.getVersion()), NoopSpan.INSTANCE.context()).onComplete(ctx.succeeding(newVersion -> {
ctx.verify(() -> {
assertThat(newVersion).isEqualTo("new-version");
final var document = ArgumentCaptor.forClass(JsonObject.class);
verify(mongoClient).findOneAndReplaceWithOptions(eq("tenants"), any(JsonObject.class), document.capture(), any(FindOptions.class), any(UpdateOptions.class));
MongoDbBasedTenantDaoTest.assertUpdateDocumentContainsStatusProperties(document.getValue(), "new-version", existingRecord.getCreationTime());
});
ctx.completeNow();
}));
}
use of io.vertx.ext.mongo.MongoClient in project vertx-auth by vert-x3.
the class AuthMongoExamples method example5.
public void example5(Vertx vertx, JsonObject mongoClientConfig) {
MongoClient client = MongoClient.createShared(vertx, mongoClientConfig);
JsonObject authProperties = new JsonObject();
MongoAuth authProvider = MongoAuth.create(client, authProperties);
authProvider.setHashAlgorithm(HashAlgorithm.PBKDF2);
}
Aggregations