Search in sources :

Example 1 with MyUser

use of org.baeldung.persistence.model.MyUser in project tutorials by eugenp.

the class MyUserService method registerNewUserAccount.

public MyUser registerNewUserAccount(final MyUserDto accountDto) throws Exception {
    if (usernameExists(accountDto.getUsername())) {
        throw new Exception("There is an account with that username: " + accountDto.getUsername());
    }
    final MyUser user = new MyUser();
    user.setUsername(accountDto.getUsername());
    user.setPassword(passwordEncoder.encode(accountDto.getPassword()));
    return myUserDAO.save(user);
}
Also used : MyUser(org.baeldung.persistence.model.MyUser)

Example 2 with MyUser

use of org.baeldung.persistence.model.MyUser in project tutorials by eugenp.

the class JPAQuerydslIntegrationTest method init.

@Before
public void init() {
    userJohn = new MyUser();
    userJohn.setFirstName("john");
    userJohn.setLastName("doe");
    userJohn.setEmail("john@doe.com");
    userJohn.setAge(22);
    repo.save(userJohn);
    userTom = new MyUser();
    userTom.setFirstName("tom");
    userTom.setLastName("doe");
    userTom.setEmail("tom@doe.com");
    userTom.setAge(26);
    repo.save(userTom);
}
Also used : MyUser(org.baeldung.persistence.model.MyUser) Before(org.junit.Before)

Example 3 with MyUser

use of org.baeldung.persistence.model.MyUser in project tutorials by eugenp.

the class JPAQuerydslIntegrationTest method givenLastAndAge_whenGettingListOfUsers_thenCorrect.

@Test
public void givenLastAndAge_whenGettingListOfUsers_thenCorrect() {
    final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("lastName", ":", "doe").with("age", ">", "25");
    final Iterable<MyUser> results = repo.findAll(builder.build());
    assertThat(results, contains(userTom));
    assertThat(results, not(contains(userJohn)));
}
Also used : MyUser(org.baeldung.persistence.model.MyUser) MyUserPredicatesBuilder(org.baeldung.persistence.dao.MyUserPredicatesBuilder) Test(org.junit.Test)

Example 4 with MyUser

use of org.baeldung.persistence.model.MyUser in project tutorials by eugenp.

the class JPAQuerydslIntegrationTest method givenPartialFirst_whenGettingListOfUsers_thenCorrect.

@Test
public void givenPartialFirst_whenGettingListOfUsers_thenCorrect() {
    final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "jo");
    final Iterable<MyUser> results = repo.findAll(builder.build());
    assertThat(results, contains(userJohn));
    assertThat(results, not(contains(userTom)));
}
Also used : MyUser(org.baeldung.persistence.model.MyUser) MyUserPredicatesBuilder(org.baeldung.persistence.dao.MyUserPredicatesBuilder) Test(org.junit.Test)

Example 5 with MyUser

use of org.baeldung.persistence.model.MyUser in project tutorials by eugenp.

the class MyUserLiveTest method givenPartialLastName_whenGettingListOfUsers_thenCorrect.

@Test
public void givenPartialLastName_whenGettingListOfUsers_thenCorrect() {
    final Response response = givenAuth().get(URL_PREFIX + "?lastName=do");
    final MyUser[] result = response.as(MyUser[].class);
    assertEquals(result.length, 2);
}
Also used : Response(io.restassured.response.Response) MyUser(org.baeldung.persistence.model.MyUser) Test(org.junit.Test)

Aggregations

MyUser (org.baeldung.persistence.model.MyUser)13 Test (org.junit.Test)9 MyUserPredicatesBuilder (org.baeldung.persistence.dao.MyUserPredicatesBuilder)5 Response (io.restassured.response.Response)4 PathBuilder (com.querydsl.core.types.dsl.PathBuilder)1 StringPath (com.querydsl.core.types.dsl.StringPath)1 Query (javax.persistence.Query)1 Before (org.junit.Before)1