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());
}
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";
}
Aggregations