FossologyScriptsHandler { public RequestStatus deployScripts() throws SW360Exception { RequestStatus status = RequestStatus.SUCCESS; for (String scriptFileName : SCRIPT_FILE_NAMES) { final InputStream inputStream = FossologyScriptsHandler.class.getResourceAsStream(SCRIPTS_FOLDER + scriptFileName); if (inputStream == null) { log.error("cannot get content of script " + scriptFileName); status = RequestStatus.FAILURE; continue; } try { if (!fossologyUploader.copyToFossology(scriptFileName, inputStream, true)) { status = RequestStatus.FAILURE; } } finally { closeQuietly(inputStream, log); } } return status; } @Autowired  FossologyScriptsHandler(FossologyUploader fossologyUploader); RequestStatus deployScripts();  }
@Test public void testDeployScriptsCanOpenAllResourceFiles() throws Exception { when(fossologyUploader.copyToFossology(anyString(), any(InputStream.class), anyBoolean())).thenReturn(true); assertThat(fossologyScriptsHandler.deployScripts(), is(RequestStatus.SUCCESS)); verify(fossologyUploader, times(5)).copyToFossology(anyString(), any(InputStream.class), anyBoolean()); }
@Test public void testDeployScriptsReportsErrorOnUploadError() throws Exception { when(fossologyUploader.copyToFossology(anyString(), any(InputStream.class), anyBoolean())).thenReturn(true, false); assertThat(fossologyScriptsHandler.deployScripts(), is(RequestStatus.FAILURE)); verify(fossologyUploader, times(5)).copyToFossology(anyString(), any(InputStream.class), anyBoolean()); }