@Test public void ensureAPostCanHaveAValueNulled() throws IOException, ClassNotFoundException { Post tested = new Post().withAuthor(author).withText("ensureAPostCanHaveAValueNulled"); tested = getPostService().create(tested); assertThat(tested.text, IsNull.notNullValue()); tested.text = null; tested = getPostService().update(tested); // force reload from graph tested = ((IdBasedService<Post>) getPostService()).findById(tested.id); assertThat(tested.text, IsNull.nullValue()); }
/** * According to latest modifications, the both note and text will be linked to literal vertex * containing value "3.0". How will it work ? * * @throws IOException * @throws ClassNotFoundException */ @Test public void ensurePostCanHaveTextIdenticalToNote() throws IOException, ClassNotFoundException { Post third = getPostService().find().matching(new FindPostByNote(3.0f)).getFirst(); // set value third.text = "3.0"; third = getPostService().update(third); // get modified post (notice we test here note to be equals to 3 - AS AN INTEGER - which allows // us to test equality between integer and float by the way) third = getPostService().find().matching(new FindPostByNote(3)).getFirst(); assertThat(third, IsNull.notNullValue()); assertThat(third.note, Is.is(3.0f)); assertThat(third.text, Is.is("3.0")); }
@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 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)); }