@Test
public void testCreateMetadataAndCopyExistingPictures() throws Exception {

    final ServiceContext context = createServiceContext();
    loginAsAdmin(context);
    final String id = importMetadata(context);
    Path mdPublicDataDir = Lib.resource.getDir(context, Params.Access.PUBLIC, Integer.parseInt(id));
    Path mdPrivateDataDir = Lib.resource.getDir(context, Params.Access.PRIVATE, Integer.parseInt(id));
    final Path smallImage = mdPublicDataDir.resolve("small.gif");
    final Path largeImage = mdPublicDataDir.resolve("large.gif");
    createImage(GIF, smallImage);
    createImage(GIF, largeImage);
    final Path privateImage = mdPrivateDataDir.resolve("privateFile.gif");
    createImage(GIF, privateImage);
    _dataManager.setThumbnail(context, id, true, smallImage.toAbsolutePath().normalize().toString(), false);
    _dataManager.setThumbnail(context, id, false, largeImage.toAbsolutePath().normalize().toString(), false);
    int sampleGroup = _groupRepo.findByName("sample").getId();
    final Element params = createParams(
        read(Geonet.Elem.ID, id),
        read(Geonet.Elem.GROUP, sampleGroup));
    final Create createService = new Create();
    final Element element = createService.serviceSpecificExec(params, context);
    assertEquals(2, _metadataRepo.count());
    final String newId = element.getChildText(Geonet.Elem.ID);
    assertNotNull(_metadataRepo.findOne(newId));
    Path newPublicMdDataDir = Lib.resource.getDir(context, Params.Access.PUBLIC, Integer.parseInt(newId));
    assertTrue(Files.exists(newPublicMdDataDir.resolve(smallImage.getFileName())));
    assertTrue(Files.exists(newPublicMdDataDir.resolve(largeImage.getFileName())));
    final int expected = 2;
    assertFilesInDirectory(newPublicMdDataDir, expected);
    Path newPrivateMdDataDir = Lib.resource.getDir(context, Params.Access.PRIVATE, Integer.parseInt(newId));
    assertTrue(Files.exists(newPrivateMdDataDir));
    assertFilesInDirectory(newPrivateMdDataDir, 1);
    assertTrue(Files.exists(newPrivateMdDataDir.resolve(privateImage.getFileName())));
}