@Test
public void testChangeRepresentation() throws YardException {
String id = "urn:yard.test.testChangeRepresentation:representation.id";
String field = "urn:the.field:used.for.this.Test";
String testValue = "This is a test";
Yard yard = getYard();
// use the ValueFactory to create the representation to ensure that this
// instance has nothing to do with the store
Representation test = create(id, false);
// now store the empty Representation
yard.store(test);
// now add a values
test.add(field, testValue);
// now get the representation from the yard
Representation stored = yard.getRepresentation(id);
// test if the stored version does not contain the value
assertFalse(stored.get(field).hasNext());
stored = null;
// now store the updated version
yard.store(test);
// now check that the updated value is stored
stored = yard.getRepresentation(id);
assertEquals(testValue, stored.getFirst(field));
// now we need to test if modifications of an Representation returned
test = stored;
stored = null;
String testValue2 = "This is an ohter test value";
test.add(field, testValue2);
// now get the representation from the yard and check that it still has
// only one value
stored = yard.getRepresentation(id);
Collection<Object> values = asCollection(stored.get(field));
assertTrue(values.remove(testValue)); // test that it contains the value
assertTrue(values.isEmpty()); // and that there is only this value
values = null;
// now update the stored version with the new state
stored = null;
stored = yard.update(test);
values = asCollection(stored.get(field));
assertTrue(values.remove(testValue)); // test that it contains the original
assertTrue(values.remove(testValue2)); // test that it contains the 2nd value
assertTrue(values.isEmpty()); // and that there are only these two values
values = null;