<commit_before>package org.codehaus.groovy.grails.orm.hibernate

/**
 * @author <NAME>
 */
class NamedCriteriaTests extends AbstractGrailsHibernateTests {

    protected void onSetUp() {
        gcl.parseClass('''

class Book {
   Long id
   Long version
   String title
   Date datePublished

   static namedQueries = {
       recentBooks {
           def now = new Date()
           gt 'datePublished', now - 365
       }

       booksWithBookInTitle {
           like 'title', '%Book%'
       }
   }

}
''')
    }

    void testList() {
        def bookClass = ga.getDomainClass("Book").clazz

        def now = new Date()
        assert bookClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert bookClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)

        session.clear()

        def books = bookClass.recentBooks.list()

        assertEquals 1, books?.size()
        assertEquals 'Some New Book', books[0].title
    }

    void testInvokingDirectly() {
        def bookClass = ga.getDomainClass("Book").clazz

        def now = new Date()
        assert bookClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert bookClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)

        session.clear()

        def books = bookClass.recentBooks()

        assertEquals 1, books?.size()
        assertEquals 'Some New Book', books[0].title
    }

    void testGetReturnsCorrectObject() {
        def bookClass = ga.getDomainClass("Book").clazz

        def now = new Date()
        def newBook = bookClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert newBook
        def oldBook = bookClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)
        assert oldBook

        session.clear()

        def book = bookClass.recentBooks.get(newBook.id)
        assert book
        assertEquals 'Some New Book', book.title

        book = bookClass.recentBooks.get(oldBook.id)
        assert book
        assertEquals 'Some Old Book', book.title
    }

    void testGetReturnsNull() {
        def bookClass = ga.getDomainClass("Book").clazz

        def now = new Date()
        def newBook = bookClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert newBook
        def oldBook = bookClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)
        assert oldBook

        session.clear()

        def book = bookClass.recentBooks.get(42 + oldBook.id)

        assert !book
    }

    void testCount() {
        def bookClass = ga.getDomainClass("Book").clazz

        def now = new Date()
        def newBook = bookClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert newBook
        def oldBook = bookClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)
        assert oldBook

        session.clear()
        assertEquals 2, bookClass.booksWithBookInTitle.count()
        assertEquals 1, bookClass.recentBooks.count()
    }

}<commit_msg>rename test domain class name as it was somehow colliding with a domain class from other tests<commit_after>package org.codehaus.groovy.grails.orm.hibernate

/**
 * @author <NAME>
 */
class NamedCriteriaTests extends AbstractGrailsHibernateTests {

    protected void onSetUp() {
        gcl.parseClass('''

class Publication {
   Long id
   Long version
   String title
   Date datePublished

   static namedQueries = {
       recentPublications {
           def now = new Date()
           gt 'datePublished', now - 365
       }

       publicationsWithBookInTitle {
           like 'title', '%Book%'
       }
   }

}
''')
    }

    void testList() {
        def publicationClass = ga.getDomainClass("Publication").clazz

        def now = new Date()
        assert publicationClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert publicationClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)

        session.clear()

        def publications = publicationClass.recentPublications.list()

        assertEquals 1, publications?.size()
        assertEquals 'Some New Book', publications[0].title
    }

    void testInvokingDirectly() {
        def publicationClass = ga.getDomainClass("Publication").clazz

        def now = new Date()
        assert publicationClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert publicationClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)

        session.clear()

        def publications = publicationClass.recentPublications()

        assertEquals 1, publications?.size()
        assertEquals 'Some New Book', publications[0].title
    }

    void testGetReturnsCorrectObject() {
        def publicationClass = ga.getDomainClass("Publication").clazz

        def now = new Date()
        def newPublication = publicationClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert newPublication
        def oldPublication = publicationClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)
        assert oldPublication

        session.clear()

        def publication = publicationClass.recentPublications.get(newPublication.id)
        assert publication
        assertEquals 'Some New Book', publication.title

        publication = publicationClass.recentPublications.get(oldPublication.id)
        assert publication
        assertEquals 'Some Old Book', publication.title
    }

    void testGetReturnsNull() {
        def publicationClass = ga.getDomainClass("Publication").clazz

        def now = new Date()
        def newPublication = publicationClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert newPublication
        def oldPublication = publicationClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)
        assert oldPublication

        session.clear()

        def publication = publicationClass.recentPublications.get(42 + oldPublication.id)

        assert !publication
    }

    void testCount() {
        def publicationClass = ga.getDomainClass("Publication").clazz

        def now = new Date()
        def newPublication = publicationClass.newInstance(title: "Some New Book",
                datePublished: now - 10).save(flush: true)
        assert newPublication
        def oldPublication = publicationClass.newInstance(title: "Some Old Book",
                datePublished: now - 900).save(flush: true)
        assert oldPublication

        session.clear()
        assertEquals 2, publicationClass.publicationsWithBookInTitle.count()
        assertEquals 1, publicationClass.recentPublications.count()
    }

}
{'fraction_non_alphanumeric': 0.09424941947821336, 'fraction_numerical': 0.00983472203250922, 'mean_word_length': 2.34185303514377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3753359', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1872, 'n_words': 512}