Group group = bean.findAll().get(0);
MetadataCategory category = serviceContext.getBean(MetadataCategoryRepository.class).findAll().get(0);
final SourceRepository sourceRepository = serviceContext.getBean(SourceRepository.class);
Source source = sourceRepository.save(new Source().setLocal(true).setName("GN").setUuid("sourceuuid"));
final Element sampleMetadataXml = super.getSampleMetadataXml();
final Metadata metadata = new Metadata();
metadata.setDataAndFixCR(sampleMetadataXml)
.setUuid(UUID.randomUUID().toString());
metadata.getCategories().add(category);
metadata.getDataInfo().setSchemaId("iso19139");
metadata.getSourceInfo().setSourceId(source.getUuid());
final Metadata templateMd = _metadataRepository.save(metadata);
final String newMetadataId = _dataManager.createMetadata(serviceContext, "" + metadata.getId(), "" + group.getId(), source.getUuid(),
principal.getId(), templateMd.getUuid(), MetadataType.METADATA.codeString, true);
Metadata newMetadata = _metadataRepository.findOne(newMetadataId);
assertEquals(1, newMetadata.getCategories().size());
assertEquals(category, newMetadata.getCategories().iterator().next());