Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.7 kB
3
Indexable
Never
@RunWith(MockitoJUnitRunner.class)
public class ProductImageBlobServiceImplTest {

    @Mock
    private E075derImageRepositoryImpl e075derImageRepositoryCustom;

    @Mock
    private BlobServiceStub blobServiceStub;

    @Mock
    private RequestDownloadsOutput requestDownloadsOutput;

    @InjectMocks
    private ProductImageBlobServiceImpl productImageBlobService;

    private static final UUID E120PED_ID = UUID.randomUUID();
    private static final String DOMAIN_NAME = "erpx_fnd";
    private static final String SERVICE_NAME = "produto";
    private static final String AREA_SECRET = "PUHQSYX3BASRQJUG4V03WAI9IT158HEO";
    private static final String TARGET_OBJECT_ID = UUID.randomUUID().toString();
    private static final String FILE_NAME = "image.jpg";
    private static final String VERSION = "1.0.0";
    private static final String URI = "https://www.example.com/image.jpg";
    private static final String CODE = "PROD_01";
    private static final String DESCRIPTION = "Product Image 01";

    @Test
    public void testRetrieveProductFilesFromBlobService() {
        // Arrange
        List<E075derImageEntity> e075derImages = new ArrayList<>();
        E075derImageEntity e075derImageEntity = new E075derImageEntity();
        e075derImageEntity.setTargetObjectId(TARGET_OBJECT_ID);
        e075derImageEntity.setFileName(FILE_NAME);
        e075derImageEntity.setVersion(VERSION);
        E075derEntity e075derEntity = new E075derEntity();
        e075derEntity.setCodDer(CODE);
        e075derEntity.setDesDer(DESCRIPTION);
        e075derImageEntity.setE075der(e075derEntity);
        e075derImages.add(e075derImageEntity);
        when(e075derImageRepositoryCustom.listProductImagesByE120ped(E120PED_ID)).thenReturn(e075derImages);

        BlobDetail blobDetail = new BlobDetail();
        blobDetail.targetObjectId = TARGET_OBJECT_ID;
        blobDetail.fileName = FILE_NAME;
        blobDetail.version = VERSION;
        blobDetail.location = new BlobLocation();
        blobDetail.location.uri = URI;
        when(requestDownloadsOutput.blobDetails).thenReturn(Collections.singletonList(blobDetail));
        when(blobServiceStub.requestDownloads(any(RequestDownloadsInput.class), anyLong())).thenReturn(requestDownloadsOutput);

        // Act
        List<ProductFile> productFiles = productImageBlobService.retrieveProductFilesFromBlobService(E120PED_ID);

        // Assert
        assertEquals(1, productFiles.size());
        ProductFile productFile = productFiles.get(0);
        assertEquals(CODE, productFile.getCode());
        assertEquals(DESCRIPTION, productFile.getDescription());
        assertEquals(URI, productFile.getUrl());
    }
}