Skip to content

Commit

Permalink
fix: fixed build tests MessageServiceImplTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Troha7 committed Feb 26, 2024
1 parent 9278b2f commit 5d0226c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.chat.yourway.integration.service.impl;

import static com.github.springtestdbunit.annotation.DatabaseOperation.CLEAN_INSERT;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.chat.yourway.exception.MessageHasAlreadyReportedException;
import com.chat.yourway.integration.extension.PostgresExtension;
import com.chat.yourway.integration.extension.RedisExtension;
import com.chat.yourway.repository.ContactRepository;
import com.chat.yourway.repository.MessageRepository;
import com.chat.yourway.service.MessageServiceImpl;
import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseOperation;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -22,10 +25,6 @@
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;

@ExtendWith({PostgresExtension.class, RedisExtension.class})
@SpringBootTest
@TestExecutionListeners(
Expand All @@ -37,21 +36,23 @@
MockitoTestExecutionListener.class,
ResetMocksTestExecutionListener.class
})
@DatabaseSetup(value = {
"/dataset/mockdb/topic.xml",
"/dataset/mockdb/message.xml",
"/dataset/mockdb/contact.xml",
"/dataset/mockdb/contact_message_report.xml"},
type = CLEAN_INSERT)
public class MessageServiceImplTest {
@Autowired ContactRepository contactRepository;
@Autowired MessageRepository messageRepository;
@Autowired MessageServiceImpl messageService;

@Test
@DisplayName("should save report to message when user makes report")
@DatabaseSetup(value = "/dataset/report-to-message-dataset.xml", type = DatabaseOperation.CLEAN_INSERT)
@DatabaseTearDown(
value = "/dataset/report-to-message-dataset.xml",
type = DatabaseOperation.DELETE)
public void shouldSaveReportToMessage_WhenUserMakesReport() {
// Given
var messageId = 2;
var email = "user3@gmail.com";
var messageId = 101;
var email = "oleg@gmail.com";

// When
messageService.reportMessageById(messageId, email);
Expand All @@ -67,14 +68,10 @@ public void shouldSaveReportToMessage_WhenUserMakesReport() {

@Test
@DisplayName("should delete message when user makes report and message reached max attempts")
@DatabaseSetup(value = "/dataset/report-to-message-dataset.xml", type = DatabaseOperation.CLEAN_INSERT)
@DatabaseTearDown(
value = "/dataset/report-to-message-dataset.xml",
type = DatabaseOperation.DELETE)
public void shouldDeleteMessage_WhenUserMakesReportAndMessageReachedMaxAttempts() {
// Given
var messageId = 1;
var email = "user3@gmail.com";
var messageId = 100;
var email = "oleg@gmail.com";

// When
messageService.reportMessageById(messageId, email);
Expand All @@ -88,14 +85,10 @@ public void shouldDeleteMessage_WhenUserMakesReportAndMessageReachedMaxAttempts(

@Test
@DisplayName("should throw MessageHasAlreadyReportedException when user makes report again")
@DatabaseSetup(value = "/dataset/report-to-message-dataset.xml", type = DatabaseOperation.CLEAN_INSERT)
@DatabaseTearDown(
value = "/dataset/report-to-message-dataset.xml",
type = DatabaseOperation.DELETE)
public void shouldThrowMessageHasAlreadyReportedException_WhenUserMakesReportAgain() {
// Given
var messageId = 1;
var email = "user2@gmail.com";
var messageId = 100;
var email = "anton@gmail.com";

// When
// Then
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/dataset/mockdb/contact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@
avatar_id="7"
is_permitted_sending_private_message="true"
/>
<contact
id="1113"
nickname="Oleg"
password="$2a$10$aerCnzmFriFrD2XqAgd8Huc/ywG/me8s/t4jC/eH8GlIaR3RcABZ2"
is_active="true"
is_private="true"
email="[email protected]"
role="USER"
avatar_id="6"
is_permitted_sending_private_message="true"
/>
</dataset>
69 changes: 0 additions & 69 deletions src/test/resources/dataset/report-to-message-dataset.xml

This file was deleted.

0 comments on commit 5d0226c

Please sign in to comment.