uk.ac.ebi.eva.pipeline.io.writers.VepInputFlatFileWriterTest.java Source code

Java tutorial

Introduction

Here is the source code for uk.ac.ebi.eva.pipeline.io.writers.VepInputFlatFileWriterTest.java

Source

/*
 * Copyright 2016 EMBL - European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.ebi.eva.pipeline.io.writers;

import org.junit.Test;
import org.opencb.opencga.storage.mongodb.variant.DBObjectToVariantConverter;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.test.MetaDataInstanceFactory;
import uk.ac.ebi.eva.pipeline.model.VariantWrapper;
import uk.ac.ebi.eva.test.data.VariantData;
import uk.ac.ebi.eva.test.utils.JobTestUtils;

import java.io.File;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static uk.ac.ebi.eva.test.utils.JobTestUtils.readFirstLine;

/**
 * {@link VepInputFlatFileWriter}
 * input: a List of VariantWrapper to each call of `.write()`
 * output: a line in a File for each VariantWrapper
 */
public class VepInputFlatFileWriterTest {

    @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);
        writer.write(Collections.singletonList(variant));
        assertEquals("20\t60344\t60348\tG/A\t+", readFirstLine(tempFile));
        writer.close();
    }

}