@Test
public void testPublishSingle() throws Exception {

    final String metadataId = metadataIds.get(0);
    allowedRepository.deleteAll();
    dataManager.indexMetadata(metadataId, true, null);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession();
    PublishReport report = publishService.publish("eng", request, metadataId, false);
    assertCorrectReport(report, 1, 0, 0, 0);
    assertPublishedInIndex(true, metadataId);
    report = publishService.publish("eng", request, metadataId, false);
    assertCorrectReport(report, 0, 0, 1, 0);
    assertPublishedInIndex(true, metadataId);
    allowedRepository.deleteAll();
    dataManager.indexMetadata(metadataId, true, null);
    assertPublishedInIndex(false, metadataId);
    SecurityContextHolder.clearContext();
    report = publishService.publish("eng", request, metadataId, false);
    assertCorrectReport(report, 0, 0, 0, 1);
    assertPublishedInIndex(false, metadataId);
    int iMetadataId = Integer.parseInt(metadataId);
    final int downloadId = ReservedOperation.download.getId();
    final int allGroupId = ReservedGroup.all.getId();
    allowedRepository.save(new OperationAllowed(new OperationAllowedId(iMetadataId, allGroupId, downloadId)));
    final int featuredId = ReservedOperation.featured.getId();
    allowedRepository.save(new OperationAllowed(new OperationAllowedId(iMetadataId, allGroupId, featuredId)));
    allowedRepository.save(new OperationAllowed(new OperationAllowedId(iMetadataId, sampleGroupId, featuredId)));
    report = publishService.publish("eng", request, metadataId, false);
    assertCorrectReport(report, 0, 0, 0, 1);
    assertEquals(3, allowedRepository.count());
    assertNotNull(allowedRepository.findOneById_GroupIdAndId_MetadataIdAndId_OperationId(allGroupId, iMetadataId, downloadId));
    assertNotNull(allowedRepository.findOneById_GroupIdAndId_MetadataIdAndId_OperationId(allGroupId, iMetadataId, featuredId));
    assertNotNull(allowedRepository.findOneById_GroupIdAndId_MetadataIdAndId_OperationId(sampleGroupId, iMetadataId, featuredId));
}