SecurityAnalysisExecutionHandlers { public static ExecutionHandler<SecurityAnalysisResult> forwarded(SecurityAnalysisExecutionInput input) { return forwarded(input, null); } private  SecurityAnalysisExecutionHandlers(); static ExecutionHandler<SecurityAnalysisResult> forwarded(SecurityAnalysisExecutionInput input); static ExecutionHandler<SecurityAnalysisResult> forwarded(SecurityAnalysisExecutionInput input, Integer forwardedTaskCount); static ExecutionHandler<SecurityAnalysisResultWithLog> forwardedWithLogs(SecurityAnalysisExecutionInput input); static ExecutionHandler<SecurityAnalysisResultWithLog> forwardedWithLogs(SecurityAnalysisExecutionInput input, Integer forwardedTaskCount); static ExecutionHandler<SecurityAnalysisResult> distributed(SecurityAnalysisExecutionInput input, int subtaskCount); static ExecutionHandler<SecurityAnalysisResultWithLog> distributedWithLog(SecurityAnalysisExecutionInput input, int subtaskCount); static SecurityAnalysisResult readSingleResult(Path workingDir); static SecurityAnalysisResultWithLog readSingleResultWithLogs(Path workingDir); static void forwardedOptions(Path workingDir, SecurityAnalysisCommandOptions options, Integer taskCount); static void forwardedWithLogsOptions(Path workingDir, SecurityAnalysisCommandOptions options, Integer taskCount); static void distributedOptions(Path workingDir, SecurityAnalysisCommandOptions options, int taskCount); static void distributedWithLogsOptions(Path workingDir, SecurityAnalysisCommandOptions options, int taskCount); static Path getOutputPathForTask(Path workingDir, int taskIndex); static SecurityAnalysisResult readResults(Path workingDir, int subtaskCount); static SecurityAnalysisResultWithLog readResultsWithLogs(Path workingDir, int subtaskCount); static Path getLogPathForTask(Path workingDir, int taskNumber); static Path getLogPath(Path workingDir);  }
@Test public void forwardedBeforeWithPartialInput() throws IOException { SecurityAnalysisExecutionInput input = new SecurityAnalysisExecutionInput(); input.setParameters(new SecurityAnalysisParameters()); input.setNetworkVariant(EurostagTutorialExample1Factory.create(), VariantManagerConstants.INITIAL_VARIANT_ID); ExecutionHandler<SecurityAnalysisResult> handler = SecurityAnalysisExecutionHandlers.forwarded(input); List<CommandExecution> commandExecutions = handler.before(workingDir); assertEquals(1, commandExecutions.size()); CommandExecution commandExecution = commandExecutions.get(0); assertEquals(1, commandExecution.getExecutionCount()); SimpleCommand command = (SimpleCommand) commandExecution.getCommand(); assertNotNull(command); String expectedDefaultProgram = SystemUtils.IS_OS_WINDOWS ? "itools.bat" : "itools"; assertEquals(expectedDefaultProgram, command.getProgram()); List<String> args = command.getArgs(0); assertThat(args).first().isEqualTo("security-analysis"); assertThat(args.subList(1, args.size())) .containsExactlyInAnyOrder("--case-file=/work/network.xiidm", "--parameters-file=/work/parameters.json", "--output-file=/work/result.json", "--output-format=JSON"); assertThat(workingDir.resolve("network.xiidm")).exists(); assertThat(workingDir.resolve("parameters.json")).exists(); }
@Test public void forwardedAfter() throws IOException { try (Writer writer = Files.newBufferedWriter(workingDir.resolve("result.json"))) { new JsonSecurityAnalysisResultExporter().export(SecurityAnalysisResult.empty(), writer); } ExecutionHandler<SecurityAnalysisResult> handler = SecurityAnalysisExecutionHandlers.forwarded(new SecurityAnalysisExecutionInput()); SecurityAnalysisResult result = handler.after(workingDir, DefaultExecutionReport.ok()); assertNotNull(result); assertTrue(result.getPreContingencyResult().isComputationOk()); assertTrue(result.getPreContingencyResult().getLimitViolations().isEmpty()); assertTrue(result.getPostContingencyResults().isEmpty()); }
@Test public void forwardedBeforeWithCompleteInput() throws IOException { SecurityAnalysisExecutionInput input = new SecurityAnalysisExecutionInput() .setParameters(new SecurityAnalysisParameters()) .setNetworkVariant(EurostagTutorialExample1Factory.create(), VariantManagerConstants.INITIAL_VARIANT_ID) .setContingenciesSource(ByteSource.wrap("contingencies definition".getBytes(StandardCharsets.UTF_8))) .addResultExtensions(ImmutableList.of("ext1", "ext2")) .addViolationTypes(ImmutableList.of(LimitViolationType.CURRENT)); ExecutionHandler<SecurityAnalysisResult> handler = SecurityAnalysisExecutionHandlers.forwarded(input, 12); Path workingDir = fileSystem.getPath("/work"); List<CommandExecution> commandExecutions = handler.before(workingDir); SimpleCommand command = (SimpleCommand) commandExecutions.get(0).getCommand(); List<String> args = command.getArgs(0); assertThat(args.subList(1, args.size())) .containsExactlyInAnyOrder("--case-file=/work/network.xiidm", "--parameters-file=/work/parameters.json", "--output-file=/work/result.json", "--output-format=JSON", "--contingencies-file=/work/contingencies.groovy", "--with-extensions=ext1,ext2", "--limit-types=CURRENT", "--task-count=12"); assertThat(workingDir.resolve("network.xiidm")).exists(); assertThat(workingDir.resolve("parameters.json")).exists(); assertThat(workingDir.resolve("contingencies.groovy")).exists(); }