@Test
public void updatePresenters() throws IOException, org.osgi.service.cm.ConfigurationException {

  String nonUser1 = "Non User 1";
  String nonUser2 = "Non User 2";
  String nonUser3 = "Non User 3";
  Properties eventProperties = new Properties();
  InputStream in = getClass().getResourceAsStream("/episode-catalog.properties");
  eventProperties.load(in);
  in.close();
  Dictionary<String, String> properties = PropertiesUtil.toDictionary(eventProperties);
  SecurityService securityService = EasyMock.createMock(SecurityService.class);
  EasyMock.expect(securityService.getOrganization()).andStubReturn(organization);
  EasyMock.replay(securityService);
  UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
  EasyMock.expect(userDirectoryService.loadUser(user1.getUsername())).andStubReturn(user1);
  EasyMock.expect(userDirectoryService.loadUser(user2.getUsername())).andStubReturn(user2);
  EasyMock.expect(userDirectoryService.loadUser(user3.getUsername())).andStubReturn(user3);
  EasyMock.expect(userDirectoryService.loadUser(nonUser1)).andStubReturn(null);
  EasyMock.expect(userDirectoryService.loadUser(nonUser2)).andStubReturn(null);
  EasyMock.expect(userDirectoryService.loadUser(nonUser3)).andStubReturn(null);
  EasyMock.replay(userDirectoryService);
  IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
  CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = new CommonEventCatalogUIAdapter();
  commonEventCatalogUIAdapter.updated(properties);
  indexServiceImpl.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
  indexServiceImpl.setUserDirectoryService(userDirectoryService);
  indexServiceImpl.setSecurityService(securityService);
  DublinCoreMetadataCollection metadata = commonEventCatalogUIAdapter.getRawFields();
  // Possible presenter combinations
  MetadataField emptyUpdatedPresenter = createCreatorMetadataField(new ArrayList<String>());
  ArrayList<String> oneNonUserList = new ArrayList<>();
  oneNonUserList.add(nonUser1);
  MetadataField nonUserUpdatedPresenter = createCreatorMetadataField(oneNonUserList);
  ArrayList<String> multiNonUserList = new ArrayList<>();
  multiNonUserList.add(nonUser1);
  multiNonUserList.add(nonUser2);
  multiNonUserList.add(nonUser3);
  MetadataField multiNonUserUpdatedPresenter = createCreatorMetadataField(multiNonUserList);
  ArrayList<String> oneUserList = new ArrayList<>();
  oneUserList.add(user1.getUsername());
  MetadataField userUpdatedPresenter = createCreatorMetadataField(oneUserList);
  ArrayList<String> multiUserList = new ArrayList<>();
  multiUserList.add(user1.getUsername());
  multiUserList.add(user2.getUsername());
  multiUserList.add(user3.getUsername());
  MetadataField multiUserUpdatedPresenter = createCreatorMetadataField(multiUserList);
  ArrayList<String> mixedUserList = new ArrayList<>();
  mixedUserList.add(user1.getUsername());
  mixedUserList.add(nonUser1);
  mixedUserList.add(user2.getUsername());
  mixedUserList.add(nonUser2);
  mixedUserList.add(nonUser3);
  mixedUserList.add(user3.getUsername());
  MetadataField mixedPresenters = createCreatorMetadataField(mixedUserList);
  ArrayList<String> userFullNames = new ArrayList<>();
  userFullNames.add(user1.getName());
  userFullNames.add(user2.getName());
  userFullNames.add(user3.getUsername());
  // Empty presenters
  metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
  metadata.addField(emptyUpdatedPresenter);
  Tuple<List<String>, Set<String>> updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
  assertTrue("The presenters dublincore metadata should be empty", updatedPresenters.getA().isEmpty());
  assertTrue("The technical presenters should be empty", updatedPresenters.getB().isEmpty());
  // Non-user presenter
  metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
  metadata.addField(nonUserUpdatedPresenter);
  updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
  assertTrue("There should be one presenter", updatedPresenters.getA().size() == 1);
  assertTrue("There should be no technical presenters", updatedPresenters.getB().isEmpty());
  // Multi non-user presenter
  metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
  metadata.addField(multiNonUserUpdatedPresenter);
  updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
  assertTrue("There should be three presenters", updatedPresenters.getA().size() == 3);
  assertTrue("The value for technical presenters should be empty", updatedPresenters.getB().isEmpty());
  // User presenter
  metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
  metadata.addField(userUpdatedPresenter);
  updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
  assertTrue("There should be one presenter", updatedPresenters.getA().size() == 1);
  assertEquals("The one presenter should have the user's full name", "User 1", updatedPresenters.getA().get(0));
  assertTrue("The one technical presenter", updatedPresenters.getB().size() == 1);
  assertEquals("The one technical presenter has the correct username", "user1",
          updatedPresenters.getB().iterator().next());
  // Multi user presenter
  metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
  metadata.addField(multiUserUpdatedPresenter);
  updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
  assertEquals("There should be three presenters", 3, updatedPresenters.getA().size());
  assertEquals("There should be three technical presenters", 3, updatedPresenters.getB().size());
  assertTrue("The list of technical presenters should contain all of the user names",
          updatedPresenters.getB().containsAll(multiUserList));
  // Mixed non-user and user presenters
  metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
  metadata.addField(mixedPresenters);
  updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
  assertEquals("There should be six presenters", 6, updatedPresenters.getA().size());
  assertEquals("There should be three technical presenters", 3, updatedPresenters.getB().size());
  assertTrue("The list of presenters should contain all of the non-user names",
          updatedPresenters.getA().containsAll(multiNonUserList));
  assertTrue("The list of presenters should contain all of the user full names",
          updatedPresenters.getA().containsAll(userFullNames));
  assertTrue("The list of technical presenters should contain all of the usernames",
          updatedPresenters.getB().containsAll(multiUserList));
}