/*
 * Copyright (c) 2014 Sacred Scripture Foundation.
 * "All scripture is given by inspiration of God, and is profitable for
 * doctrine, for reproof, for correction, for instruction in righteousness:
 * That the man of God may be perfect, throughly furnished unto all good
 * works." (2 Tim 3:16-17)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sacredscripture.platform.internal.bible.dao.impl;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import org.sacredscripture.platform.internal.ObjectMother;
import org.sacredscripture.platform.internal.bible.BookTypeGroupImpl;
import org.sacredscripture.platform.internal.bible.dao.impl.BookTypeGroupDaoImpl;

import org.sacredscripturefoundation.commons.test.AbstractSpringJpaIntegrationTests;

import org.junit.Before;
import org.junit.Test;

/**
 * Persistence integeration tests for {@link BookTypeGroupDaoImpl}.
 *
 * @author Paul Benedict
 * @since Sacred Scripture Platform 1.0
 */
public class BookTypeGroupDaoImplPersistenceITest extends AbstractSpringJpaIntegrationTests {

    private BookTypeGroupDaoImpl dao;

    @Before
    public void onSetUp() {
        dao = new BookTypeGroupDaoImpl();
        dao.setEntityManager(em);
    }

    /**
     * Verifies group can be found by its code.
     */
    @Test
    public void testFindCode() {
        BookTypeGroupImpl g = ObjectMother.newBookTypeGroup();
        em.persist(g);
        assertSame(g, dao.findByCode(g.getCode()));
        // case insensitive checks
        assertSame(g, dao.findByCode(g.getCode().toUpperCase()));
        assertSame(g, dao.findByCode(g.getCode().toLowerCase()));
    }

    /**
     * Verifies group cannot be found by the wrong code.
     */
    @Test
    public void testFindCodeNotFound() {
        BookTypeGroupImpl g = ObjectMother.newBookTypeGroup();
        em.persist(g);
        assertNull(dao.findByCode("z"));
    }

}

@@ -18,16 +18,22 @@
 (c) 2014
+, 2015
  Sacred 
@@ -55,16 +55,16 @@
 ation.%0D%0A
-
  * %22All 
@@ -943,24 +943,70 @@
 ao.impl;%0D%0A%0D%0A
+import static org.junit.Assert.assertEquals;%0D%0A
 import stati
@@ -1079,24 +1079,82 @@
 ertSame;%0D%0A%0D%0A
+import org.sacredscripture.platform.bible.BookTypeGroup;%0D%0A
 import org.s
@@ -1275,91 +1275,8 @@
 pl;%0D
-%0Aimport org.sacredscripture.platform.internal.bible.dao.impl.BookTypeGroupDaoImpl;%0D
 %0A%0D%0Ai
@@ -1358,24 +1358,50 @@
 onTests;%0D%0A%0D%0A
+import java.util.List;%0D%0A%0D%0A
 import org.j
@@ -2498,32 +2498,32 @@
 em.persist(g);%0D%0A
-
         assertNu
@@ -2557,11 +2557,737 @@
    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Verifies only root groups are retrieved.%0D%0A     */%0D%0A    @Test%0D%0A    public void testFindRoots() %7B%0D%0A        BookTypeGroupImpl pg1 = ObjectMother.newBookTypeGroup();%0D%0A        BookTypeGroupImpl cg1 = ObjectMother.newBookTypeGroup();%0D%0A        pg1.addChild(cg1);%0D%0A%0D%0A        BookTypeGroupImpl pg2 = ObjectMother.newBookTypeGroup();%0D%0A        BookTypeGroupImpl cg2 = ObjectMother.newBookTypeGroup();%0D%0A        pg2.addChild(cg2);%0D%0A%0D%0A        em.persist(pg1);%0D%0A        em.persist(cg1);%0D%0A        em.persist(pg2);%0D%0A        em.persist(cg2);%0D%0A%0D%0A        List%3CBookTypeGroup%3E roots = dao.findRoots();%0D%0A        assertEquals(2, roots.size());%0D%0A        assertSame(pg1, roots.get(0));%0D%0A        assertSame(pg2, roots.get(1));%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

Add test