@Override public Iterable<Representation> update(Iterable<Representation> representations) throws YardException, IllegalArgumentException { return yard.update(representations); } }
@Override public Iterable<Representation> update(Iterable<Representation> representations) throws YardException, IllegalArgumentException { return yard.update(representations); } }
@Override public Representation update(Representation representation) throws YardException, IllegalArgumentException { return yard.update(applyCacheMappings(yard, representation)); }
@Override public Representation update(Representation representation) throws YardException, IllegalArgumentException { return yard.update(applyCacheMappings(yard, representation)); }
@Test(expected = IllegalArgumentException.class) public void testUpdateRepresentationsWithNull() throws YardException { getYard().update((Iterable<Representation>) null); }
@Test(expected = IllegalArgumentException.class) public void testUpdateRepresentationWithNull() throws YardException { getYard().update((Representation) null); }
@Test(expected = IllegalArgumentException.class) public void testUpdateRepresentationWithNonPresent() throws YardException { String id = "urn:yard.test.testUpdateRepresentationWithNonPresent:representation.id"; Representation test = create(id, false); getYard().update(test); // throws an Exception because test is not part of the yard }
/** * When updating multiple null values need to be ignored. * * @throws YardException */ @Test public void testUpdateRepresentationsWithNullElement() throws YardException { // NOTE: this does not test if the updated view of the representation is // stored, but only that the update method works correctly Yard yard = getYard(); String id1 = "urn:yard.test.testUpdateRepresentationsWithNullElement:representation.id"; String field = "urn:the.field:used.for.this.Test"; Representation test1 = create(id1, true); // change the representations to be sure to force an update even if the // implementation checks for changes before updating a representation test1.add(field, "test value 1"); Iterable<Representation> updated = yard.update(Arrays.asList(test1, null)); assertNotNull(updated); Iterator<Representation> updatedIt = updated.iterator(); assertTrue(updatedIt.hasNext()); assertEquals(test1, updatedIt.next()); assertFalse(updatedIt.hasNext()); }
/** * When updating multiple non present representations need to be ignored. * * @throws YardException */ @Test public void testUpdateRepresentationsWithNonPresent() throws YardException { // NOTE: this does not test if the updated view of the representation is // stored, but only that the update method works correctly Yard yard = getYard(); String id1 = "urn:yard.test.testUpdateRepresentationsWithNonPresent:representation.id1"; String id2 = "urn:yard.test.testUpdateRepresentationsWithNonPresent:representation.id2"; String field = "urn:the.field:used.for.this.Test"; Representation test1 = create(id1, true); // change the representations to be sure to force an update even if the // implementation checks for changes before updating a representation test1.add(field, "test value 1"); // create a 2nd Representation by using the ValueFactory (will not add it // to the yard!) Representation test2 = create(id2, false); // now test1 is present and test2 is not. Iterable<Representation> updated = yard.update(Arrays.asList(test1, test2)); // We expect that only test1 is updated and test2 is ignored assertNotNull(updated); Iterator<Representation> updatedIt = updated.iterator(); assertTrue(updatedIt.hasNext()); assertEquals(test1, updatedIt.next()); assertFalse(updatedIt.hasNext()); }
@Test public void testUpdateRepresentations() throws YardException { // NOTE: this does not test if the updated view of the representation is // stored, but only that the update method works correctly Yard yard = getYard(); String id1 = "urn:yard.test.testUpdateRepresentations:representation.id1"; String id2 = "urn:yard.test.testUpdateRepresentations:representation.id2"; String field = "urn:the.field:used.for.this.Test"; Representation test1 = create(id1, true); Representation test2 = create(id2, true); // change the representations to be sure to force an update even if the // implementation checks for changes before updating a representation test1.add(field, "test value 1"); test2.add(field, "test value 2"); Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2)); assertNotNull(updatedIterable); Collection<Representation> updated = asCollection(updatedIterable.iterator()); // test that both the parsed Representations where stored (updated & created) assertTrue(updated.remove(test1)); assertTrue(updated.remove(test2)); assertTrue(updated.isEmpty()); }
stored = yard.update(test); values = asCollection(stored.get(field));