@Test public void testCreateWhenResourceCrnIsNotEmpty() { CDPStructuredEvent event = new CDPStructuredRestCallEvent(); CDPOperationDetails operation = new CDPOperationDetails(); operation.setResourceCrn("crn"); event.setOperation(operation); CDPStructuredEventEntity entity = new CDPStructuredEventEntity(); when(conversionService.convert(event, CDPStructuredEventEntity.class)).thenReturn(entity); underTest.create(event); verify(conversionService, Mockito.times(1)).convert(event, CDPStructuredEventEntity.class); verify(structuredEventRepository, Mockito.times(1)).save(entity); }
@Override public void create(CDPStructuredEvent structuredEvent) { LOGGER.info("Stored StructuredEvent type: {}, payload: {}", structuredEvent.getType(), AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(structuredEvent))); ValidationResult validationResult = validate(structuredEvent); if (validationResult.hasError()) { LOGGER.warn(validationResult.getFormattedErrors()); } else { CDPStructuredEventEntity structuredEventEntityEntity = conversionService.convert(structuredEvent, CDPStructuredEventEntity.class); create(structuredEventEntityEntity, structuredEventEntityEntity.getAccountId()); } }
CDPStructuredEventDBService extends AbstractAccountAwareResourceService<CDPStructuredEventEntity> implements CDPStructuredEventService { @Override public void create(CDPStructuredEvent structuredEvent) { LOGGER.info("Stored StructuredEvent type: {}, payload: {}", structuredEvent.getType(), AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(structuredEvent))); ValidationResult validationResult = validate(structuredEvent); if (validationResult.hasError()) { LOGGER.warn(validationResult.getFormattedErrors()); } else { CDPStructuredEventEntity structuredEventEntityEntity = conversionService.convert(structuredEvent, CDPStructuredEventEntity.class); create(structuredEventEntityEntity, structuredEventEntityEntity.getAccountId()); } } }
CDPStructuredEventDBService extends AbstractAccountAwareResourceService<CDPStructuredEventEntity> implements CDPStructuredEventService { @Override public void create(CDPStructuredEvent structuredEvent) { LOGGER.info("Stored StructuredEvent type: {}, payload: {}", structuredEvent.getType(), AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(structuredEvent))); ValidationResult validationResult = validate(structuredEvent); if (validationResult.hasError()) { LOGGER.warn(validationResult.getFormattedErrors()); } else { CDPStructuredEventEntity structuredEventEntityEntity = conversionService.convert(structuredEvent, CDPStructuredEventEntity.class); create(structuredEventEntityEntity, structuredEventEntityEntity.getAccountId()); } }  }
CDPStructuredEventDBService extends AbstractAccountAwareResourceService<CDPStructuredEventEntity> implements CDPStructuredEventService { @Override public void create(CDPStructuredEvent structuredEvent) { LOGGER.info("Stored StructuredEvent type: {}, payload: {}", structuredEvent.getType(), AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(structuredEvent))); ValidationResult validationResult = validate(structuredEvent); if (validationResult.hasError()) { LOGGER.warn(validationResult.getFormattedErrors()); } else { CDPStructuredEventEntity structuredEventEntityEntity = conversionService.convert(structuredEvent, CDPStructuredEventEntity.class); create(structuredEventEntityEntity, structuredEventEntityEntity.getAccountId()); } }  @Override void create(CDPStructuredEvent structuredEvent); boolean isEnabled(); @Override AccountAwareResourceRepository<CDPStructuredEventEntity, Long> repository(); @Override Page<T> getPagedEventsOfResource(List<StructuredEventType> eventTypes, String resourceCrn, Pageable pageable); @Override List<T> getEventsOfResource(List<StructuredEventType> eventTypes, String resourceCrn); }
CDPStructuredEventDBService extends AbstractAccountAwareResourceService<CDPStructuredEventEntity> implements CDPStructuredEventService { @Override public void create(CDPStructuredEvent structuredEvent) { LOGGER.info("Stored StructuredEvent type: {}, payload: {}", structuredEvent.getType(), AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(structuredEvent))); ValidationResult validationResult = validate(structuredEvent); if (validationResult.hasError()) { LOGGER.warn(validationResult.getFormattedErrors()); } else { CDPStructuredEventEntity structuredEventEntityEntity = conversionService.convert(structuredEvent, CDPStructuredEventEntity.class); create(structuredEventEntityEntity, structuredEventEntityEntity.getAccountId()); } }  @Override void create(CDPStructuredEvent structuredEvent); boolean isEnabled(); @Override AccountAwareResourceRepository<CDPStructuredEventEntity, Long> repository(); @Override Page<T> getPagedEventsOfResource(List<StructuredEventType> eventTypes, String resourceCrn, Pageable pageable); @Override List<T> getEventsOfResource(List<StructuredEventType> eventTypes, String resourceCrn);  }