Search in sources :

Example 6 with MyUser

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

the class MyUserDAO method findByUsername.

public MyUser findByUsername(final String username) {
    final Query query = entityManager.createQuery("from MyUser where username=:username", MyUser.class);
    query.setParameter("username", username);
    final List<MyUser> result = query.getResultList();
    if (result != null && result.size() > 0) {
        return result.get(0);
    } else
        return null;
}
Also used : MyUser(org.baeldung.persistence.model.MyUser) Query(javax.persistence.Query)

Example 7 with MyUser

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

the class MyUserLiveTest method givenFirstName_whenGettingListOfUsers_thenCorrect.

@Test
public void givenFirstName_whenGettingListOfUsers_thenCorrect() {
    final Response response = givenAuth().get(URL_PREFIX + "?firstName=john");
    final MyUser[] result = response.as(MyUser[].class);
    assertEquals(result.length, 1);
    assertEquals(result[0].getEmail(), userJohn.getEmail());
}
Also used : Response(io.restassured.response.Response) MyUser(org.baeldung.persistence.model.MyUser) Test(org.junit.Test)

Example 8 with MyUser

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

the class MyUserLiveTest method givenEmail_whenGettingListOfUsers_thenIgnored.

@Test
public void givenEmail_whenGettingListOfUsers_thenIgnored() {
    final Response response = givenAuth().get(URL_PREFIX + "?email=john");
    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)

Example 9 with MyUser

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

the class MyUserLiveTest method whenGettingListOfUsers_thenCorrect.

@Test
public void whenGettingListOfUsers_thenCorrect() {
    final Response response = givenAuth().get(URL_PREFIX);
    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)

Example 10 with MyUser

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

the class JPAQuerydslIntegrationTest method givenWrongFirstAndLast_whenGettingListOfUsers_thenCorrect.

@Test
public void givenWrongFirstAndLast_whenGettingListOfUsers_thenCorrect() {
    final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "adam").with("lastName", ":", "fox");
    final Iterable<MyUser> results = repo.findAll(builder.build());
    assertThat(results, emptyIterable());
}
Also used : MyUser(org.baeldung.persistence.model.MyUser) MyUserPredicatesBuilder(org.baeldung.persistence.dao.MyUserPredicatesBuilder) 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