@Test public void ensureCascadedCreateWorks() throws IOException, ClassNotFoundException { String METHOD_NAME = "ensureCascadedCreateWorks"; Post toCreate = new Post(); toCreate.text = METHOD_NAME; User author = new User(); author.password = METHOD_NAME; author.setLogin(METHOD_NAME); toCreate.author = author; getPostService().create(toCreate); // Find it back Post found = getPostService().find().matching(new FindPostByText(METHOD_NAME)).getFirst(); assertThat(found, IsNull.notNullValue()); assertThat(found.author, IsNull.notNullValue()); assertThat(found.author.getLogin(), IsNull.notNullValue()); }
@Test public void ensureDeletCascadesWell() { User other = new User().withId(2).withLogin("other login").withPassword("other password"); long id = DELETABLE_POST; other.about = new Post(id, "a post about another user", 2, State.PUBLIC, other); getUserService().create(other); Post about = ((IdBasedService<Post>) getPostService()).findById(id); assertThat(about, IsNull.notNullValue()); getUserService().delete(other); try { if (environment.getGraph() instanceof TransactionalGraph) { TransactionalGraph transactionalGraph = (TransactionalGraph) environment.getGraph(); // transactionalGraph.startTransaction(); } about = ((IdBasedService<Post>) getPostService()).findById(id); assertThat(about, IsNull.nullValue()); } catch (NoReturnableVertexException e) { // that exception is one of possible correct behaviours } }
@Test public void ensureUpdateCascadesWell() { User other = new User().withId(2).withLogin("other login").withPassword("other password"); long id = DELETABLE_POST; String POST_TEXT = "a post about another user"; other.about = new Post(id, POST_TEXT, 2, State.PUBLIC, other); getUserService().create(other); Post about = ((IdBasedService<Post>) getPostService()).findById(id); assertThat(about, IsNull.notNullValue()); assertThat(about.text, Is.is(POST_TEXT)); about.text += POST_TEXT; getUserService().update(other); about = ((IdBasedService<Post>) getPostService()).findById(id); assertThat(about, IsNull.notNullValue()); // we didn't change author's about Post, but the one we fetched separatly assertThat(about.text, Is.is(POST_TEXT)); // Now we update the GOOD about message (yeah these cascade things are a nightmare) ((Post) other.about).text += POST_TEXT; getUserService().update(other); about = ((IdBasedService<Post>) getPostService()).findById(id); assertThat(about, IsNull.notNullValue()); assertThat(about.text, Is.is(POST_TEXT + POST_TEXT)); }