<commit_before><commit_msg>BookRepository integration tests<commit_after>package com.bk.repository;

import com.bk.common.AbstractIntegrationTest;
import com.bk.model.Book;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * @author: <NAME>
 * Date: 4/27/13
 */
public class BookRepositoryTest extends AbstractIntegrationTest {
    @Autowired
    private BookRepository repository;

    private static final String ISBN = "9780439064866";
    private static final Long ID = 1L;
    private static final Long count = 1L;

    @Before
    public void setUp() {
        Book book = new Book();
        book.setIsbn(ISBN);
        book.setTitle("title");
        book.setPages(25);
        repository.save(book);
    }

    @Test
    @Ignore
    public void findByIdTest() {
        // TODO
        // Fix findById() + save() issue
        Book book = repository.findById(1L);
        assertNotNull(book);
    }

    @Test
    public void findByIsbnTest() {
        Book book = repository.findByIsbn(ISBN);
        assertNotNull(book);
    }

    @Test
    public void saveTestOk() {
        Book book = new Book();
        book.setTitle("title");
        book.setIsbn("isbn");
        book.setPages(50);
        book = repository.save(book);
        assertNotNull(book);
    }

    @Test(expected = org.springframework.dao.DataIntegrityViolationException.class)
    public void duplicateIsbnSaveTestFail() {
        Book book = new Book();
        book.setTitle("title");
        book.setIsbn(ISBN);
        book.setPages(50);
        book = repository.save(book);
    }

    @Test
    public void countTest() {
        Long bookCount = repository.count();
        assertEquals(bookCount, count);
    }
}
{'fraction_non_alphanumeric': 0.11193633952254642, 'fraction_numerical': 0.014323607427055704, 'mean_word_length': 2.6980392156862747, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6198977', 'n_tokens_mistral': 565, 'n_tokens_neox': 542, 'n_words': 124}