/*
 * 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.jdbi.v3.jpa;

import org.jdbi.v3.H2DatabaseRule;
import org.jdbi.v3.sqlobject.SqlObjectBuilder;
import org.jdbi.v3.sqlobject.SqlQuery;
import org.jdbi.v3.sqlobject.SqlUpdate;
import org.junit.Rule;
import org.junit.Test;

import javax.persistence.Entity;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class PluginTest {
    @Rule
    public H2DatabaseRule db = new H2DatabaseRule().withPlugins();

    @Entity
    static class Thing {
        private int id;
        private String name;

        public Thing() {}
        public Thing(int id, String name) { setId(id); setName(name); }

        public int getId() { return id; }
        public String getName() { return name; }

        public void setId(int id) { this.id = id; }
        public void setName(String name) { this.name = name; }
    }

    interface ThingDao {
        @SqlUpdate("insert into something (id, name) values (:id, :name)")
        void insert(@BindJpa Thing thing);

        @SqlQuery("select id, name from something")
        List<Thing> list();
    }

    @Test
    public void testPluginInstallsJpaMapper() {
        Thing brian = new Thing(1, "Brian");
        Thing keith = new Thing(2, "Keith");

        ThingDao dao = SqlObjectBuilder.attach(db.getSharedHandle(), ThingDao.class);
        dao.insert(brian);
        dao.insert(keith);

        List<Thing> rs = dao.list();

        assertEquals(rs.size(), 2);
        assertThingEquals(rs.get(0), brian);
        assertThingEquals(rs.get(1), keith);
    }

    public static void assertThingEquals(Thing one, Thing two) {
        assertEquals(one.getId(), two.getId());
        assertEquals(one.getName(), two.getName());
    }
}

@@ -1976,16 +1976,19 @@
 tEquals(
+2, 
 rs.size(
@@ -1992,11 +1992,8 @@
 ze()
-, 2
 );%0A 
@@ -2013,24 +2013,31 @@
 ThingEquals(
+brian, 
 rs.get(0), b
@@ -2037,15 +2037,8 @@
 t(0)
-, brian
 );%0A 
@@ -2062,16 +2062,23 @@
 gEquals(
+keith, 
 rs.get(1
@@ -2082,15 +2082,8 @@
 t(1)
-, keith
 );%0A 

fix order of expected vs. actual parameters in test asserts