GeneratedOutputAttachmentHandler { Optional<GeneratedOutput> getGeneratedOutputFromAttachment(ModelInfo modelInfo, Map<String, String> requestParams, GeneratorPluginConfiguration plugin, IModelRepository repository) { List<Attachment> attachments = repository .getAttachmentsByTags(modelInfo.getId(), Sets.newHashSet( GeneratedOutputAttachmentHandler.tagsForRequest(plugin, requestParams))); if (Objects.nonNull(attachments)) { return attachments.stream() .findFirst() .map(Attachment::getFilename) .flatMap(fileName -> repository.getAttachmentContent(modelInfo.getId(), fileName)) .map(MAP_TO_GENERATED_OUTPUT); } return Optional.empty(); } @Autowired  GeneratedOutputAttachmentHandler(IModelRepositoryFactory modelRepositoryFactory);   }
@Test public void getGeneratedOutputFromAttachment() { String filename = "thiswasgenerated.json"; byte[] content = {0x01}; List<Attachment> attList = new ArrayList<>(); ModelId id = new ModelId(); id.setName("TestInfoModel"); attList.add(Attachment.newInstance(id, filename)); when(repository.getAttachmentsByTags(any(), any())).thenReturn(attList); ModelInfo modelInfo = new ModelInfo(); modelInfo.setId(id); Map<String, String> requestParams = new HashMap<>(); GeneratorPluginConfiguration plugin = GeneratorPluginConfiguration .of("eclipseditto", "v2", "http: when(repository.getAttachmentContent(any(), any())) .thenReturn(Optional.of(new FileContent(filename, content))); Optional<GeneratedOutput> result = sut .getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository); assertTrue(result.isPresent()); assertEquals(content, result.get().getContent()); assertEquals(filename, result.get().getFileName()); assertEquals(1, result.get().getSize()); }