Skip to content

Commit

Permalink
[Hexlet#106] add test getPageAccountByWorkspaceName
Browse files Browse the repository at this point in the history
  • Loading branch information
12oprs authored and alexeiak committed Sep 13, 2022
1 parent f7f308f commit aed7a5a
Showing 1 changed file with 20 additions and 1 deletion.
Expand Up @@ -8,6 +8,7 @@
import io.hexlet.typoreporter.domain.typo.Typo;
import io.hexlet.typoreporter.domain.workspace.Workspace;
import io.hexlet.typoreporter.test.DBUnitEnumPostgres;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
Expand All @@ -17,6 +18,10 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -35,7 +40,7 @@
@Transactional
@DBRider
@DBUnit(caseInsensitiveStrategy = LOWERCASE, dataTypeFactoryClass = DBUnitEnumPostgres.class, cacheConnection = false)
@DataSet(value = {"accounts.yml"})
@DataSet(value = {"accounts.yml", "workspaces.yml"})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class AccountRepositoryIT {

Expand All @@ -47,6 +52,9 @@ public class AccountRepositoryIT {
@Autowired
private AccountRepository accountRepository;

@Autowired
private WorkspaceRepository workspaceRepository;

@DynamicPropertySource
static void datasourceProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl);
Expand All @@ -68,4 +76,15 @@ void getAccountByEmail(final String email) {
void getAccountByEmailNotExist(final String email) {
assertThat(accountRepository.findAccountByEmail(email)).isEmpty();
}

@Test
void getPageAccountByWorkspaceName() {
Workspace wks = workspaceRepository.findAll().stream().findFirst().get();
accountRepository.findAll().forEach(account -> account.setWorkspace(wks));
Pageable pageable = PageRequest.of(0, 10, Sort.by("id"));
Page<Account> page = accountRepository.findPageAccountByWorkspaceName(pageable, wks.getName());
assertThat(page).isNotEmpty();
assertThat(page.getTotalElements()).isEqualTo(accountRepository.count());
assertThat(page.getTotalPages()).isEqualTo(1);
}
}

0 comments on commit aed7a5a

Please sign in to comment.