package com.unidev.polydata;

import com.unidev.polydata.domain.BasicPoly;
import com.unidev.polydata.domain.Poly;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;


import java.util.Optional;

/**
 * SQLite storage tests
 */
public class SQLiteStorageTest {

    @Test
    public void testStorageSaveLoad() throws SQLiteStorageException {

        SQLiteStorage sqLiteStorage = new SQLiteStorage("/tmp/testdb.db");

        BasicPoly basicPoly = BasicPoly.newPoly("potato");
        basicPoly.put("value", "tomato");


        sqLiteStorage.save("poly", basicPoly);

        Optional<Poly> polyOptional = sqLiteStorage.fetch("poly", "potato");
        assertThat(polyOptional.isPresent(), is(true));

        Poly poly = polyOptional.get();
        assertThat(poly._id(), is("potato"));
        assertThat(poly.get("value"), is("tomato"));


        Optional<Poly> polyOptional2 = sqLiteStorage.fetch("poly", "tomato");
        assertThat(polyOptional2.isPresent(), is(false));
    }
}

@@ -314,16 +314,126 @@
 alue;%0A%0A%0A
+import java.sql.Connection;%0Aimport java.sql.SQLException;%0Aimport java.sql.Statement;%0Aimport java.util.Arrays;%0A
 import j
@@ -673,16 +673,718 @@
 db.db%22);
+%0A        sqLiteStorage.setPolyMigrators(Arrays.asList(new SQLitePolyMigrator() %7B%0A            @Override%0A            public boolean canHandle(String poly) %7B%0A                return %22poly%22.equalsIgnoreCase(poly);%0A            %7D%0A%0A            @Override%0A            public void handle(String poly, Connection connection) throws SQLiteStorageException %7B%0A                try %7B%0A                    Statement statement = connection.createStatement();%0A                    statement.executeUpdate(%22CREATE TABLE IF NOT EXISTS %22+poly+%22 (_id TEXT PRIMARY KEY, value TEXT)%22);%0A                %7D catch (SQLException e) %7B%0A                    throw new SQLiteStorageException(e);%0A                %7D%0A            %7D%0A        %7D));
 %0A%0A      

Test coverage for poly tables conversion