package org.dynamicfinder.test.integration.jpa;

import java.util.List;

import javax.persistence.Query;
import javax.persistence.TypedQuery;

import org.dynamicfinder.QueryBuilder;
import org.dynamicfinder.jpa.JpaQueryBuilder;
import org.dynamicfinder.test._entity.Employee;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author xsalefter (xsalefter[at]gmail.com)
 */
public class JpaQueryBuilderSelectIntegrationTest extends AbstractJpaIntegrationTest {

	private static final Logger logger = LoggerFactory.getLogger(JpaQueryBuilderSelectIntegrationTest.class);

	private QueryBuilder queryBuilder;

	@Before
	public void before() {
		this.queryBuilder = new JpaQueryBuilder(Employee.class);
	}

	@Test
	public void selectWithEmptyParameter() {
		logger.debug("#selectWithEmptyParameter()");

		super.entityManager.getTransaction().begin();
		TypedQuery<Employee> query = super.entityManager.
				createQuery(this.queryBuilder.select().getQueryString(), Employee.class);
		Assert.assertNotNull(query);
		List<Employee> result = query.getResultList();
		super.entityManager.getTransaction().commit();

		Assert.assertEquals(200, result.size());
		
	}

	@Test
	public void selectWithDefinedParameters() {
		logger.debug("#selectWithDefinedParameter()");

		queryBuilder.select("id", "firstName");
		String actual = queryBuilder.getQueryString();
		String expected = "select employee.id, employee.firstName from Employee employee";
		Assert.assertEquals(expected, actual);

		super.entityManager.getTransaction().begin();
		Query query = super.entityManager.createQuery(actual);
		Assert.assertNotNull(query);
		@SuppressWarnings("unchecked")
		List<Object[]> result = query.getResultList();
		super.entityManager.getTransaction().commit();

		Assert.assertEquals(200, result.size());
	}

}

@@ -779,31 +779,85 @@
 class);%0A%09%7D%0A%0A
+%09/**%0A%09 * Test for %7B@link QueryBuilder#select()%7D.%0A%09 */%0A
 %09@Test%0A
-
 %09public void
@@ -1292,16 +1292,79 @@
 %0A%09%09%0A%09%7D%0A%0A
+%09/**%0A%09 * Test for %7B@link QueryBuilder#select(String...)%7D.%0A%09 */%0A
 %09@Test%0A%09
@@ -1990,10 +1990,777 @@
 ));%0A%09%7D%0A%0A
+%0A%09/**%0A%09 * Test for %7B@link QueryBuilder#select(%22name as personName%22, %22address as address%22)%7D%0A%09 */%0A%09@Test%0A%09@org.junit.Ignore%0A%09public void selectWithAliasParameters() %7B%0A%09%09queryBuilder.select(%22firstName as firstName%22, %22lastName as lastName%22);%0A%0A%09%09String actual = queryBuilder.getQueryString();%0A%09%09String expected = %22select employee.firstName as firstName, %22 +%0A%09%09%09%09%22employee.lastName as lastName from Employee employee%22;%0A%09%09Assert.assertEquals(expected, actual);%0A%0A%09%09super.entityManager.getTransaction().begin();%0A%09%09TypedQuery%3CEmployee%3E query = super.entityManager.createQuery(actual, Employee.class);%0A%09%09Assert.assertNotNull(query);%0A%09%09List%3CEmployee%3E result = query.getResultList();%0A%09%09super.entityManager.getTransaction().commit();%0A%0A%09%09Assert.assertEquals(200, result.size());%0A%09%7D%0A
 %7D%0A

Add comment for every method and @Ignore #selectWithAliasParameters()