|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.fineract.infrastructure.documentmanagement.service; |
| 20 | + |
| 21 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 22 | +import static org.mockito.ArgumentMatchers.anyString; |
| 23 | +import static org.mockito.Mockito.when; |
| 24 | + |
| 25 | +import java.util.Collections; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Optional; |
| 28 | +import org.apache.fineract.infrastructure.contentstore.detector.ContentDetectorManager; |
| 29 | +import org.apache.fineract.infrastructure.contentstore.service.ContentStoreService; |
| 30 | +import org.apache.fineract.infrastructure.documentmanagement.adapter.EntityImageIdAdapter; |
| 31 | +import org.apache.fineract.infrastructure.documentmanagement.domain.ImageRepository; |
| 32 | +import org.apache.fineract.infrastructure.documentmanagement.exception.DocumentNotFoundException; |
| 33 | +import org.junit.jupiter.api.BeforeEach; |
| 34 | +import org.junit.jupiter.api.Test; |
| 35 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 36 | +import org.mockito.Mock; |
| 37 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 38 | + |
| 39 | +@ExtendWith(MockitoExtension.class) |
| 40 | +class ImageReadPlatformServiceImplTest { |
| 41 | + |
| 42 | + @Mock |
| 43 | + private ImageRepository imageRepository; |
| 44 | + @Mock |
| 45 | + private ContentStoreService storeService; |
| 46 | + @Mock |
| 47 | + private ContentDetectorManager contentDetectorManager; |
| 48 | + @Mock |
| 49 | + private EntityImageIdAdapter imageIdAdapter; |
| 50 | + |
| 51 | + private ImageReadPlatformServiceImpl imageReadPlatformService; |
| 52 | + |
| 53 | + @BeforeEach |
| 54 | + void setUp() { |
| 55 | + List<EntityImageIdAdapter> imageIdAdapters = Collections.singletonList(imageIdAdapter); |
| 56 | + imageReadPlatformService = new ImageReadPlatformServiceImpl(imageIdAdapters, storeService, imageRepository, |
| 57 | + contentDetectorManager); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void testRetrieveImage_NotFound_ThrowsDocumentNotFoundException() { |
| 62 | + // Arrange |
| 63 | + String entityType = "clients"; |
| 64 | + Long entityId = 1L; |
| 65 | + |
| 66 | + when(imageIdAdapter.accept(anyString())).thenReturn(true); |
| 67 | + when(imageIdAdapter.get(entityId)).thenReturn(Optional.empty()); |
| 68 | + |
| 69 | + // Act & Assert |
| 70 | + assertThrows(DocumentNotFoundException.class, () -> { |
| 71 | + imageReadPlatformService.retrieveImage(entityType, entityId); |
| 72 | + }); |
| 73 | + } |
| 74 | +} |
0 commit comments