PreparationExportStrategy extends BaseSampleExportStrategy { @Override public StreamingResponseBody execute(final ExportParameters parameters) { final String formatName = parameters.getExportType(); final ExportFormat format = getFormat(formatName); ExportUtils.setExportHeaders(parameters.getExportName(), parameters.getArguments().get(ExportFormat.PREFIX + CSVFormat.ParametersCSV.ENCODING), format); return outputStream -> performPreparation(parameters, outputStream); }  @Override boolean test(final ExportParameters parameters); @Override StreamingResponseBody execute(final ExportParameters parameters); void performPreparation(final ExportParameters parameters, final OutputStream outputStream);  }
@Test public void shouldUsedVersionedPreparation() throws IOException { final ExportParameters parameters = new ExportParameters(); parameters.setExportType("JSON"); parameters.setPreparationId("prep-1234"); parameters.setStepId("step-1234"); final PreparationDTO preparation = new PreparationDTO(); preparation.setId("prep-1234"); preparation.setHeadId("step-1234"); configurePreparation(preparation, "prep-1234", "step-1234"); final StreamingResponseBody body = strategy.execute(parameters); body.writeTo(new NullOutputStream()); final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class); verify(transformer).buildExecutable(any(), captor.capture()); assertEquals("prep-1234", captor.getValue().getPreparationId()); assertEquals("step-1234", captor.getValue().getPreparation().getHeadId()); }
@Test public void shouldUsedHeadPreparation() throws IOException { final ExportParameters parameters = new ExportParameters(); parameters.setExportType("JSON"); parameters.setPreparationId("prep-1234"); parameters.setStepId("head"); final PreparationDTO preparation = new PreparationDTO(); preparation.getSteps().add(Step.ROOT_STEP.id()); preparation.setId("prep-1234"); preparation.setHeadId("head"); configurePreparation(preparation, "prep-1234", "head"); final StreamingResponseBody body = strategy.execute(parameters); body.writeTo(new NullOutputStream()); final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class); verify(transformer).buildExecutable(any(), captor.capture()); assertEquals("prep-1234", captor.getValue().getPreparationId()); assertEquals("head", captor.getValue().getPreparation().getHeadId()); }