GeneratedOutputAttachmentHandler { GeneratedOutput attachGeneratedOutput(IUserContext userContext, ModelId modelId, String serviceKey, Map<String, String> requestParams, GeneratedOutput response, GeneratorPluginConfiguration plugin) { String filename = buildAttachmentFilename(modelId, serviceKey, requestParams, response, plugin); FileContent fc = new FileContent(filename, response.getContent()); modelRepositoryFactory.getRepositoryByModel(modelId, userContext) .attachFileInElevatedSession(modelId, fc, userContext, GeneratedOutputAttachmentHandler.tagsForRequest(plugin, requestParams)); return new GeneratedOutput(response.getContent(), filename, response.getSize()); } @Autowired  GeneratedOutputAttachmentHandler(IModelRepositoryFactory modelRepositoryFactory);   }
@Test public void attachGeneratedOutput() { 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))); when(modelRepositoryFactory.getRepositoryByModel(any(), any())).thenReturn(repository); IUserContext userContext = new IUserContext() { @Override public Authentication getAuthentication() { return null; } @Override public String getUsername() { return "testuser"; } @Override public String getWorkspaceId() { return null; } @Override public String getHashedUsername() { return null; } @Override public boolean isAnonymous() { return false; } @Override public boolean isSysAdmin() { return false; } }; GeneratedOutput generatedOutput = sut .getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository).get(); GeneratedOutput result = sut.attachGeneratedOutput(userContext, modelInfo.getId(), "eclipseditto", requestParams, generatedOutput, plugin); assertNotNull(result); assertEquals(1, result.getSize()); assertEquals("generated_eclipseditto_1.0.0_TestInfoModel.json", result.getFileName()); assertEquals(content, result.getContent()); }