Example usage for org.springframework.batch.test MetaDataInstanceFactory createStepExecution

List of usage examples for org.springframework.batch.test MetaDataInstanceFactory createStepExecution

Introduction

In this page you can find the example usage for org.springframework.batch.test MetaDataInstanceFactory createStepExecution.

Prototype

public static StepExecution createStepExecution() 

Source Link

Document

Create a StepExecution with default parameters.

Usage

From source file:uk.ac.ebi.eva.pipeline.io.readers.GeneReaderTest.java

@Test
public void shouldReadAllLinesInGtf() throws Exception {
    ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext();

    //simulate VEP output file
    File file = JobTestUtils.makeGzipFile(GtfStaticTestData.GTF_CONTENT);

    GeneReader geneReader = new GeneReader(file);
    geneReader.setSaveState(false);/*from  www  .  ja v a2 s.  c om*/
    geneReader.open(executionContext);

    FeatureCoordinates gene;
    int chromosomeCount = 0;
    int count = 0;
    while ((gene = geneReader.read()) != null) {
        count++;
        if (gene.getChromosome() != null && !gene.getChromosome().isEmpty()) {
            chromosomeCount++;
        }
    }
    // all should have at least the chromosome field
    assertEquals(count, chromosomeCount);

    // GeneReader should get all the lines from the file
    long actualCount = JobTestUtils.getLines(new GZIPInputStream(new FileInputStream(file)));
    assertEquals(actualCount, count);
}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.processor.GeneFilterProcessorTest.java

@Test
public void shouldKeepGenesAndTranscripts() throws Exception {
    ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext();
    GeneFilterProcessor geneFilterProcessor = new GeneFilterProcessor();

    //simulate VEP output file
    File file = JobTestUtils.makeGzipFile(GtfStaticTestData.GTF_CONTENT);

    GeneReader geneReader = new GeneReader(file);
    geneReader.setSaveState(false);// w  w w. j a va 2 s  .c o m
    geneReader.open(executionContext);

    FeatureCoordinates gene;
    int count = 0;
    int keptGenes = 0;
    while ((gene = geneReader.read()) != null) {
        count++;
        FeatureCoordinates processedGene = geneFilterProcessor.process(gene);
        if (processedGene != null) {
            keptGenes++;
        }
    }

    assertEquals(7, count);
    assertEquals(4, keptGenes);
}

From source file:uk.ac.ebi.eva.pipeline.io.writers.VepInputFlatFileWriterTest.java

@Test
public void shouldWriteAllFieldsToFile() throws Exception {
    ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext();

    DBObjectToVariantConverter converter = new DBObjectToVariantConverter();
    VariantWrapper variant = new VariantWrapper(converter
            .convertToDataModelType(JobTestUtils.constructDbo(VariantData.getVariantWithAnnotation())));

    File tempFile = JobTestUtils.createTempFile();
    VepInputFlatFileWriter writer = new VepInputFlatFileWriter(tempFile);
    writer.open(executionContext);/*from   w  w w.  j  a v a2s.com*/
    writer.write(Collections.singletonList(variant));
    assertEquals("20\t60344\t60348\tG/A\t+", readFirstLine(tempFile));
    writer.close();
}

From source file:uk.ac.ebi.eva.pipeline.io.readers.AnnotationFlatFileReaderTest.java

@Test
public void shouldReadAllLinesInVepOutput() throws Exception {
    ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext();

    //simulate VEP output file
    File file = JobTestUtils.makeGzipFile(VepOutputContent.vepOutputContent);

    AnnotationFlatFileReader annotationFlatFileReader = new AnnotationFlatFileReader(file);
    annotationFlatFileReader.setSaveState(false);
    annotationFlatFileReader.open(executionContext);

    VariantAnnotation variantAnnotation;
    int consequenceTypeCount = 0;
    int count = 0;
    while ((variantAnnotation = annotationFlatFileReader.read()) != null) {
        count++;/*w ww  . j a v a  2s . co m*/
        if (variantAnnotation.getConsequenceTypes() != null
                && !variantAnnotation.getConsequenceTypes().isEmpty()) {
            consequenceTypeCount++;
        }
    }
    // all should have at least consequence type annotations
    assertEquals(count, consequenceTypeCount);

    // annotationFlatFileReader should get all the lines from the file
    long actualCount = JobTestUtils.getLines(new GZIPInputStream(new FileInputStream(file)));
    assertEquals(actualCount, count);
}

