List of usage examples for org.springframework.util StringUtils commaDelimitedListToStringArray
public static String[] commaDelimitedListToStringArray(@Nullable String str)
From source file:org.geoserver.security.RESTfulDefinitionSource.java
private void processPathList(String pathToRoleList) throws IllegalArgumentException { /*/*from w w w. j a v a 2 s. c om*/ FilterInvocationDefinitionDecorator source = new FilterInvocationDefinitionDecorator(); source.setDecorated( delegate ); source.setConvertUrlToLowercaseBeforeComparison( true ); */ delegate.setConvertUrlToLowercaseBeforeComparison(true); BufferedReader br = new BufferedReader(new StringReader(pathToRoleList)); int counter = 0; String line; List<RESTfulDefinitionSourceMapping> mappings = new ArrayList<RESTfulDefinitionSourceMapping>(); while (true) { counter++; try { line = br.readLine(); } catch (IOException ioe) { throw new IllegalArgumentException(ioe.getMessage()); } if (line == null) { break; } line = line.trim(); if (log.isDebugEnabled()) { log.debug("Line " + counter + ": " + line); } if (line.startsWith("//")) { continue; } // Skip lines that are not directives if (line.lastIndexOf('=') == -1) { continue; } if (line.lastIndexOf("==") != -1) { throw new IllegalArgumentException("Only single equals should be used in line " + line); } // Tokenize the line into its name/value tokens // As per SEC-219, use the LAST equals as the delimiter between LHS and RHS String name = substringBeforeLast(line, "="); String value = substringAfterLast(line, "="); if (!StringUtils.hasText(name) || !StringUtils.hasText(value)) { throw new IllegalArgumentException("Failed to parse a valid name/value pair from " + line); } String antPath = name; String methods = null; int firstColonIndex = name.indexOf(":"); if (log.isDebugEnabled()) log.debug("~~~~~~~~~~ name= " + name + " firstColonIndex= " + firstColonIndex); if (firstColonIndex != -1) { antPath = name.substring(0, firstColonIndex); methods = name.substring((firstColonIndex + 1), name.length()); } if (log.isDebugEnabled()) log.debug("~~~~~~~~~~ name= " + name + " antPath= " + antPath + " methods= " + methods); String[] methodList = null; if (methods != null) { methodList = methods.split(","); // Verify methodList is valid for (int ii = 0; ii < methodList.length; ii++) { boolean matched = false; for (int jj = 0; jj < validMethodNames.length; jj++) { if (methodList[ii].equals(validMethodNames[jj])) { matched = true; break; } } if (!matched) { throw new IllegalArgumentException("The HTTP Method Name (" + methodList[ii] + " does NOT equal a valid name (GET,PUT,POST,DELETE)"); } } } if (log.isDebugEnabled()) { log.debug("methodList = " + Arrays.toString(methodList)); } // Should all be lowercase; check each character // We only do this for Ant (regexp have control chars) for (int i = 0; i < antPath.length(); i++) { String character = antPath.substring(i, i + 1); if (!character.toLowerCase().equals(character)) { throw new IllegalArgumentException( "You are using Ant Paths, yet you have specified an uppercase character in line: " + line + " (character '" + character + "')"); } } RESTfulDefinitionSourceMapping mapping = new RESTfulDefinitionSourceMapping(); mapping.setUrl(antPath); mapping.setHttpMethods(methodList); String[] tokens = StringUtils.commaDelimitedListToStringArray(value); for (int i = 0; i < tokens.length; i++) { mapping.addConfigAttribute(new SecurityConfig(tokens[i].trim())); } mappings.add(mapping); } // This will call the addSecureUrl in RESTfulPathBasedFilterInvocationDefinitionMap // which is how this whole convoluted beast gets wired together //source.setMappings(mappings); setMappings(mappings); }
From source file:org.LexGrid.LexBIG.gui.load.LoaderExtensionShell.java
/** * Builds the gui.//from w ww. ja v a 2 s. co m * * @param shell the shell * @param loader the loader */ private void buildGUI(final Shell shell, final Loader loader) { Group options = new Group(shell, SWT.NONE); options.setText("Load Options"); shell.setLayout(new GridLayout()); GridData gd = new GridData(GridData.FILL_HORIZONTAL); options.setLayoutData(gd); GridLayout layout = new GridLayout(1, false); options.setLayout(layout); Group groupUri = new Group(options, SWT.NONE); groupUri.setLayout(new GridLayout(3, false)); groupUri.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); String uriHelp = "The URI of the resource to load."; Label label = new Label(groupUri, SWT.NONE); label.setText("URI:"); label.setToolTipText(uriHelp); final Text file = new Text(groupUri, SWT.BORDER); file.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL)); file.setToolTipText(uriHelp); OptionHolder optionHolder = loader.getOptions(); final Button uriChooseButton; if (optionHolder.isResourceUriFolder()) { uriChooseButton = Utility.getFolderChooseButton(groupUri, file); } else { uriChooseButton = Utility.getFileChooseButton(groupUri, file, optionHolder.getResourceUriAllowedFileTypes().toArray(new String[0]), optionHolder.getResourceUriAllowedFileTypes().toArray(new String[0])); } uriChooseButton.setToolTipText(uriHelp); // Get resolved value sets LexEVSResolvedValueSetService resolvedValueSetService = new LexEVSResolvedValueSetServiceImpl(); java.util.List<CodingScheme> resolvedValueSets = null; try { resolvedValueSets = resolvedValueSetService.listAllResolvedValueSets(); } catch (LBException e) { resolvedValueSets = null; } for (final URIOption uriOption : optionHolder.getURIOptions()) { Composite group1 = new Composite(options, SWT.NONE); group1.setLayout(new GridLayout(3, false)); group1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label uriOptionLable = new Label(group1, SWT.NONE); uriOptionLable.setText(uriOption.getOptionName() + ":"); uriOptionLable.setToolTipText(uriOption.getHelpText()); final Text uriOptionFile = new Text(group1, SWT.BORDER); uriOptionFile.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL)); uriOptionFile.setToolTipText(uriOption.getHelpText()); Button uriOptionfileChooseButton = Utility.getFileChooseButton(group1, uriOptionFile, uriOption.getAllowedFileExtensions().toArray(new String[0]), null); uriOptionfileChooseButton.setToolTipText(uriOption.getHelpText()); uriOptionfileChooseButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent arg0) { // } public void widgetSelected(SelectionEvent arg0) { try { uriOption.setOptionValue(Utility.getAndVerifyURIFromTextField(uriOptionFile)); } catch (Exception e) { throw new RuntimeException(e); } } }); } for (final Option<Boolean> boolOption : optionHolder.getBooleanOptions()) { Composite group2 = new Composite(options, SWT.NONE); RowLayout rlo = new RowLayout(); rlo.marginWidth = 0; group2.setLayout(rlo); final Button button = new Button(group2, SWT.CHECK); button.setText(boolOption.getOptionName()); button.setToolTipText(boolOption.getHelpText()); if (boolOption.getOptionValue() != null) { button.setSelection(boolOption.getOptionValue()); } button.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) { // } public void widgetSelected(SelectionEvent event) { boolOption.setOptionValue(button.getSelection()); } }); } for (final Option<String> stringOption : optionHolder.getStringOptions()) { Composite group3 = new Composite(options, SWT.NONE); RowLayout rlo = new RowLayout(); rlo.marginWidth = 0; group3.setLayout(rlo); Label textLabel = new Label(group3, SWT.NONE); textLabel.setText(stringOption.getOptionName() + ":"); textLabel.setToolTipText(stringOption.getHelpText()); if (CollectionUtils.isNotEmpty(stringOption.getPickList())) { final Combo comboDropDown = new Combo(group3, SWT.DROP_DOWN | SWT.BORDER); comboDropDown.setToolTipText(stringOption.getHelpText()); for (String pickListItem : stringOption.getPickList()) { // Add if it is not a resolved value set if (resolvedValueSets != null && !isResolvedValueSet(resolvedValueSets, pickListItem)) { comboDropDown.add(pickListItem); } } comboDropDown.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0) { // } @Override public void widgetSelected(SelectionEvent event) { String option = comboDropDown.getItem(comboDropDown.getSelectionIndex()); stringOption.setOptionValue(option); } }); } else { final Text text = new Text(group3, SWT.BORDER); RowData textGd = new RowData(); textGd.width = 25; text.setLayoutData(textGd); text.setToolTipText(stringOption.getHelpText()); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { stringOption.setOptionValue(text.getText()); } }); } } for (final Option<Integer> integerOption : optionHolder.getIntegerOptions()) { Composite group3 = new Composite(options, SWT.NONE); RowLayout rlo = new RowLayout(); rlo.marginWidth = 0; group3.setLayout(rlo); Label textLabel = new Label(group3, SWT.NONE); textLabel.setText(integerOption.getOptionName() + ":"); textLabel.setToolTipText(integerOption.getHelpText()); final Text text = new Text(group3, SWT.BORDER); text.setToolTipText(integerOption.getHelpText()); if (integerOption.getOptionValue() != null) { text.setText(integerOption.getOptionValue().toString()); } text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { integerOption.setOptionValue(Integer.parseInt(text.getText())); } }); } for (final MultiValueOption<String> stringArrayOption : optionHolder.getStringArrayOptions()) { Composite group4 = new Composite(options, SWT.NONE); RowLayout rlo = new RowLayout(); rlo.marginWidth = 0; group4.setLayout(rlo); Label textLabel = new Label(group4, SWT.NONE); String appendString = CollectionUtils.isNotEmpty(stringArrayOption.getPickList()) ? "" : "\n\t(Comma Seperated):"; textLabel.setText(stringArrayOption.getOptionName() + appendString); textLabel.setToolTipText(stringArrayOption.getHelpText()); if (CollectionUtils.isNotEmpty(stringArrayOption.getPickList())) { final List multi = new List(group4, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); multi.setToolTipText(stringArrayOption.getHelpText()); for (String pickListItem : stringArrayOption.getPickList()) { multi.add(pickListItem); } for (int i = 0; i < stringArrayOption.getPickList().size(); i++) { if (stringArrayOption.getOptionValue().contains(stringArrayOption.getPickList().get(i))) { multi.select(i); } } multi.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0) { // } @Override public void widgetSelected(SelectionEvent event) { String[] options = multi.getSelection(); stringArrayOption.setOptionValue(Arrays.asList(options)); } }); } else { final Text text = new Text(group4, SWT.BORDER); text.setToolTipText(stringArrayOption.getHelpText()); String arrayString = StringUtils .collectionToCommaDelimitedString(stringArrayOption.getOptionValue()); text.setText(arrayString); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { String[] options = StringUtils.commaDelimitedListToStringArray(text.getText()); stringArrayOption.setOptionValue(Arrays.asList(options)); } }); } } Group groupControlButtons = new Group(options, SWT.NONE); groupControlButtons.setLayout(new GridLayout(3, false)); groupControlButtons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Button load = new Button(groupControlButtons, SWT.PUSH); final Button nextLoad = new Button(groupControlButtons, SWT.PUSH); final Button close = new Button(groupControlButtons, SWT.PUSH); close.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, true, 1, 1)); load.setText("Load"); load.setToolTipText("Start Load Process."); load.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { URI uri = null; // is this a local file? File theFile = new File(file.getText()); if (theFile.exists()) { uri = theFile.toURI(); } else { // is it a valid URI (like http://something) try { uri = new URI(file.getText()); uri.toURL().openConnection(); } catch (Exception e) { dialog_.showError("Path Error", "No file could be located at this location"); return; } } setLoading(true); load.setEnabled(false); close.setEnabled(false); loader.load(uri); // Create/start a new thread to update the buttons when the load completes. ButtonUpdater buttonUpdater = new ButtonUpdater(nextLoad, close, loader); Thread t = new Thread(buttonUpdater); t.setDaemon(true); t.start(); } public void widgetDefaultSelected(SelectionEvent arg0) { // } }); nextLoad.setText("Next Load"); nextLoad.setToolTipText("Start a New Load Process."); nextLoad.setEnabled(false); nextLoad.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { Loader newLoader = null; try { newLoader = lb_gui_.getLbs().getServiceManager(null).getLoader(loader.getName()); } catch (LBException e) { e.printStackTrace(); } if (!isLoading()) { // close the current window and create/initialize it again with the same loader shell.dispose(); setMonitorLoader(true); initializeLBGui(newLoader); } } public void widgetDefaultSelected(SelectionEvent arg0) { // } }); close.setText("Close"); close.setToolTipText("Close this Loader Window."); close.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { shell.dispose(); } public void widgetDefaultSelected(SelectionEvent arg0) { // } }); Composite status = getStatusComposite(shell, loader); gd = new GridData(GridData.FILL_BOTH); status.setLayoutData(gd); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanNonBufferingTests.java
/** * Check items causing errors are skipped as expected. */// www . j a v a 2 s. c o m @Test public void testSkip() throws Exception { @SuppressWarnings("unchecked") SkipListener<Integer, String> skipListener = mock(SkipListener.class); skipListener.onSkipInWrite("3", exception); skipListener.onSkipInWrite("4", exception); factory.setListeners(new SkipListener[] { skipListener }); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals(2, stepExecution.getSkipCount()); assertEquals(0, stepExecution.getReadSkipCount()); assertEquals(2, stepExecution.getWriteSkipCount()); // only one exception caused rollback, and only once in this case // because all items in that chunk were skipped immediately assertEquals(1, stepExecution.getRollbackCount()); assertFalse(writer.written.contains("4")); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,5")); assertEquals(expectedOutput, writer.written); // 5 items + 1 rollbacks reading 2 items each time assertEquals(7, stepExecution.getReadCount()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@SuppressWarnings("unchecked") @Test//from ww w. ja v a 2 s . c om public void testSkipAndRetryWithWriteFailure() throws Exception { factory.setListeners(new StepListener[] { new SkipListenerSupport<String, String>() { @Override public void onSkipInWrite(String item, Throwable t) { recovered.add(item); assertTrue(TransactionSynchronizationManager.isActualTransactionActive()); } } }); factory.setSkipLimit(2); ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("a", "b", "c", "d", "e", "f")) { @Override public String read() { String item = super.read(); logger.debug("Read Called! Item: [" + item + "]"); provided.add(item); count++; return item; } }; ItemWriter<String> itemWriter = new ItemWriter<String>() { @Override public void write(List<? extends String> item) throws Exception { logger.debug("Write Called! Item: [" + item + "]"); processed.addAll(item); written.addAll(item); if (item.contains("b") || item.contains("d")) { throw new RuntimeException("Write error - planned but recoverable."); } } }; factory.setItemReader(provider); factory.setItemWriter(itemWriter); factory.setRetryLimit(5); factory.setRetryableExceptionClasses(getExceptionMap(RuntimeException.class)); AbstractStep step = (AbstractStep) factory.getObject(); step.setName("mytest"); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); assertEquals(2, recovered.size()); assertEquals(2, stepExecution.getSkipCount()); assertEquals(2, stepExecution.getWriteSkipCount()); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("a,c,e,f")); assertEquals(expectedOutput, written); assertEquals("[a, b, c, d, e, f, null]", provided.toString()); assertEquals("[a, b, b, b, b, b, b, c, d, d, d, d, d, d, e, f]", processed.toString()); assertEquals("[b, d]", recovered.toString()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@SuppressWarnings("unchecked") @Test//from w w w . j a v a2s.c om public void testSkipAndRetryWithWriteFailureAndNonTrivialCommitInterval() throws Exception { factory.setCommitInterval(3); factory.setListeners(new StepListener[] { new SkipListenerSupport<String, String>() { @Override public void onSkipInWrite(String item, Throwable t) { recovered.add(item); assertTrue(TransactionSynchronizationManager.isActualTransactionActive()); } } }); factory.setSkipLimit(2); ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("a", "b", "c", "d", "e", "f")) { @Override public String read() { String item = super.read(); logger.debug("Read Called! Item: [" + item + "]"); provided.add(item); count++; return item; } }; ItemWriter<String> itemWriter = new ItemWriter<String>() { @Override public void write(List<? extends String> item) throws Exception { logger.debug("Write Called! Item: [" + item + "]"); processed.addAll(item); written.addAll(item); if (item.contains("b") || item.contains("d")) { throw new RuntimeException("Write error - planned but recoverable."); } } }; factory.setItemReader(provider); factory.setItemWriter(itemWriter); factory.setRetryLimit(5); factory.setRetryableExceptionClasses(getExceptionMap(RuntimeException.class)); AbstractStep step = (AbstractStep) factory.getObject(); step.setName("mytest"); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); assertEquals(2, recovered.size()); assertEquals(2, stepExecution.getSkipCount()); assertEquals(2, stepExecution.getWriteSkipCount()); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("a,c,e,f")); assertEquals(expectedOutput, written); // [a, b, c, d, e, f, null] assertEquals(7, provided.size()); // [a, b, c, a, b, c, a, b, c, a, b, c, a, b, c, a, b, c, d, e, f, d, // e, f, d, e, f, d, e, f, d, e, f, d, e, f] // System.err.println(processed); assertEquals(36, processed.size()); // [b, d] assertEquals(2, recovered.size()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@Test public void testRetryWithNoSkip() throws Exception { factory.setRetryLimit(4);//from w w w.j av a2s. com factory.setSkipLimit(0); ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("b")) { @Override public String read() { String item = super.read(); provided.add(item); count++; return item; } }; ItemWriter<String> itemWriter = new ItemWriter<String>() { @Override public void write(List<? extends String> item) throws Exception { processed.addAll(item); written.addAll(item); logger.debug("Write Called! Item: [" + item + "]"); throw new RuntimeException("Write error - planned but retryable."); } }; factory.setItemReader(provider); factory.setItemWriter(itemWriter); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("")); assertEquals(expectedOutput, written); assertEquals(0, stepExecution.getSkipCount()); // [b] assertEquals(1, provided.size()); // the failed items are tried up to the limit (but only precisely so if // the commit interval is 1) assertEquals("[b, b, b, b, b]", processed.toString()); // [] assertEquals(0, recovered.size()); assertEquals(1, stepExecution.getReadCount()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@SuppressWarnings("unchecked") @Test// w ww .ja v a 2 s .com public void testNonSkippableException() throws Exception { // Very specific skippable exception factory.setSkippableExceptionClasses(getExceptionMap(UnsupportedOperationException.class)); // ...which is not retryable... factory.setRetryableExceptionClasses(getExceptionMap()); factory.setSkipLimit(1); ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("b")) { @Override public String read() { String item = super.read(); provided.add(item); count++; return item; } }; ItemWriter<String> itemWriter = new ItemWriter<String>() { @Override public void write(List<? extends String> item) throws Exception { processed.addAll(item); written.addAll(item); logger.debug("Write Called! Item: [" + item + "]"); throw new RuntimeException("Write error - planned but not skippable."); } }; factory.setItemReader(provider); factory.setItemWriter(itemWriter); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); String message = stepExecution.getFailureExceptions().get(0).getMessage(); assertTrue("Wrong message: " + message, message.contains("Write error - planned but not skippable.")); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("")); assertEquals(expectedOutput, written); assertEquals(0, stepExecution.getSkipCount()); // [b] assertEquals("[b]", provided.toString()); // [b] assertEquals("[b]", processed.toString()); // [] assertEquals(0, recovered.size()); assertEquals(1, stepExecution.getReadCount()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@Test public void testRetryPolicy() throws Exception { factory.setRetryPolicy(new SimpleRetryPolicy(4, Collections.<Class<? extends Throwable>, Boolean>singletonMap(Exception.class, true))); factory.setSkipLimit(0);/*from ww w. ja v a 2 s .co m*/ ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("b")) { @Override public String read() { String item = super.read(); provided.add(item); count++; return item; } }; ItemWriter<String> itemWriter = new ItemWriter<String>() { @Override public void write(List<? extends String> item) throws Exception { processed.addAll(item); written.addAll(item); logger.debug("Write Called! Item: [" + item + "]"); throw new RuntimeException("Write error - planned but retryable."); } }; factory.setItemReader(provider); factory.setItemWriter(itemWriter); AbstractStep step = (AbstractStep) factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("")); assertEquals(expectedOutput, written); assertEquals(0, stepExecution.getSkipCount()); // [b] assertEquals(1, provided.size()); assertEquals("[b, b, b, b, b]", processed.toString()); // [] assertEquals(0, recovered.size()); assertEquals(1, stepExecution.getReadCount()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRollbackTests.java
@Test public void testProcessSkipWithNoRollbackForCheckedException() throws Exception { processor.setFailures("4"); processor.setExceptionType(SkippableException.class); factory.setNoRollbackExceptionClasses(getExceptionList(SkippableException.class)); Step step = factory.getObject();/*from www . j a v a2 s .c o m*/ step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals(1, stepExecution.getSkipCount()); assertEquals(0, stepExecution.getReadSkipCount()); assertEquals(5, stepExecution.getReadCount()); assertEquals(1, stepExecution.getProcessSkipCount()); assertEquals(0, stepExecution.getRollbackCount()); // skips "4" assertTrue(reader.getRead().contains("4")); assertFalse(writer.getCommitted().contains("4")); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,3,5")); assertEquals(expectedOutput, writer.getCommitted()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanTests.java
/** * Check items causing errors are skipped as expected. *//* ww w . j a v a 2 s . c om*/ @Test public void testReadSkip() throws Exception { reader.setFailures("2"); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(1, stepExecution.getSkipCount()); assertEquals(1, stepExecution.getReadSkipCount()); assertEquals(4, stepExecution.getReadCount()); assertEquals(0, stepExecution.getWriteSkipCount()); assertEquals(0, stepExecution.getRollbackCount()); // writer did not skip "2" as it never made it to writer, only "4" did assertTrue(reader.getRead().contains("4")); assertFalse(reader.getRead().contains("2")); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,3,4,5")); assertEquals(expectedOutput, writer.getWritten()); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step.getName())); }