DublinCoreMetadataCollection { public List<MetadataField> getFields() { return this.fieldsInOrder; } DublinCoreMetadataCollection();  DublinCoreMetadataCollection(final Iterable<MetadataField> fields);  DublinCoreMetadataCollection(final DublinCoreMetadataCollection c); DublinCoreMetadataCollection readOnlyCopy(); Map<String, MetadataField> getOutputFields(); void addField(final MetadataField metadata); void addEmptyField(final MetadataField metadataField, final ListProvidersService listProvidersService); void addField(final MetadataField metadataField, final String value, final ListProvidersService listProvidersService); void addField(final MetadataField metadataField, final List<String> values, final ListProvidersService listProvidersService); void removeField(final MetadataField metadata); List<MetadataField> getFields(); void updateStringField(final MetadataField current, final String value); boolean isUpdated();  }
@Test public void testOrderOfFields() { final DublinCoreMetadataCollection collection = new DublinCoreMetadataCollection(Collections.singleton(third)); assertEquals(1, collection.getFields().size()); assertEquals(third, collection.getFields().get(0)); }
@Test public void testOrderOfFieldsInputFieldOrderZeroExpectsAtFront() { DublinCoreMetadataCollection collection = new DublinCoreMetadataCollection(Arrays .asList(unorderedOne, unorderedTwo, unorderedThree, first)); assertEquals(4, collection.getFields().size()); assertEquals("A field with an order value of 0 should be first in the list of fields", first, collection .getFields().get(0)); collection = new DublinCoreMetadataCollection(Arrays.asList(first, unorderedOne, unorderedTwo, unorderedThree)); assertEquals(4, collection.getFields().size()); assertEquals("A field with an order value of 0 should be first in the list of fields", first, collection .getFields().get(0)); collection = new DublinCoreMetadataCollection(Arrays.asList(unorderedOne, first, unorderedTwo, unorderedThree)); assertEquals(4, collection.getFields().size()); assertEquals("A field with an order value of 0 should be first in the list of fields", first, collection .getFields().get(0)); }
@Test public void testOrderOfFieldsInputFieldOrderTwoExpectsInMiddle() { DublinCoreMetadataCollection collection = new DublinCoreMetadataCollection(Arrays .asList(unorderedOne, unorderedTwo, unorderedThree, third)); assertEquals(4, collection.getFields().size()); assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection .getFields().get(2)); collection = new DublinCoreMetadataCollection(Arrays.asList(third, unorderedOne, unorderedTwo, unorderedThree)); assertEquals(4, collection.getFields().size()); assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection .getFields().get(2)); collection = new DublinCoreMetadataCollection(Arrays.asList(unorderedOne, third, unorderedTwo, unorderedThree)); assertEquals(4, collection.getFields().size()); assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection .getFields().get(2)); }
@Test public void testOrderOfFieldsInputMultipleOrderedFieldsExpectsInCorrectPositions() { DublinCoreMetadataCollection collection = new DublinCoreMetadataCollection(Arrays .asList(unorderedOne, unorderedTwo, unorderedThree, first, third, seventh)); assertEquals(6, collection.getFields().size()); assertEquals("A field with an order value of 0 should be first in the list of fields", first, collection .getFields().get(0)); assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection .getFields().get(2)); assertEquals("A field with an order value of 7 should be in the last position in the list of fields", seventh, collection.getFields().get(5)); collection = new DublinCoreMetadataCollection(Arrays .asList(first, third, seventh, unorderedOne, unorderedTwo, unorderedThree)); assertEquals(6, collection.getFields().size()); assertEquals("A field with an order value of 0 should be first in the list of fields", first, collection .getFields().get(0)); assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection .getFields().get(2)); assertEquals("A field with an order value of 7 should be in the last position in the list of fields", seventh, collection.getFields().get(5)); collection = new DublinCoreMetadataCollection(Arrays .asList(third, unorderedOne, unorderedTwo, first, seventh, unorderedThree)); assertEquals(6, collection.getFields().size()); assertEquals("A field with an order value of 0 should be first in the list of fields", first, collection .getFields().get(0)); assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection .getFields().get(2)); assertEquals("A field with an order value of 7 should be in the last position in the list of fields", seventh, collection.getFields().get(5)); }
@Test public void testOrderOfFieldsInputDuplicateOrderValueExpectsBothInserted() { final MetadataField newFirst = createField("New first", 0, null); final DublinCoreMetadataCollection collection = new DublinCoreMetadataCollection(Arrays .asList(unorderedOne, unorderedTwo, unorderedThree, first, third, seventh, newFirst)); assertEquals(7, collection.getFields().size()); assertTrue("A field with an order value of 0 should be first in the list of fields", first == collection .getFields().get(0) || newFirst == collection.getFields().get(0)); assertTrue("A field with an order value of 0 should be second in the list of fields", first == collection .getFields().get(1) || newFirst == collection.getFields().get(1)); assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection .getFields().get(2)); assertEquals("A field with an order value of 7 should be in the last position in the list of fields", seventh, collection.getFields().get(6)); }
@Test public void testAddExistingFieldInputAlreadyExistingFieldExpectsOnlyOneFieldFromGetFields() { final String value = "Hello"; final MetadataField newFirst = createField("first", 0, value); final DublinCoreMetadataCollection collection = new DublinCoreMetadataCollection(Arrays .asList(unorderedOne, unorderedTwo, unorderedThree, first, third, seventh, newFirst)); int numberOfFirsts = 0; Opt<String> valueFound = Opt.none(); for (final MetadataField field : collection.getFields()) { if (field.getInputID().equals(FIRST_ID)) { numberOfFirsts++; if (field.getValue() != null && field.getValue() instanceof String) { valueFound = Opt.some((String) field.getValue()); } } } assertEquals("There should only be one field called first in the collection.", 1, numberOfFirsts); assertTrue("The value has been set so it should be in the collection.", valueFound.isSome()); assertEquals("There should only be one field called first in the collection.", value, valueFound.get()); }