TMTextUnitVariantCommentService { public void copyComments(Long sourceTmTextUnitVariantId, Long targetTMTextUnitVariantId) { logger.debug("Copy TMTextUnitVariantComments from source TMTextUnitVariant: {} into target TMTextUnitVariant: {}", sourceTmTextUnitVariantId, targetTMTextUnitVariantId); for (TMTextUnitVariantComment comment : tmTextUnitVariantCommentRepository.findAllByTmTextUnitVariant_id(sourceTmTextUnitVariantId)) { logger.debug("Copy comment, id: {}", comment.getId()); addComment(targetTMTextUnitVariantId, comment.getType(), comment.getSeverity(), comment.getContent()); } }  void copyComments(Long sourceTmTextUnitVariantId, Long targetTMTextUnitVariantId); @Transactional TMTextUnitVariantComment addComment(
            Long tmTextUnitVariantId,
            TMTextUnitVariantComment.Type type,
            TMTextUnitVariantComment.Severity severity,
            String content); @Transactional TMTextUnitVariantComment addComment(
            TMTextUnitVariant tmTextUnitVariant,
            TMTextUnitVariantComment.Type type,
            TMTextUnitVariantComment.Severity severity,
            String content); List<TextUnitDTOWithComments> enrichTextUnitDTOsWithComments(List<TextUnitDTO> textUnitDTOs);  }
@Test public void testCopyComments() { Long sourceTmTextUnitVariantId = tmTestData.addCurrentTMTextUnitVariant1FrFR.getId(); tmTextUnitVariantCommentService.addComment( sourceTmTextUnitVariantId, TMTextUnitVariantComment.Type.LEVERAGING, TMTextUnitVariantComment.Severity.INFO, "for test"); tmTextUnitVariantCommentService.addComment( sourceTmTextUnitVariantId, TMTextUnitVariantComment.Type.LEVERAGING, TMTextUnitVariantComment.Severity.WARNING, "for test2"); Long targetTmTextUnitVariantId = tmTestData.addCurrentTMTextUnitVariant1KoKR.getId(); tmTextUnitVariantCommentService.copyComments(sourceTmTextUnitVariantId, targetTmTextUnitVariantId); List<TMTextUnitVariantComment> targetComments = tmTextUnitVariantCommentRepository.findAllByTmTextUnitVariant_id(sourceTmTextUnitVariantId); Assert.assertEquals("There should be 2 copied comments in the TextUnitVariant", 2L, targetComments.size()); Iterator<TMTextUnitVariantComment> sourceCommentsIt = tmTextUnitVariantCommentRepository.findAllByTmTextUnitVariant_id(targetTmTextUnitVariantId).iterator(); for (TMTextUnitVariantComment targetComment : targetComments) { TMTextUnitVariantComment sourceComment = sourceCommentsIt.next(); Assert.assertNotEquals("Ids should be different", sourceComment.getId(), targetComment.getId()); Assert.assertEquals(sourceComment.getType(), targetComment.getType()); Assert.assertEquals(sourceComment.getSeverity(), targetComment.getSeverity()); Assert.assertEquals(sourceComment.getContent(), targetComment.getContent()); } }