OptimizedExportStrategy extends BaseSampleExportStrategy { @Override public boolean test(ExportParameters parameters) { if (parameters == null) { return false; } if (parameters.getContent() != null) { return false; } if (StringUtils.isEmpty(parameters.getPreparationId())) { return false; } final OptimizedPreparationInput optimizedPreparationInput = new OptimizedPreparationInput(parameters); return optimizedPreparationInput.applicable(); }  @Override boolean test(ExportParameters parameters); @Override StreamingResponseBody execute(ExportParameters parameters);  }
@Test public void testAcceptNullParameters() { assertFalse(optimizedExportStrategy.test(null)); }
@Test public void testAcceptKO_withContent() { ExportParameters exportParameters = new ExportParameters(); exportParameters.setContent(new DataSet()); assertFalse(optimizedExportStrategy.test(exportParameters)); }
@Test public void testAcceptKO_noPreparation() { ExportParameters exportParameters = new ExportParameters(); exportParameters.setDatasetId("1234"); assertFalse(optimizedExportStrategy.test(exportParameters)); }
@Ignore @Test(expected = TDPException.class) public void testAcceptKO_preparationNotExist() { ExportParameters exportParameters = new ExportParameters(); exportParameters.setPreparationId("1234"); assertFalse(optimizedExportStrategy.test(exportParameters)); }
@Test public void testAcceptKO_noStepId() { preparationRepository.add(new Preparation("prep-1234", "1234", Step.ROOT_STEP.id(), "0.1")); ExportParameters exportParameters = new ExportParameters(); exportParameters.setPreparationId("prep-1234"); assertFalse(optimizedExportStrategy.test(exportParameters)); }
@Test public void testAcceptKO_noMetadataCache() throws Exception { final String preparation = createEmptyPreparationFromDataset("1234", "test"); applyAction(preparation, "[{}]"); applyAction(preparation, "[{}]"); ExportParameters exportParameters = new ExportParameters(); exportParameters.setPreparationId(preparation); assertFalse(optimizedExportStrategy.test(exportParameters)); }
@Test public void testAcceptKO_withMetadataCacheNoContentCache() throws Exception { final String preparation = createEmptyPreparationFromDataset("1234", "test"); applyAction(preparation, "[{}]"); applyAction(preparation, "[{}]"); final PreparationDTO preparationDetails = getPreparation(preparation); for (String step : preparationDetails.getSteps()) { try (OutputStream content = contentCache.put(cacheKeyGenerator.generateMetadataKey(preparation, step, HEAD), ContentCache.TimeToLive.DEFAULT)) { content.write("{}".getBytes()); content.flush(); } } ExportParameters exportParameters = new ExportParameters(); exportParameters.setPreparationId(preparation); exportParameters.setFrom(HEAD); assertFalse(optimizedExportStrategy.test(exportParameters)); }
@Test public void testAcceptKO_stepIdIsRootStep() throws Exception { final String datasetId = "1234"; final String format = ""; final String preparation = createEmptyPreparationFromDataset(datasetId, "test"); applyAction(preparation, "[{}]"); applyAction(preparation, "[{}]"); final PreparationDTO preparationDetails = getPreparation(preparation); final List<String> stepsWithoutRootStep = new ArrayList<>(preparationDetails.getSteps()); stepsWithoutRootStep.remove(0); putTransformationAndMetadataInCacheForSteps(stepsWithoutRootStep, preparation, datasetId, format); ExportParameters exportParameters = new ExportParameters(); exportParameters.setPreparationId(preparation); exportParameters.setDatasetId(datasetId); exportParameters.setExportType(format); exportParameters.setFrom(HEAD); exportParameters.setStepId(Step.ROOT_STEP.id()); assertFalse("The OptimizedExportStrategy should not be acceptable if version is ROOT_STEP", optimizedExportStrategy.test(exportParameters)); }
@Test public void testAcceptOK() throws Exception { final String datasetId = "1234"; final String format = ""; final String preparation = createEmptyPreparationFromDataset(datasetId, "test"); applyAction(preparation, "[{}]"); applyAction(preparation, "[{}]"); final PreparationDTO preparationDetails = getPreparation(preparation); putTransformationAndMetadataInCacheForSteps(preparationDetails.getSteps(), preparation, datasetId, format); ExportParameters exportParameters = new ExportParameters(); exportParameters.setPreparationId(preparation); exportParameters.setDatasetId(datasetId); exportParameters.setExportType(format); exportParameters.setFrom(HEAD); assertTrue(optimizedExportStrategy.test(exportParameters)); }