use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenUsingOrderBy_thenResultsShouldBeOrdered.
@Test
public void whenUsingOrderBy_thenResultsShouldBeOrdered() {
QUser user = QUser.user;
List<User> users = queryFactory.selectFrom(user).orderBy(user.login.asc()).fetch();
assertEquals(users.size(), 4);
assertEquals(users.get(0).getLogin(), "Ash");
assertEquals(users.get(1).getLogin(), "Bishop");
assertEquals(users.get(2).getLogin(), "Call");
assertEquals(users.get(3).getLogin(), "David");
}
use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenUpdating_thenTheRecordShouldChange.
@Test
public void whenUpdating_thenTheRecordShouldChange() {
QUser user = QUser.user;
queryFactory.update(user).where(user.login.eq("Ash")).set(user.login, "Ash2").set(user.disabled, true).execute();
em.getTransaction().commit();
em.getTransaction().begin();
assertEquals(Boolean.TRUE, queryFactory.select(user.disabled).from(user).where(user.login.eq("Ash2")).fetchOne());
}
use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenFindByLogin_thenShouldReturnUser.
@Test
public void whenFindByLogin_thenShouldReturnUser() {
QUser user = QUser.user;
User aUser = queryFactory.selectFrom(user).where(user.login.eq("David")).fetchOne();
assertNotNull(aUser);
assertEquals(aUser.getLogin(), "David");
}
use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenDeleting_thenTheRecordShouldBeAbsent.
@Test
public void whenDeleting_thenTheRecordShouldBeAbsent() {
QUser user = QUser.user;
queryFactory.delete(user).where(user.login.eq("Bishop")).execute();
em.getTransaction().commit();
em.getTransaction().begin();
assertNull(queryFactory.selectFrom(user).where(user.login.eq("Bishop")).fetchOne());
}
use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenJoiningWithCondition_thenResultCountShouldMatch.
@Test
public void whenJoiningWithCondition_thenResultCountShouldMatch() {
QUser user = QUser.user;
QBlogPost blogPost = QBlogPost.blogPost;
List<User> users = queryFactory.selectFrom(user).innerJoin(user.blogPosts, blogPost).on(blogPost.title.eq("Hello World!")).fetch();
assertEquals(2, users.size());
}