Search in sources :

Example 1 with MapOf

use of org.cactoos.map.MapOf in project cactoos-jdbc by fabriciofx.

the class StatementTransactionTest method rollback.

@Test
public void rollback() throws Exception {
    final Transacted transacted = new Transacted(new SessionNoAuth(new SourceH2("unsafedb")));
    new ScriptSql(new ResourceOf("com/github/fabriciofx/cactoos/jdbc/phonebook/phonebook-h2.sql")).run(transacted);
    final Phonebook phonebook = new PhonebookSql(transacted);
    final String name = "Frank Miller";
    try {
        new StatementTransaction<>(transacted, () -> {
            final Contact contact = phonebook.contact(new MapOf<String, String>(new MapEntry<>("name", name)));
            contact.phones().add(new MapOf<String, String>(new MapEntry<>("number", "99991234"), new MapEntry<>("carrier", "TIM")));
            throw new IllegalStateException("Rollback");
        }).result();
    } catch (final IllegalStateException ex) {
    }
    MatcherAssert.assertThat("Can't perform a transaction rollback", StreamSupport.stream(phonebook.filter(name).spliterator(), false).count(), Matchers.equalTo(0L));
}
Also used : PhonebookSql(com.github.fabriciofx.cactoos.jdbc.phonebook.sql.PhonebookSql) Contact(com.github.fabriciofx.cactoos.jdbc.phonebook.Contact) SourceH2(com.github.fabriciofx.cactoos.jdbc.source.SourceH2) ScriptSql(com.github.fabriciofx.cactoos.jdbc.script.ScriptSql) Phonebook(com.github.fabriciofx.cactoos.jdbc.phonebook.Phonebook) ResourceOf(org.cactoos.io.ResourceOf) MapOf(org.cactoos.map.MapOf) Transacted(com.github.fabriciofx.cactoos.jdbc.session.Transacted) SessionNoAuth(com.github.fabriciofx.cactoos.jdbc.session.SessionNoAuth) Test(org.junit.Test)

Aggregations

Contact (com.github.fabriciofx.cactoos.jdbc.phonebook.Contact)1 Phonebook (com.github.fabriciofx.cactoos.jdbc.phonebook.Phonebook)1 PhonebookSql (com.github.fabriciofx.cactoos.jdbc.phonebook.sql.PhonebookSql)1 ScriptSql (com.github.fabriciofx.cactoos.jdbc.script.ScriptSql)1 SessionNoAuth (com.github.fabriciofx.cactoos.jdbc.session.SessionNoAuth)1 Transacted (com.github.fabriciofx.cactoos.jdbc.session.Transacted)1 SourceH2 (com.github.fabriciofx.cactoos.jdbc.source.SourceH2)1 ResourceOf (org.cactoos.io.ResourceOf)1 MapOf (org.cactoos.map.MapOf)1 Test (org.junit.Test)1