use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class JacksonSerializerUTests method Should_SerializeAnAuditAsJson.
@Test
public void Should_SerializeAnAuditAsJson() throws URISyntaxException, IOException {
DtoMapper mapper = new DtoMapper();
GraviteeContext context = GraviteeContext.defaultContext("acme");
Node node = new DummyNode("node-id", "main.srv.local");
AuditMessageValueDto auditMessageValueDto = mapper.map(AuditValueFactory.createAudit(), context, node);
JacksonSerializer<AuditMessageValueDto> serializer = new JacksonSerializer<>();
byte[] bytes = serializer.serialize("topic", auditMessageValueDto);
URL resource = JacksonSerializerUTests.class.getResource("/json/audit.json");
byte[] expected = Files.readAllBytes(Paths.get(resource.toURI()));
assertEquals(new String(expected, StandardCharsets.UTF_8), new String(bytes, StandardCharsets.UTF_8));
}
use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class DtoMapperUTests method Should_MapAuditToAuditDto.
@Test
public void Should_MapAuditToAuditDto() {
// arrange
DtoMapper mapper = new DtoMapper();
GraviteeContext context = GraviteeContext.defaultContext("domain");
Node nodeMock = new DummyNode("first", "first.srv.local");
Audit audit = AuditValueFactory.createAudit();
// act
AuditMessageValueDto dto = mapper.map(audit, context, nodeMock);
// assert
Assert.assertEquals("id", dto.getId());
Assert.assertEquals("reference id", dto.getReferenceId());
this.assertEquals(ReferenceType.APPLICATION, dto.getReferenceType());
Assert.assertEquals(Instant.EPOCH, dto.getTimestamp());
Assert.assertEquals("transaction id", dto.getTransactionId());
Assert.assertEquals("type", dto.getType());
Assert.assertEquals("status", dto.getStatus());
this.assertEquals(audit.getActor(), dto.getActor());
this.assertEquals(audit.getTarget(), dto.getTarget());
Assert.assertEquals(context.getOrganizationId(), dto.getOrganizationId());
Assert.assertEquals(context.getEnvironmentId(), dto.getEnvironmentId());
Assert.assertEquals("first", dto.getNodeId());
Assert.assertEquals("first.srv.local", dto.getNodeHostname());
this.assertEquals(audit.getAccessPoint(), dto.getAccessPoint());
}
use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
logger.info("Initializing reporters for domain {}", domain.getName());
logger.info("\t Starting reporter verticle for domain {}", domain.getName());
Single<String> deployment = RxHelper.deployVerticle(vertx, applicationContext.getBean(AuditReporterVerticle.class));
deployment.subscribe(id -> {
// Deployed
deploymentId = id;
// Start reporters
reporterRepository.findByDomain(domain.getId()).toList().flatMap(reporters -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporters, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReportersContext -> {
if (!tupleReportersContext.getT1().isEmpty()) {
tupleReportersContext.getT1().forEach(reporter -> {
startReporterProvider(reporter, tupleReportersContext.getT2());
});
logger.info("Reporters loaded for domain {}", domain.getName());
} else {
logger.info("\tThere is no reporter to start");
}
}, err -> {
logger.error("Reporter service can not be started", err);
});
}, err -> {
// Could not deploy
logger.error("Reporter service can not be started", err);
});
}
Aggregations