@Test public void buildPreprocessedInput() { SecurityAnalysisExecutionInput executionInput = new SecurityAnalysisExecutionInput() .setNetworkVariant(mock(Network.class), "") .setParameters(new SecurityAnalysisParameters()); SecurityAnalysisPreprocessor preprocessor = mock(SecurityAnalysisPreprocessor.class); SecurityAnalysisPreprocessorFactory factory = mock(SecurityAnalysisPreprocessorFactory.class); when(factory.newPreprocessor(any())).thenReturn(preprocessor); SecurityAnalysisInput input = SecurityAnalysisTool.buildPreprocessedInput(executionInput, LimitViolationFilter::new, factory); assertSame(executionInput.getParameters(), input.getParameters()); assertSame(executionInput.getNetworkVariant(), input.getNetworkVariant()); verify(factory, times(0)).newPreprocessor(any()); executionInput.setContingenciesSource(ByteSource.empty()); SecurityAnalysisTool.buildPreprocessedInput(executionInput, LimitViolationFilter::new, factory); verify(factory, times(1)).newPreprocessor(any()); verify(preprocessor, times(1)).preprocess(any()); }
static SecurityAnalysisInput buildPreprocessedInput(SecurityAnalysisExecutionInput executionInput, Supplier<LimitViolationFilter> filterInitializer, SecurityAnalysisPreprocessorFactory preprocessorFactory) { SecurityAnalysisInput input = new SecurityAnalysisInput(executionInput.getNetworkVariant()) .setParameters(executionInput.getParameters()) .setFilter(filterInitializer.get()); executionInput.getResultExtensions().stream() .map(SecurityAnalysisInterceptors::createInterceptor) .forEach(input::addInterceptor); if (!executionInput.getViolationTypes().isEmpty()) { input.getFilter().setViolationTypes(ImmutableSet.copyOf(executionInput.getViolationTypes())); } executionInput.getContingenciesSource() .map(preprocessorFactory::newPreprocessor) .ifPresent(p -> p.preprocess(input)); return input; }
SecurityAnalysisTool implements Tool { static SecurityAnalysisInput buildPreprocessedInput(SecurityAnalysisExecutionInput executionInput, Supplier<LimitViolationFilter> filterInitializer, SecurityAnalysisPreprocessorFactory preprocessorFactory) { SecurityAnalysisInput input = new SecurityAnalysisInput(executionInput.getNetworkVariant()) .setParameters(executionInput.getParameters()) .setFilter(filterInitializer.get()); executionInput.getResultExtensions().stream() .map(SecurityAnalysisInterceptors::createInterceptor) .forEach(input::addInterceptor); if (!executionInput.getViolationTypes().isEmpty()) { input.getFilter().setViolationTypes(ImmutableSet.copyOf(executionInput.getViolationTypes())); } executionInput.getContingenciesSource() .map(preprocessorFactory::newPreprocessor) .ifPresent(p -> p.preprocess(input)); return input; } }
SecurityAnalysisTool implements Tool { static SecurityAnalysisInput buildPreprocessedInput(SecurityAnalysisExecutionInput executionInput, Supplier<LimitViolationFilter> filterInitializer, SecurityAnalysisPreprocessorFactory preprocessorFactory) { SecurityAnalysisInput input = new SecurityAnalysisInput(executionInput.getNetworkVariant()) .setParameters(executionInput.getParameters()) .setFilter(filterInitializer.get()); executionInput.getResultExtensions().stream() .map(SecurityAnalysisInterceptors::createInterceptor) .forEach(input::addInterceptor); if (!executionInput.getViolationTypes().isEmpty()) { input.getFilter().setViolationTypes(ImmutableSet.copyOf(executionInput.getViolationTypes())); } executionInput.getContingenciesSource() .map(preprocessorFactory::newPreprocessor) .ifPresent(p -> p.preprocess(input)); return input; }  }
SecurityAnalysisTool implements Tool { static SecurityAnalysisInput buildPreprocessedInput(SecurityAnalysisExecutionInput executionInput, Supplier<LimitViolationFilter> filterInitializer, SecurityAnalysisPreprocessorFactory preprocessorFactory) { SecurityAnalysisInput input = new SecurityAnalysisInput(executionInput.getNetworkVariant()) .setParameters(executionInput.getParameters()) .setFilter(filterInitializer.get()); executionInput.getResultExtensions().stream() .map(SecurityAnalysisInterceptors::createInterceptor) .forEach(input::addInterceptor); if (!executionInput.getViolationTypes().isEmpty()) { input.getFilter().setViolationTypes(ImmutableSet.copyOf(executionInput.getViolationTypes())); } executionInput.getContingenciesSource() .map(preprocessorFactory::newPreprocessor) .ifPresent(p -> p.preprocess(input)); return input; }  @Override Command getCommand(); @Override void run(CommandLine line, ToolRunningContext context); }
SecurityAnalysisTool implements Tool { static SecurityAnalysisInput buildPreprocessedInput(SecurityAnalysisExecutionInput executionInput, Supplier<LimitViolationFilter> filterInitializer, SecurityAnalysisPreprocessorFactory preprocessorFactory) { SecurityAnalysisInput input = new SecurityAnalysisInput(executionInput.getNetworkVariant()) .setParameters(executionInput.getParameters()) .setFilter(filterInitializer.get()); executionInput.getResultExtensions().stream() .map(SecurityAnalysisInterceptors::createInterceptor) .forEach(input::addInterceptor); if (!executionInput.getViolationTypes().isEmpty()) { input.getFilter().setViolationTypes(ImmutableSet.copyOf(executionInput.getViolationTypes())); } executionInput.getContingenciesSource() .map(preprocessorFactory::newPreprocessor) .ifPresent(p -> p.preprocess(input)); return input; }  @Override Command getCommand(); @Override void run(CommandLine line, ToolRunningContext context);  }