void expectNewTemplateAndAttributesAreCreatedIfNotExists()

in ddm-notification-service/src/it/java/com/epam/digital/data/platform/notification/service/SaveDiiaNotificationTemplateServiceTest.java [86:132]


  void expectNewTemplateAndAttributesAreCreatedIfNotExists() {
    var inputDto =
        SaveNotificationTemplateInputDto.builder()
            .title(TITLE)
            .content("some long text")
            .attributes(
                List.of(
                    new NotificationTemplateAttributeDto(ACTION_TYPE, "DiiaActionType"),
                    new NotificationTemplateAttributeDto(TEMPLATE_TYPE, "DiiaTemplateType"),
                    new NotificationTemplateAttributeDto(SHORT_TEXT, "DiiaShortText")
                )).build();

    diiaWireMock.
        stubFor(post(urlEqualTo("/api/v1/notification/template"))
            .willReturn(aResponse()
                .withStatus(200)
                .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
                .withBody("{\"templateId\":\"12345\"}")
            ));

    service.save(CHANNEL, NAME_1, inputDto);

    var templateTableContent = notificationTemplateRepository
        .findByNameAndChannel(NAME_1, CHANNEL).get();
    assertThat(templateTableContent).isNotNull();
    assertThat(templateTableContent.getId()).isNotNull();
    assertThat(templateTableContent.getChannel()).isEqualTo(CHANNEL);
    assertThat(templateTableContent.getName()).isEqualTo(NAME_1);
    assertThat(templateTableContent.getTitle()).isEqualTo(TITLE);
    assertThat(templateTableContent.getContent()).isEqualTo(CONTENT);
    assertThat(templateTableContent.getChecksum())
        .isEqualTo("b873ee130819ed542ec8ce28ea74a5830ad17756c55557e5f21e30efbcf57785");
    assertThat(templateTableContent.getCreatedAt()).isNotNull();
    assertThat(templateTableContent.getUpdatedAt()).isNotNull();
    assertThat(templateTableContent.getExtTemplateId()).isEqualTo("12345");
    assertThat(templateTableContent.getExtPublishedAt()).isNotNull();

    var attributesTableContent =
        notificationTemplateAttributeRepository.findByTemplateId(templateTableContent.getId());
    assertThat(attributesTableContent.stream()
        .collect(
            toMap(NotificationTemplateAttribute::getName, NotificationTemplateAttribute::getValue)))
        .containsExactly(
            Map.entry("templateType", "DiiaTemplateType"),
            Map.entry("actionType", "DiiaActionType"),
            Map.entry("shortText", "DiiaShortText"));
  }