Search in sources :

Example 1 with MarvelCharacter

use of br.com.thomasdacosta.handler.dto.MarvelCharacter in project bff-marvel-api by thomasdacosta.

the class ImageUtilTest method testCreateImage.

@Test
@Order(1)
@DisplayName("1 - Criando as imagens em um Bucket S3")
public void testCreateImage() throws URISyntaxException, IOException {
    S3Util.setAmazonS3(null);
    S3Util.setEndpointConfiguration(null);
    WireMockUtils.serverImage();
    S3Util.setEndpointConfiguration(LocalStackUtil.getLocalstack().getEndpointConfiguration(LocalStackContainer.Service.S3));
    AmazonS3 amazonS3 = S3Util.getS3(S3Util.Env.LOCALSTACK);
    Objects.requireNonNull(amazonS3).createBucket(Constants.BUCKET);
    ThumbnailCharacter thumbnailCharacter = new ThumbnailCharacter();
    thumbnailCharacter.setUrl("http://localhost:8082/imageMarvel");
    thumbnailCharacter.setExtension("jpg");
    MarvelCharacter marvelCharacter = new MarvelCharacter();
    marvelCharacter.setId(new BigDecimal(1011355));
    marvelCharacter.setName("Captain Midlands");
    ImageUtil.saveImage(thumbnailCharacter, marvelCharacter);
    ObjectListing files = amazonS3.listObjects(Constants.BUCKET);
    assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals("captain_midlands_1011355_portrait_uncanny.jpg")).count());
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) ThumbnailCharacter(br.com.thomasdacosta.handler.dto.ThumbnailCharacter) MarvelCharacter(br.com.thomasdacosta.handler.dto.MarvelCharacter) BigDecimal(java.math.BigDecimal) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest)

Example 2 with MarvelCharacter

use of br.com.thomasdacosta.handler.dto.MarvelCharacter in project bff-marvel-api by thomasdacosta.

the class ApplicationHandler method handleRequest.

public String handleRequest(final SQSEvent input, final Context context) {
    ObjectMapper objectMapper = new ObjectMapper();
    String url;
    String character;
    try {
        LoggerUtil.setLogger(context);
        LoggerUtil.log("## Executando Function");
        LoggerUtil.log("## Total de Mensagens:" + input.getRecords().size());
        for (SQSEvent.SQSMessage message : input.getRecords()) {
            LoggerUtil.log("## Processando Mensagem...");
            Notification notification = objectMapper.readValue(message.getBody(), Notification.class);
            url = notification.getMessage();
            Header header = notification.getMessageAttributes().get("marvelCharacter");
            character = header.getValue();
            ThumbnailCharacter thumbnailCharacter = objectMapper.readValue(url, ThumbnailCharacter.class);
            MarvelCharacter marvelCharacter = objectMapper.readValue(character, MarvelCharacter.class);
            ImageUtil.saveImage(thumbnailCharacter, marvelCharacter);
        }
    } catch (Exception ex) {
        LoggerUtil.error(ex);
        throw new FunctionMarvelWorkerException(ex.getMessage(), ex);
    }
    LoggerUtil.log("## Function Executada");
    return "## Function Executada";
}
Also used : Header(br.com.thomasdacosta.handler.dto.Header) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) ThumbnailCharacter(br.com.thomasdacosta.handler.dto.ThumbnailCharacter) MarvelCharacter(br.com.thomasdacosta.handler.dto.MarvelCharacter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Notification(br.com.thomasdacosta.handler.dto.Notification) FunctionMarvelWorkerException(br.com.thomasdacosta.handler.exception.FunctionMarvelWorkerException) FunctionMarvelWorkerException(br.com.thomasdacosta.handler.exception.FunctionMarvelWorkerException)

Aggregations

MarvelCharacter (br.com.thomasdacosta.handler.dto.MarvelCharacter)2 ThumbnailCharacter (br.com.thomasdacosta.handler.dto.ThumbnailCharacter)2 Header (br.com.thomasdacosta.handler.dto.Header)1 Notification (br.com.thomasdacosta.handler.dto.Notification)1 FunctionMarvelWorkerException (br.com.thomasdacosta.handler.exception.FunctionMarvelWorkerException)1 SQSEvent (com.amazonaws.services.lambda.runtime.events.SQSEvent)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMockTest (com.github.tomakehurst.wiremock.junit5.WireMockTest)1 BigDecimal (java.math.BigDecimal)1