1818
1919import com .epam .reportportal .rules .exception .ErrorType ;
2020import com .epam .reportportal .rules .exception .ReportPortalException ;
21- import com .epam .ta .reportportal .binary .impl . AttachmentDataStoreService ;
21+ import com .epam .ta .reportportal .binary .tms . TmsAttachmentDataStoreService ;
2222import com .epam .ta .reportportal .core .tms .db .entity .TmsAttachment ;
2323import com .epam .ta .reportportal .core .tms .db .repository .TmsAttachmentRepository ;
2424import com .epam .ta .reportportal .core .tms .db .repository .TmsManualScenarioPreconditionsAttachmentRepository ;
2727import com .epam .ta .reportportal .core .tms .dto .UploadAttachmentRS ;
2828import com .epam .ta .reportportal .core .tms .mapper .TmsAttachmentMapper ;
2929import java .io .ByteArrayInputStream ;
30- import java .io .IOException ;
3130import java .io .InputStream ;
3231import java .time .Duration ;
3332import java .time .Instant ;
@@ -53,7 +52,7 @@ class TmsAttachmentServiceImplTest {
5352 private TmsAttachmentRepository tmsAttachmentRepository ;
5453
5554 @ Mock
56- private AttachmentDataStoreService attachmentDataStoreService ;
55+ private TmsAttachmentDataStoreService tmsAttachmentDataStoreService ;
5756
5857 @ Mock
5958 private TmsAttachmentMapper tmsAttachmentMapper ;
@@ -106,7 +105,7 @@ void setUp() {
106105 @ Test
107106 void uploadAttachment_ShouldSucceed_WhenValidFile () throws Exception {
108107 // Given valid file to upload
109- when (attachmentDataStoreService .save (anyString (), any (InputStream .class ))).thenReturn (fileId );
108+ when (tmsAttachmentDataStoreService .save (anyString (), any (InputStream .class ))).thenReturn (fileId );
110109 when (tmsAttachmentMapper .convertToAttachment (fileId , file )).thenReturn (attachment );
111110 when (tmsAttachmentRepository .save (attachment )).thenReturn (attachment );
112111 when (tmsAttachmentMapper .convertToUploadAttachmentRS (attachment )).thenReturn (
@@ -120,7 +119,7 @@ void uploadAttachment_ShouldSucceed_WhenValidFile() throws Exception {
120119 assertEquals (uploadAttachmentRS .getId (), result .getId ());
121120 assertEquals (uploadAttachmentRS .getFileName (), result .getFileName ());
122121
123- verify (attachmentDataStoreService ).save (eq ("test.txt" ), any (InputStream .class ));
122+ verify (tmsAttachmentDataStoreService ).save (eq ("test.txt" ), any (InputStream .class ));
124123 verify (tmsAttachmentMapper ).convertToAttachment (fileId , file );
125124 verify (tmsAttachmentRepository ).save (attachment );
126125 verify (tmsAttachmentMapper ).convertToUploadAttachmentRS (attachment );
@@ -138,13 +137,13 @@ void uploadAttachment_ShouldThrowException_WhenFileIsEmpty() {
138137 assertEquals (ErrorType .BAD_REQUEST_ERROR , exception .getErrorType ());
139138 assertEquals ("Error in handled Request. Please, check specified parameters: 'File cannot be empty'" , exception .getMessage ());
140139
141- verifyNoInteractions (attachmentDataStoreService , tmsAttachmentMapper , tmsAttachmentRepository );
140+ verifyNoInteractions (tmsAttachmentDataStoreService , tmsAttachmentMapper , tmsAttachmentRepository );
142141 }
143142
144143 @ Test
145144 void uploadAttachment_ShouldThrowException_WhenDataStoreServiceFails () throws Exception {
146145 // Given data store service throws IOException
147- when (attachmentDataStoreService .save (anyString (), any (InputStream .class )))
146+ when (tmsAttachmentDataStoreService .save (anyString (), any (InputStream .class )))
148147 .thenThrow (new RuntimeException ("Storage error" ));
149148
150149 // When/Then exception should be thrown when storage fails
@@ -154,7 +153,7 @@ void uploadAttachment_ShouldThrowException_WhenDataStoreServiceFails() throws Ex
154153 assertEquals (ErrorType .BINARY_DATA_CANNOT_BE_SAVED , exception .getErrorType ());
155154 assertTrue (exception .getMessage ().contains ("Failed to upload attachment" ));
156155
157- verify (attachmentDataStoreService ).save (eq ("test.txt" ), any (InputStream .class ));
156+ verify (tmsAttachmentDataStoreService ).save (eq ("test.txt" ), any (InputStream .class ));
158157 verifyNoInteractions (tmsAttachmentRepository );
159158 }
160159
@@ -189,15 +188,15 @@ void getTmsAttachment_ShouldReturnEmpty_WhenNotExists() {
189188 void deleteAttachment_ShouldSucceed_WhenAttachmentExists () {
190189 // Given attachment exists in repository
191190 when (tmsAttachmentRepository .findById (attachmentId )).thenReturn (Optional .of (attachment ));
192- doNothing ().when (attachmentDataStoreService ).delete (fileId );
191+ doNothing ().when (tmsAttachmentDataStoreService ).delete (fileId );
193192 doNothing ().when (tmsAttachmentRepository ).deleteById (attachmentId );
194193
195194 // When deleting existing attachment
196195 sut .deleteAttachment (attachmentId );
197196
198197 // Then attachment should be deleted from both data store and repository
199198 verify (tmsAttachmentRepository ).findById (attachmentId );
200- verify (attachmentDataStoreService ).delete (fileId );
199+ verify (tmsAttachmentDataStoreService ).delete (fileId );
201200 verify (tmsAttachmentRepository ).deleteById (attachmentId );
202201 }
203202
@@ -214,15 +213,15 @@ void deleteAttachment_ShouldThrowException_WhenAttachmentNotFound() {
214213 assertTrue (exception .getMessage ().contains ("Attachment not found: " + attachmentId ));
215214
216215 verify (tmsAttachmentRepository ).findById (attachmentId );
217- verifyNoInteractions (attachmentDataStoreService );
216+ verifyNoInteractions (tmsAttachmentDataStoreService );
218217 verify (tmsAttachmentRepository , never ()).deleteById (attachmentId );
219218 }
220219
221220 @ Test
222221 void deleteAttachment_ShouldThrowException_WhenDataStoreDeleteFails () {
223222 // Given attachment exists but data store delete operation fails
224223 when (tmsAttachmentRepository .findById (attachmentId )).thenReturn (Optional .of (attachment ));
225- doThrow (new RuntimeException ("Delete failed" )).when (attachmentDataStoreService ).delete (fileId );
224+ doThrow (new RuntimeException ("Delete failed" )).when (tmsAttachmentDataStoreService ).delete (fileId );
226225
227226 // When/Then exception should be thrown when data store delete fails
228227 var exception = assertThrows (ReportPortalException .class ,
@@ -231,7 +230,7 @@ void deleteAttachment_ShouldThrowException_WhenDataStoreDeleteFails() {
231230 assertEquals (ErrorType .UNCLASSIFIED_REPORT_PORTAL_ERROR , exception .getErrorType ());
232231
233232 verify (tmsAttachmentRepository ).findById (attachmentId );
234- verify (attachmentDataStoreService ).delete (fileId );
233+ verify (tmsAttachmentDataStoreService ).delete (fileId );
235234 }
236235
237236 @ Test
@@ -288,8 +287,8 @@ void cleanupExpiredAttachments_ShouldCleanup_WhenExpiredAttachmentsExist() {
288287
289288 // Then expired attachments should be cleaned up from both data store and repository
290289 verify (tmsAttachmentRepository ).findExpiredAttachments (any (Instant .class ));
291- verify (attachmentDataStoreService ).delete ("path1" );
292- verify (attachmentDataStoreService ).delete ("path2" );
290+ verify (tmsAttachmentDataStoreService ).delete ("path1" );
291+ verify (tmsAttachmentDataStoreService ).delete ("path2" );
293292 verify (tmsAttachmentRepository ).deleteByIds (Arrays .asList (1L , 2L ));
294293 }
295294
@@ -304,7 +303,7 @@ void cleanupExpiredAttachments_ShouldDoNothing_WhenNoExpiredAttachments() {
304303
305304 // Then no cleanup operations should be performed
306305 verify (tmsAttachmentRepository ).findExpiredAttachments (any (Instant .class ));
307- verifyNoInteractions (attachmentDataStoreService );
306+ verifyNoInteractions (tmsAttachmentDataStoreService );
308307 verify (tmsAttachmentRepository , never ()).deleteByIds (anyList ());
309308 }
310309
@@ -317,15 +316,15 @@ void cleanupExpiredAttachments_ShouldContinueOnFileDeleteError() {
317316
318317 when (tmsAttachmentRepository .findExpiredAttachments (any (Instant .class )))
319318 .thenReturn (List .of (expiredAttachment ));
320- doThrow (new RuntimeException ("File delete failed" )).when (attachmentDataStoreService )
319+ doThrow (new RuntimeException ("File delete failed" )).when (tmsAttachmentDataStoreService )
321320 .delete ("path1" );
322321
323322 // When cleaning up expired attachments
324323 sut .cleanupExpiredAttachments ();
325324
326325 // Then cleanup should continue despite file delete error
327326 verify (tmsAttachmentRepository ).findExpiredAttachments (any (Instant .class ));
328- verify (attachmentDataStoreService ).delete ("path1" );
327+ verify (tmsAttachmentDataStoreService ).delete ("path1" );
329328 verify (tmsAttachmentRepository ).deleteByIds (List .of (1L ));
330329 }
331330
@@ -382,9 +381,9 @@ void duplicateTmsAttachment_ShouldSucceed_WhenValidAttachment() throws Exception
382381
383382 var originalFileStream = new ByteArrayInputStream ("test content" .getBytes ());
384383
385- when (attachmentDataStoreService .load (attachment .getPathToFile ()))
384+ when (tmsAttachmentDataStoreService .load (attachment .getPathToFile ()))
386385 .thenReturn (Optional .of (originalFileStream ));
387- when (attachmentDataStoreService .save (anyString (), any (InputStream .class ))).thenReturn (
386+ when (tmsAttachmentDataStoreService .save (anyString (), any (InputStream .class ))).thenReturn (
388387 newFileId );
389388 when (tmsAttachmentMapper .duplicateAttachment (eq (attachment ), eq (newFileId )))
390389 .thenReturn (duplicatedAttachment );
@@ -397,34 +396,34 @@ void duplicateTmsAttachment_ShouldSucceed_WhenValidAttachment() throws Exception
397396 assertNotNull (result );
398397 assertEquals (duplicatedAttachment , result );
399398
400- verify (attachmentDataStoreService ).load (attachment .getPathToFile ());
401- verify (attachmentDataStoreService ).save (anyString (), eq (originalFileStream ));
399+ verify (tmsAttachmentDataStoreService ).load (attachment .getPathToFile ());
400+ verify (tmsAttachmentDataStoreService ).save (anyString (), eq (originalFileStream ));
402401 verify (tmsAttachmentMapper ).duplicateAttachment (attachment , newFileId );
403402 verify (tmsAttachmentRepository ).save (duplicatedAttachment );
404403 }
405404
406405 @ Test
407406 void duplicateTmsAttachment_ShouldThrowException_WhenOriginalFileNotFound () {
408407 // Given original file does not exist in data store
409- when (attachmentDataStoreService .load (attachment .getPathToFile ())).thenReturn (Optional .empty ());
408+ when (tmsAttachmentDataStoreService .load (attachment .getPathToFile ())).thenReturn (Optional .empty ());
410409
411410 // When/Then exception should be thrown when original file is not found
412411 var exception = assertThrows (ReportPortalException .class ,
413412 () -> sut .duplicateTmsAttachment (attachment ));
414413
415414 assertEquals (ErrorType .BINARY_DATA_CANNOT_BE_SAVED , exception .getErrorType ());
416415
417- verify (attachmentDataStoreService ).load (attachment .getPathToFile ());
416+ verify (tmsAttachmentDataStoreService ).load (attachment .getPathToFile ());
418417 verifyNoInteractions (tmsAttachmentRepository );
419418 }
420419
421420 @ Test
422421 void duplicateTmsAttachment_ShouldThrowException_WhenDataStoreSaveFails () throws Exception {
423422 // Given original file exists but data store save operation fails
424423 var originalFileStream = new ByteArrayInputStream ("test content" .getBytes ());
425- when (attachmentDataStoreService .load (attachment .getPathToFile ()))
424+ when (tmsAttachmentDataStoreService .load (attachment .getPathToFile ()))
426425 .thenReturn (Optional .of (originalFileStream ));
427- when (attachmentDataStoreService .save (anyString (), any (InputStream .class )))
426+ when (tmsAttachmentDataStoreService .save (anyString (), any (InputStream .class )))
428427 .thenThrow (new RuntimeException ("Storage error" ));
429428
430429 // When/Then exception should be thrown when data store save fails
0 commit comments