New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A POJO test case - add this to BasicTest.java if you want #24

Closed
paul-hammant opened this Issue Aug 20, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@paul-hammant

paul-hammant commented Aug 20, 2017

    @Test
    @SuppressWarnings("unchecked")
    public void testBasicPojoStuff() throws Exception {
        final JSimpleDB jdb = BasicTest.getJSimpleDB();

        JTransaction txn = jdb.createTransaction(true, ValidationMode.MANUAL);
        PojoPerson p = txn.create(PojoPerson.class);
        p.setId(123);
        p.setName("Fred");
        PojoPerson p2 = keyedOnId(txn).asMap().get(123).first();
        assertEquals(p2.getId(), 123);
        assertEquals(p2.getName(), "Fred");
        NavigableSet<PojoPerson> ppl = keyedOnId(txn).asMap().get(456);
        assertNull(ppl);
        txn.commit();

        try {
            keyedOnId(txn);
            fail("should have barfed, even read-only operations have to be in a txn");
        } catch (StaleTransactionException e) {
            // expected;
        }

        txn = jdb.createTransaction(true, ValidationMode.MANUAL);
        p2 = keyedOnId(txn).asMap().get(123).first();
        assertEquals(p2.getName(), "Fred");
        txn.rollback();

        txn = jdb.createTransaction(true, ValidationMode.MANUAL);
        p2 = keyedOnId(txn).asMap().get(123).first();
        txn.delete((JObject) p2);

        assertFalse(keyedOnId(txn).asMap().containsKey(123));

        txn.commit();

    }

    private Index<Integer, PojoPerson> keyedOnId(JTransaction txn) {
        return txn.queryIndex(PojoPerson.class, "id", Integer.class);
    }

    @JSimpleClass()
    public static class PojoPerson {
        private int id;
        private String name;
        @JField(indexed = true)
        public int getId() {
            return id;
        }
        public void setId(int value) {
            id = value;
        }
        @JField()
        public String getName() {
            return name;
        }
        public void setName(String value) {
            name = value;
        }
    }
@archiecobbs

This comment has been minimized.

Show comment
Hide comment
@archiecobbs

archiecobbs Oct 9, 2017

Collaborator

POJO import/export capability added in 55fc249.

Collaborator

archiecobbs commented Oct 9, 2017

POJO import/export capability added in 55fc249.

@archiecobbs archiecobbs closed this Oct 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment