@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testRun() throws Exception { final EtmPoint point = mock(EtmPoint.class); mockStatic(PointFactory.class); when(PointFactory.getPoint(ScriptCompilerCommand.class, "run")).thenReturn(point); final String scriptName = "a_script"; when(sourceCodeLocation.getName()).thenReturn(scriptName + ".prg"); final URI listingLocationUri = URI.create("booo"); when(localListingFile.toURI()).thenReturn(listingLocationUri); final URI sourceCodeTargetLocation = URI.create("sourceTarget"); final CclResourceUploader uploader = prepareResourceUploader(); when(uploader.upload()).thenReturn(Collections.singletonMap(sourceCodeLocation, sourceCodeTargetLocation)); final String cerTemp = "cer_temp"; prepareEnvironment(cerTemp); final JSchSshTerminal sshTerminal = prepareTerminal(); final Downloader downloader = prepareDownloder(); final FileRequest request = mock(FileRequest.class); final ArgumentCaptor<URI> listingOriginCaptor = prepareUploadRequest(request, listingLocationUri); final CompileErrorValidator validator = prepareValidator(); final CclCommandTerminal cclTerminal = mock(CclCommandTerminal.class); final TerminalProperties basicTerminalProperties = TerminalProperties.getNewBuilder() .setOsPromptPattern("osPromptPattern").build(); when(cclTerminal.getTerminalProperties()).thenReturn(basicTerminalProperties); command.run(cclTerminal); verify(uploader).queueUpload(sourceCodeLocation); verify(uploader).queueUpload(dependency); verify(uploader).upload(); final ArgumentCaptor<List> commandsCaptor = ArgumentCaptor.forClass(List.class); verify(cclTerminal).executeCommands(eq(sshTerminal), commandsCaptor.capture(), eq(false)); final Iterator<String> commandsIterator = commandsCaptor.getValue().iterator(); assertThat(commandsIterator.next()).isEqualTo("call compile("); assertThat(commandsIterator.next()).startsWith("'" + sourceCodeTargetLocation.getPath() + "',"); assertThat(commandsIterator.next()).startsWith("'" + cerTemp + "/" + scriptName).endsWith(".out'") .isEqualTo("'" + listingOriginCaptor.getValue().getPath() + "'"); assertThat(commandsIterator.next()).isEqualTo(") go"); verify(downloader).download(Collections.singleton(request)); verify(validator).validate(localListingFile); verify(point).collect(); }
@Override public void run(final CclCommandTerminal terminal) { final EtmPoint point = PointFactory.getPoint(getClass(), "run"); try { final String objectName = parseObjectName(sourceCodeLocation); final CclResourceUploader uploader = CclResourceUploader.getUploader(); uploader.queueUpload(sourceCodeLocation); for (final File dependency : dependencies) uploader.queueUpload(dependency); final URI sourceCodeTargetLocation = uploader.upload().get(sourceCodeLocation); final String listingOutputFilename = createListingOutputFilename(objectName); final File finalListingDestination = localListingDestination == null ? createTemporaryFile(listingOutputFilename) : localListingDestination; final Environment environment = Environment.getEnvironment(); final URI listingTargetLocation = URI.create(environment.getCerTemp() + "/" + listingOutputFilename); try { final List<String> commands = new ArrayList<String>(); if (doDebugCompile) commands.add("SET COMPILE = DEBUG go"); commands.addAll(Arrays.asList("call compile(", "'" + sourceCodeTargetLocation.getPath() + "',", "'" + listingTargetLocation.getPath() + "'", ") go")); if (doDebugCompile) commands.add("SET COMPILE = NODEBUG go"); terminal.executeCommands(new JSchSshTerminal(), commands, false); } catch (final SshTimeoutException e) { throw new CclCompilationTimeoutException("Compilation of " + objectName + " timed out.", e); } catch (final SshException e) { throw new CclCommandException("Compilation of " + objectName + " failed.", e); } final Downloader downloader = SftpDownloader.createDownloader(AuthHelper.fromCurrentSubject()); downloader.download(Collections .singleton(FileRequestFactory.create(listingTargetLocation, finalListingDestination.toURI()))); logger.info("validating compile {}", listingOutputFilename); CompileErrorValidator.getInstance().validate(finalListingDestination); } finally { point.collect(); } }
ScriptCompilerCommand extends AbstractCclCommand { @Override public void run(final CclCommandTerminal terminal) { final EtmPoint point = PointFactory.getPoint(getClass(), "run"); try { final String objectName = parseObjectName(sourceCodeLocation); final CclResourceUploader uploader = CclResourceUploader.getUploader(); uploader.queueUpload(sourceCodeLocation); for (final File dependency : dependencies) uploader.queueUpload(dependency); final URI sourceCodeTargetLocation = uploader.upload().get(sourceCodeLocation); final String listingOutputFilename = createListingOutputFilename(objectName); final File finalListingDestination = localListingDestination == null ? createTemporaryFile(listingOutputFilename) : localListingDestination; final Environment environment = Environment.getEnvironment(); final URI listingTargetLocation = URI.create(environment.getCerTemp() + "/" + listingOutputFilename); try { final List<String> commands = new ArrayList<String>(); if (doDebugCompile) commands.add("SET COMPILE = DEBUG go"); commands.addAll(Arrays.asList("call compile(", "'" + sourceCodeTargetLocation.getPath() + "',", "'" + listingTargetLocation.getPath() + "'", ") go")); if (doDebugCompile) commands.add("SET COMPILE = NODEBUG go"); terminal.executeCommands(new JSchSshTerminal(), commands, false); } catch (final SshTimeoutException e) { throw new CclCompilationTimeoutException("Compilation of " + objectName + " timed out.", e); } catch (final SshException e) { throw new CclCommandException("Compilation of " + objectName + " failed.", e); } final Downloader downloader = SftpDownloader.createDownloader(AuthHelper.fromCurrentSubject()); downloader.download(Collections .singleton(FileRequestFactory.create(listingTargetLocation, finalListingDestination.toURI()))); logger.info("validating compile {}", listingOutputFilename); CompileErrorValidator.getInstance().validate(finalListingDestination); } finally { point.collect(); } } }
ScriptCompilerCommand extends AbstractCclCommand { @Override public void run(final CclCommandTerminal terminal) { final EtmPoint point = PointFactory.getPoint(getClass(), "run"); try { final String objectName = parseObjectName(sourceCodeLocation); final CclResourceUploader uploader = CclResourceUploader.getUploader(); uploader.queueUpload(sourceCodeLocation); for (final File dependency : dependencies) uploader.queueUpload(dependency); final URI sourceCodeTargetLocation = uploader.upload().get(sourceCodeLocation); final String listingOutputFilename = createListingOutputFilename(objectName); final File finalListingDestination = localListingDestination == null ? createTemporaryFile(listingOutputFilename) : localListingDestination; final Environment environment = Environment.getEnvironment(); final URI listingTargetLocation = URI.create(environment.getCerTemp() + "/" + listingOutputFilename); try { final List<String> commands = new ArrayList<String>(); if (doDebugCompile) commands.add("SET COMPILE = DEBUG go"); commands.addAll(Arrays.asList("call compile(", "'" + sourceCodeTargetLocation.getPath() + "',", "'" + listingTargetLocation.getPath() + "'", ") go")); if (doDebugCompile) commands.add("SET COMPILE = NODEBUG go"); terminal.executeCommands(new JSchSshTerminal(), commands, false); } catch (final SshTimeoutException e) { throw new CclCompilationTimeoutException("Compilation of " + objectName + " timed out.", e); } catch (final SshException e) { throw new CclCommandException("Compilation of " + objectName + " failed.", e); } final Downloader downloader = SftpDownloader.createDownloader(AuthHelper.fromCurrentSubject()); downloader.download(Collections .singleton(FileRequestFactory.create(listingTargetLocation, finalListingDestination.toURI()))); logger.info("validating compile {}", listingOutputFilename); CompileErrorValidator.getInstance().validate(finalListingDestination); } finally { point.collect(); } } ScriptCompilerCommand(final File sourceCodeLocation, final Collection<File> dependencies,
            final File localListingDestination, final boolean doDebugCompile); }
ScriptCompilerCommand extends AbstractCclCommand { @Override public void run(final CclCommandTerminal terminal) { final EtmPoint point = PointFactory.getPoint(getClass(), "run"); try { final String objectName = parseObjectName(sourceCodeLocation); final CclResourceUploader uploader = CclResourceUploader.getUploader(); uploader.queueUpload(sourceCodeLocation); for (final File dependency : dependencies) uploader.queueUpload(dependency); final URI sourceCodeTargetLocation = uploader.upload().get(sourceCodeLocation); final String listingOutputFilename = createListingOutputFilename(objectName); final File finalListingDestination = localListingDestination == null ? createTemporaryFile(listingOutputFilename) : localListingDestination; final Environment environment = Environment.getEnvironment(); final URI listingTargetLocation = URI.create(environment.getCerTemp() + "/" + listingOutputFilename); try { final List<String> commands = new ArrayList<String>(); if (doDebugCompile) commands.add("SET COMPILE = DEBUG go"); commands.addAll(Arrays.asList("call compile(", "'" + sourceCodeTargetLocation.getPath() + "',", "'" + listingTargetLocation.getPath() + "'", ") go")); if (doDebugCompile) commands.add("SET COMPILE = NODEBUG go"); terminal.executeCommands(new JSchSshTerminal(), commands, false); } catch (final SshTimeoutException e) { throw new CclCompilationTimeoutException("Compilation of " + objectName + " timed out.", e); } catch (final SshException e) { throw new CclCommandException("Compilation of " + objectName + " failed.", e); } final Downloader downloader = SftpDownloader.createDownloader(AuthHelper.fromCurrentSubject()); downloader.download(Collections .singleton(FileRequestFactory.create(listingTargetLocation, finalListingDestination.toURI()))); logger.info("validating compile {}", listingOutputFilename); CompileErrorValidator.getInstance().validate(finalListingDestination); } finally { point.collect(); } } ScriptCompilerCommand(final File sourceCodeLocation, final Collection<File> dependencies,
            final File localListingDestination, final boolean doDebugCompile); @Override void run(final CclCommandTerminal terminal); }
ScriptCompilerCommand extends AbstractCclCommand { @Override public void run(final CclCommandTerminal terminal) { final EtmPoint point = PointFactory.getPoint(getClass(), "run"); try { final String objectName = parseObjectName(sourceCodeLocation); final CclResourceUploader uploader = CclResourceUploader.getUploader(); uploader.queueUpload(sourceCodeLocation); for (final File dependency : dependencies) uploader.queueUpload(dependency); final URI sourceCodeTargetLocation = uploader.upload().get(sourceCodeLocation); final String listingOutputFilename = createListingOutputFilename(objectName); final File finalListingDestination = localListingDestination == null ? createTemporaryFile(listingOutputFilename) : localListingDestination; final Environment environment = Environment.getEnvironment(); final URI listingTargetLocation = URI.create(environment.getCerTemp() + "/" + listingOutputFilename); try { final List<String> commands = new ArrayList<String>(); if (doDebugCompile) commands.add("SET COMPILE = DEBUG go"); commands.addAll(Arrays.asList("call compile(", "'" + sourceCodeTargetLocation.getPath() + "',", "'" + listingTargetLocation.getPath() + "'", ") go")); if (doDebugCompile) commands.add("SET COMPILE = NODEBUG go"); terminal.executeCommands(new JSchSshTerminal(), commands, false); } catch (final SshTimeoutException e) { throw new CclCompilationTimeoutException("Compilation of " + objectName + " timed out.", e); } catch (final SshException e) { throw new CclCommandException("Compilation of " + objectName + " failed.", e); } final Downloader downloader = SftpDownloader.createDownloader(AuthHelper.fromCurrentSubject()); downloader.download(Collections .singleton(FileRequestFactory.create(listingTargetLocation, finalListingDestination.toURI()))); logger.info("validating compile {}", listingOutputFilename); CompileErrorValidator.getInstance().validate(finalListingDestination); } finally { point.collect(); } } ScriptCompilerCommand(final File sourceCodeLocation, final Collection<File> dependencies,
            final File localListingDestination, final boolean doDebugCompile); @Override void run(final CclCommandTerminal terminal);  }