Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-ebi committed Oct 24, 2023
1 parent 65c790a commit 2ca0623
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public void testRefAltAssignmentInConstructor() {
assertEquals("T", variant.getAlternate());
}

@Test
public void testChangeRefAltToUpperCase() {
Variant variant = new Variant("1", 1, 1, "c", "t");
assertEquals("C", variant.getReference());
assertEquals("T", variant.getAlternate());
}

@Test
public void testRefAltAssignmentInRenormalization() {
Variant variant = new Variant("1", 1, 1, "", "T");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package uk.ac.ebi.eva.commons.core.models;

import org.junit.Test;
import uk.ac.ebi.eva.commons.core.models.genotype.Genotype;

import static org.junit.Assert.assertEquals;

public class GenotypeTest {

@Test
public void testChangeRefAltToUpperCase() {
Genotype genotype = new Genotype("", "a", "t");

assertEquals("A", genotype.getReference());
assertEquals("T", genotype.getAlternate());
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.ac.ebi.eva.commons.core.models;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class VariantStatisticsTest {

@Test
public void testChangeRefAltToUpperCase() {
VariantStatistics variantStatistics = new VariantStatistics("a", "t", null,
-1, -1, "", "", -1, -1, -1,
-1, -1, -1, -1);
assertEquals("A", variantStatistics.getRefAllele());
assertEquals("T", variantStatistics.getAltAllele());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ public void testVariantIds() {
Collections.singleton("rs123,rs456"));
}

@Test
public void testChangeRefAltToUpperCase(){
String line = "chr1\t1000\t.\tt\tg\t.\t.\t.";
List<Variant> expResult = Collections.singletonList(new Variant("chr1", 1000, 1000, "T", "G"));
List<Variant> result = factory.create(FILE_ID, STUDY_ID, line);
assertEquals(expResult, result);
}

private void checkIds(VariantVcfFactory variantVcfFactory, String vcfLine, Set<String> expectedIds) {
List<Variant> expectedVariants = new LinkedList<>();
expectedVariants.add(new Variant("1", 1000, 1000, "C", "T"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.lordofthejars.nosqlunit.mongodb.MongoDbConfigurationBuilder;
import com.lordofthejars.nosqlunit.mongodb.MongoDbRule;

import org.bson.BsonArray;
import org.bson.BsonString;
import org.bson.Document;
Expand All @@ -31,7 +30,6 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import uk.ac.ebi.eva.commons.core.models.pipeline.VariantSourceEntry;
import uk.ac.ebi.eva.commons.core.models.ws.VariantSourceEntryWithSampleNames;
import uk.ac.ebi.eva.commons.core.models.ws.VariantWithSamplesAndAnnotation;
Expand Down Expand Up @@ -180,7 +178,7 @@ private Document buildMongoVariantWithFiles() {

private Document buildMongoBasicVariant() {
VariantWithSamplesAndAnnotation variant = new VariantWithSamplesAndAnnotation(CHROMOSOME, START, END, REFERENCE,
ALTERNATE, null);
ALTERNATE, null);
Document mongoVariant = new Document("_id", VARIANT_ID)
.append(VariantMongo.IDS_FIELD, Collections.singleton(RS_666))
.append(VariantMongo.TYPE_FIELD, variant.getType().name())
Expand Down Expand Up @@ -249,4 +247,13 @@ public void testConvertToDataModelTypeEmptyIds() {
assertNotNull(variant.getIds());
assertTrue(variant.getIds().isEmpty());
}

@Test
public void testChangeRefAltToUpperCase() {
VariantMongo variantMongo = new VariantMongo(new VariantWithSamplesAndAnnotation("chr1", START,
END, "a", "t", null));
Assert.assertEquals("A", variantMongo.getReference());
Assert.assertEquals("T", variantMongo.getAlternate());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.ac.ebi.eva.commons.mongodb;

import org.junit.Test;
import uk.ac.ebi.eva.commons.mongodb.entities.projections.SimplifiedVariant;

import java.lang.reflect.Field;

import static org.junit.Assert.assertEquals;

public class SimplifiedVariantTest {

@Test
public void testChangeRefAltToUpperCase() throws NoSuchFieldException, IllegalAccessException {
SimplifiedVariant simplifiedVariant = new SimplifiedVariant(null, "", -1, -1,
-1, "a", "t", null);

Field refField = SimplifiedVariant.class.getDeclaredField("reference");
Field altField = SimplifiedVariant.class.getDeclaredField("alternate");
refField.setAccessible(true);
altField.setAccessible(true);
String refValue = (String) refField.get(simplifiedVariant);
String altValue = (String) altField.get(simplifiedVariant);

assertEquals("A", refValue);
assertEquals("T", altValue);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,19 @@ public void testConvertFromVariantSourceEntryMongoToVariantSourceEntry() {
Assert.assertEquals("1/1", variantSourceEntryWithSampleNames.getSamplesDataMap().get("NA003").get("GT"));
}

@Test
public void testChangeRefAltToUpperCaseVariantSourceEntry() {
VariantSourceEntry variantSourceEntry = new VariantSourceEntry(null, "", new String[]{"a"},
null, null, null, null);
Assert.assertEquals("A", variantSourceEntry.getSecondaryAlternates()[0]);

}

@Test
public void testChangeRefAltToUpperCaseVariantEntrySourceMongo() {
VariantSourceEntryMongo variantSourceEntryMongo = new VariantSourceEntryMongo(new VariantSourceEntry(null,
"", new String[]{"a"}, null, null, null, null));
Assert.assertEquals( "A", variantSourceEntryMongo.getSecondaryAlternates()[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package uk.ac.ebi.eva.commons.mongodb.filter;

import org.bson.Document;
import org.junit.Test;
import org.springframework.data.mongodb.core.query.Criteria;

Expand Down Expand Up @@ -67,4 +68,14 @@ public void getCriteriaIn() throws Exception {
Criteria test = filter.getCriteria();
assertEquals(expected, test);
}

@Test
public void testChangeRefAltToUpperCase() {
List<VariantRepositoryFilter> filters = new FilterBuilder().getBeaconFilters("a", "t",
null, null);
assertEquals("A", ((List<String>) ((Document)filters.get(0).getCriteria().getCriteriaObject()
.get("ref")).get("$in")).get(0));
assertEquals("T", ((List<String>) ((Document)filters.get(1).getCriteria().getCriteriaObject()
.get("alt")).get("$in")).get(0));
}
}

0 comments on commit 2ca0623

Please sign in to comment.