package th.co.geniustree.springdata.jpa;

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specifications;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import th.co.geniustree.springdata.jpa.domain.Document;
import th.co.geniustree.springdata.jpa.repository.DocumentRepository;
import th.co.geniustree.springdata.jpa.specification.DocumentSpecs;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,classes = DemoApplication.class)
@Transactional
public class SpecificationExecutorProjectionTests {
    @Autowired
    private DocumentRepository documentRepository;

    @Test
    public void specificationWithProjection() {
        Specifications<Document> where = Specifications.where(DocumentSpecs.idEq(1L));
        Page<DocumentRepository.DocumentWithoutParent> all = documentRepository.findAll(where, DocumentRepository.DocumentWithoutParent.class, null);
        Assertions.assertThat(all).isNotEmpty();
        System.out.println(all.getContent());
        Assertions.assertThat(all.getContent().get(0).getDocumentType()).isEqualTo("ต้นฉบับ");
    }


}

@@ -974,35 +974,15 @@
 oid 
-specificationWithProjection
+findAll
 () %7B
@@ -1416,11 +1416,356 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void findOne() %7B%0A        Specifications%3CDocument%3E where = Specifications.where(DocumentSpecs.idEq(1L));%0A        DocumentRepository.DocumentWithoutParent one = documentRepository.findOne(where, DocumentRepository.DocumentWithoutParent.class);%0A        Assertions.assertThat(one.getDocumentType()).isEqualTo(%22%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%89%E0%B8%9A%E0%B8%B1%E0%B8%9A%22);%0A    %7D%0A%0A
 %0A%7D%0A

add test for findOne