From source file:de.langmi.spring.batch.examples.complex.file.split.GetLineCountTaskletTest.java

@Test
public void testExecute() throws Exception {
    // setup//from ww  w. j ava2s . co m
    tasklet = new GetLineCountTasklet();
    tasklet.setResource(new FileSystemResource(INPUT));
    StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution();

    // execute
    RepeatStatus status = tasklet.execute(new StepContribution(stepExecution),
            new ChunkContext(new StepContext(stepExecution)));
    // assertions
    assertEquals(RepeatStatus.FINISHED, status);
    assertEquals(EXPECTED_COUNT, stepExecution.getExecutionContext().get("line.count"));
}

From source file:de.langmi.spring.batch.examples.readers.file.flatfileitemreader.FlatFileItemReaderTest.java

/**
 * Test should read succesfully./*  w  ww. jav  a 2 s.  c  om*/
 *
 * @throws Exception 
 */
@Test
public void testSuccessfulReading() throws Exception {
    // init reader
    reader.setLineMapper(new PassThroughLineMapper());
    reader.setResource(new FileSystemResource(INPUT_FILE));
    // open, provide "mock" ExecutionContext
    reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());
    // read
    try {
        int count = 0;
        String line;
        while ((line = reader.read()) != null) {
            assertEquals(String.valueOf(count), line);
            count++;
        }
        assertEquals(EXPECTED_COUNT, count);
    } catch (Exception e) {
        throw e;
    } finally {
        reader.close();
    }
}

From source file:de.langmi.spring.batch.examples.readers.file.peekable.SimplePeekableItemReaderTest.java

/**
 * Test should read succesfully.//from w  w  w .  jav a 2s.c om
 *
 * @throws Exception 
 */
@Test
public void testSuccessfulPeekAhead() throws Exception {
    // init delegate
    delegateReader.setLineMapper(new PassThroughLineMapper());
    delegateReader.setResource(new FileSystemResource(INPUT_FILE));
    // init peekable
    SingleItemPeekableItemReader<String> peekable = new SingleItemPeekableItemReader<String>();
    peekable.setDelegate(delegateReader);
    // open, provide "mock" ExecutionContext
    peekable.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());
    // read
    try {
        int count = 0;
        String line;
        while ((line = peekable.read()) != null) {
            assertEquals(String.valueOf(count), line);
            // test for peek
            String lineAhead = peekable.peek();
            if (count + 1 < EXPECTED_COUNT) {
                assertEquals(String.valueOf(count + 1), lineAhead);
            } else {
                assertNull(lineAhead);
            }
            count++;
        }
        assertEquals(EXPECTED_COUNT, count);
    } catch (Exception e) {
        throw e;
    } finally {
        peekable.close();
    }
}

From source file:fr.acxio.tools.agia.alfresco.MultiLineNodeListItemReaderTest.java

public StepExecution getStepExection() {
    StepExecution execution = MetaDataInstanceFactory.createStepExecution();
    return execution;
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsVersionsWriterTest.java

public StepExecution getStepExecution() {

    final StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution();
    stepExecution.getExecutionContext().putInt("mantis.loop.project_id", 1);

    return stepExecution;
}

From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReaderTest.java

/**
 * Test with one ZIP file containing one text file with 20 lines.
 *
 * @throws Exception //  w  w w  .ja  v a  2  s .co m
 */
@Test
public void testOneZipFile() throws Exception {
    LOG.debug("testOneZipFile");
    ZipMultiResourceItemReader<String> mReader = new ZipMultiResourceItemReader<String>();
    // setup multResourceReader
    mReader.setArchives(new Resource[] { new FileSystemResource(ZIP_INPUT_SINGLE_FILE) });

    // call general setup last
    generalMultiResourceReaderSetup(mReader);

    // open with mock context
    mReader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());

    // read
    try {
        String item = null;
        int count = 0;
        do {
            item = mReader.read();
            if (item != null) {
                assertEquals(String.valueOf(count), item);
                count++;
            }
        } while (item != null);
        assertEquals(20, count);
    } catch (Exception e) {
        throw e;
    } finally {
        mReader.close();
    }
}