aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/berzerkula/builddb/repositories/AppUserRepositoryTest.java
blob: 5be591ffb3375667a29b65f20bff0592259a5f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package org.berzerkula.builddb.repositories;

import org.assertj.core.api.Assertions;
import org.berzerkula.builddb.BuilddbConstants;
import org.berzerkula.builddb.models.AppUser;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class AppUserRepositoryTest {

    @Autowired AppUserRepository appUserRepository;

    @Test
    void testCreateReadDelete() {

        AppUser appUser = new AppUser("John", "Doe", "john.doe@test.com", "", "",
                "password", BuilddbConstants.ROLE_CLIENT);

        appUserRepository.save(appUser);

        Iterable<AppUser> appUsers = appUserRepository.findAll();
        Assertions.assertThat(appUsers).extracting(AppUser::getFirstName).containsOnly("John");

        appUserRepository.deleteAll();
        Assertions.assertThat(appUserRepository.findAll()).isEmpty();
    }

}