package uk.ac.ebi.atlas.resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import uk.ac.ebi.atlas.model.ExpressionUnit;
import uk.ac.ebi.atlas.model.resource.AtlasResource;

import javax.inject.Inject;

import java.util.Collection;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("classpath:applicationContext.xml")
public class DataFileHubIT {

    @Inject
    DataFileHubFactory dataFileHubFactory;

    @Test
    public void testGetExperimentFiles() {
        DataFileHub subject = dataFileHubFactory.getGxaDataFileHub();
        assertAtlasResourceExists(subject.getExperimentFiles("E-MTAB-513").analysisMethods);
        assertAtlasResourceExists(subject.getExperimentFiles("E-MTAB-513").condensedSdrf);
        assertAtlasResourceExists(subject.getExperimentFiles("E-MTAB-513").experimentDesign);
    }

    @Test
    public void testGetBaselineFiles() {
        DataFileHub subject = dataFileHubFactory.getGxaDataFileHub();
        assertAtlasResourceExists(
                subject.getRnaSeqBaselineExperimentFiles("E-MTAB-513").dataFile(ExpressionUnit.Absolute.Rna.TPM));
        assertAtlasResourceExists(
                subject.getRnaSeqBaselineExperimentFiles("E-MTAB-513").dataFile(ExpressionUnit.Absolute.Rna.FPKM));
        assertAtlasResourceExists(subject.getProteomicsBaselineExperimentFiles("E-PROT-1").main);
    }

    @Test
    public void testGetDifferentialExperimentFiles() {
        DataFileHub subject = dataFileHubFactory.getGxaDataFileHub();
        assertAtlasResourceExists(subject.getRnaSeqDifferentialExperimentFiles("E-GEOD-54705").analytics);
        assertAtlasResourceExists(subject.getRnaSeqDifferentialExperimentFiles("E-GEOD-54705").rawCounts);
    }

    @Test
    public void findsTSnePlotFiles() {
        DataFileHub subject = dataFileHubFactory.getScxaDataFileHub();
        assertAtlasResourceExists(subject.getSingleCellExperimentFiles("E-MTAB-5061").tSnePlotTsvs.values());
    }

    private void assertAtlasResourceExists(AtlasResource<?> resource) {
        assertThat(resource.exists()).isTrue();
    }

    private void assertAtlasResourceExists(Collection<? extends AtlasResource<?>> resource) {
        assertThat(resource).isNotEmpty();
        assertThat(resource).allMatch(AtlasResource::exists);
    }
}

@@ -45,16 +45,28 @@
 g.junit.
+jupiter.api.
 Test;%0Aim
@@ -84,18 +84,36 @@
 nit.
-runner.Run
+jupiter.api.extension.Extend
 With
@@ -225,33 +225,32 @@
 unit
-4.SpringJUnit4ClassRunner
+.jupiter.SpringExtension
 ;%0Aim
@@ -401,32 +401,76 @@
 e.AtlasResource;
+%0Aimport uk.ac.ebi.atlas.testutils.JdbcUtils;
 %0A%0Aimport javax.i
@@ -574,19 +574,22 @@
 That;%0A%0A@
-Run
+Extend
 With(Spr
@@ -595,25 +595,17 @@
 ring
-JUnit4ClassRunner
+Extension
 .cla
@@ -651,16 +651,29 @@
 uration(
+locations = %7B
 %22classpa
@@ -702,17 +702,11 @@
 xml%22
+%7D
 )%0A
-public 
 clas
@@ -722,16 +722,57 @@
 eHubIT %7B
+%0A    @Inject%0A    JdbcUtils jdbcTestUtils;
 %0A%0A    @I
@@ -827,39 +827,32 @@
 %0A%0A    @Test%0A    
-public 
 void testGetExpe
@@ -1228,39 +1228,32 @@
 %0A%0A    @Test%0A    
-public 
 void testGetBase
@@ -1752,31 +1752,24 @@
   @Test%0A    
-public 
 void testGet
@@ -2109,15 +2109,8 @@
     
-public 
 void
@@ -2125,32 +2125,127 @@
 nePlotFiles() %7B%0A
+        String experimentAccession = jdbcTestUtils.fetchRandomSingleCellExperimentAccession();%0A
         DataFile
@@ -2374,21 +2374,27 @@
 les(
-%22E-MTAB-5061%22
+experimentAccession
 ).tS

Check t-SNE plot files from an experiment fetched from the DB