Search in sources :

Example 6 with GenomeBrowserTrack

use of org.molgenis.genomebrowser.GenomeBrowserTrack in project molgenis by molgenis.

the class GenomeBrowserServiceTest method testGetReferenceTracksAll.

@Test
public void testGetReferenceTracksAll() {
    EntityType entity = mock(EntityType.class);
    when(entity.getLabel()).thenReturn("label");
    GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
    GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, null, null, null, null);
    EntityType molgenisEntity = mock(EntityType.class);
    when(molgenisEntity.getLabel()).thenReturn("label");
    GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.ALL, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
    GenomeBrowserAttributes attrs1 = getGenomeBrowserAttributes("pos", "chr", "ref", "alt");
    GenomeBrowserAttributes attrs2 = getGenomeBrowserAttributes("POS", "CHROM", null, null);
    when(dataService.findAll(GenomeBrowserAttributesMetadata.GENOMEBROWSERATTRIBUTES, new QueryImpl<GenomeBrowserAttributes>().eq(GenomeBrowserAttributesMetadata.DEFAULT, true), GenomeBrowserAttributes.class)).thenReturn(Stream.of(attrs1, attrs2));
    EntityType type1 = mock(EntityType.class);
    EntityType type2 = mock(EntityType.class);
    EntityType type3 = mock(EntityType.class);
    Attribute labelAttr = mock(Attribute.class);
    when(labelAttr.getName()).thenReturn("refLabel");
    List<EntityType> types = new ArrayList<>();
    types.add(type1);
    when(type1.getIdValue()).thenReturn("type1");
    when(type1.getLabel()).thenReturn("label1");
    when(type1.getAttributeNames()).thenReturn(Arrays.asList("POS", "CHROM", "AAP", "NOOT", "MIES"));
    when(type1.getLabelAttribute()).thenReturn(labelAttr);
    types.add(type2);
    when(type2.getIdValue()).thenReturn("type2");
    when(type2.getLabel()).thenReturn("label2");
    when(type2.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alt", "aap"));
    when(type2.getLabelAttribute()).thenReturn(labelAttr);
    types.add(type3);
    when(type3.getIdValue()).thenReturn("type3");
    when(type3.getLabel()).thenReturn("label3");
    when(type3.getAttributeNames()).thenReturn(Arrays.asList("pos", "chr", "ref", "alternative", "monkey"));
    when(type3.getLabelAttribute()).thenReturn(labelAttr);
    MetaDataService metaDataService = mock(MetaDataService.class);
    when(dataService.getMeta()).thenReturn(metaDataService);
    when(metaDataService.getEntityTypes()).thenReturn(types.stream());
    Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
    assertEquals(result.size(), 2);
    assertEquals(result.get("type2"), GenomeBrowserTrack.create("type2", "label2", "refLabel", type2, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs1, null, null, null, null));
    assertEquals(result.get("type1"), GenomeBrowserTrack.create("type1", "label1", "refLabel", type1, GenomeBrowserSettings.TrackType.VARIANT, Collections.emptyList(), GenomeBrowserSettings.MolgenisReferenceMode.ALL, attrs2, null, null, null, null));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) QueryImpl(org.molgenis.data.support.QueryImpl) MetaDataService(org.molgenis.data.meta.MetaDataService) Attribute(org.molgenis.data.meta.model.Attribute) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) Test(org.testng.annotations.Test)

Aggregations

GenomeBrowserTrack (org.molgenis.genomebrowser.GenomeBrowserTrack)6 EntityType (org.molgenis.data.meta.model.EntityType)5 GenomeBrowserAttributes (org.molgenis.genomebrowser.meta.GenomeBrowserAttributes)4 Test (org.testng.annotations.Test)3 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)2 QueryImpl (org.molgenis.data.support.QueryImpl)2 Gson (com.google.gson.Gson)1 ParseException (freemarker.core.ParseException)1 IOException (java.io.IOException)1 URLDecoder (java.net.URLDecoder)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 StringUtils (org.apache.commons.lang3.StringUtils)1 JSONObject (org.json.JSONObject)1