initial compilation fixes

This commit is contained in:
eugenp
2014-05-10 15:33:07 +03:00
parent 8f86fe971a
commit a5c1d774ec
3 changed files with 43 additions and 58 deletions
@@ -1,7 +1,9 @@
package org.baeldung.persistence.service;
import static org.junit.Assert.*;
import static org.junit.Assert.assertNull;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
@@ -11,11 +13,13 @@ import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import com.google.common.collect.Lists;
import org.baeldung.persistence.model.Bar;
import org.baeldung.persistence.model.Foo;
import org.junit.BeforeClass;
import org.junit.Test;
import com.cc.jpa.example.Foo;
import com.cc.jpa.example.Bar;
import com.google.common.collect.Lists;
public class FooServiceSortingTests {
private static EntityManager entityManager;
@@ -25,7 +29,6 @@ public class FooServiceSortingTests {
@BeforeClass
public static void before() {
emf = Persistence.createEntityManagerFactory("punit");
entityManager = emf.createEntityManager();
entityTransaction = entityManager.getTransaction();
@@ -35,43 +38,36 @@ public class FooServiceSortingTests {
@Test
public final void whenSortingByOneAttributeDefaultOrder_thenPrintSortedResult() {
final String jql = "Select f from Foo as f order by f.id";
final Query sortQuery = entityManager.createQuery(jql);
final List<Foo> fooList = sortQuery.getResultList();
for (final Foo foo : fooList) {
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
}
}
@Test
public final void whenSortingByOneAttributeSetOrder_thenSortedPrintResult() {
final String jql = "Select f from Foo as f order by f.id desc";
final Query sortQuery = entityManager.createQuery(jql);
final List<Foo> fooList = sortQuery.getResultList();
for (final Foo foo : fooList) {
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
}
}
@Test
public final void whenSortingByTwoAttributes_thenPrintSortedResult() {
final String jql = "Select f from Foo as f order by f.name asc, f.id desc";
final Query sortQuery = entityManager.createQuery(jql);
final List<Foo> fooList = sortQuery.getResultList();
for (final Foo foo : fooList) {
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
}
}
@Test
public final void whenSortingFooByBar_thenBarsSorted() {
final String jql = "Select f from Foo as f order by f.name, f.bar.id";
final Query barJoinQuery = entityManager.createQuery(jql);
final List<Foo> fooList = barJoinQuery.getResultList();
@@ -82,7 +78,6 @@ public class FooServiceSortingTests {
@Test
public final void whenSortinfBar_thenPrintBarsSortedWithFoos() {
final String jql = "Select b from Bar as b order by b.id";
final Query barQuery = entityManager.createQuery(jql);
final List<Bar> barList = barQuery.getResultList();
@@ -92,12 +87,10 @@ public class FooServiceSortingTests {
System.out.println("FooName:" + foo.getName());
}
}
}
@Test
public final void whenSortingByStringNullLast_thenLastNull() {
final String jql = "Select f from Foo as f order by f.name desc NULLS LAST";
final Query sortQuery = entityManager.createQuery(jql);
final List<Foo> fooList = sortQuery.getResultList();
@@ -109,7 +102,6 @@ public class FooServiceSortingTests {
@Test
public final void whenSortingByStringNullFirst_thenFirstNull() {
final Foo nullNameFoo = new Foo();
nullNameFoo.setName(null);
@@ -133,7 +125,6 @@ public class FooServiceSortingTests {
@Test
public final void whenSortingFooWithCriteria_thenPrintSortedFoos() {
criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Foo> criteriaQuery = criteriaBuilder.createQuery(Foo.class);
final Root<Foo> from = criteriaQuery.from(Foo.class);
@@ -144,12 +135,10 @@ public class FooServiceSortingTests {
for (final Foo foo : fooList) {
System.out.println("Name:" + foo.getName() + "--------Id:" + foo.getId());
}
}
@Test
public final void whenSortingFooWithCriteriaAndMultipleAttributes_thenPrintSortedFoos() {
criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Foo> criteriaQuery = criteriaBuilder.createQuery(Foo.class);
final Root<Foo> from = criteriaQuery.from(Foo.class);