package uk.ac.ebi.quickgo.rest;

import uk.ac.ebi.quickgo.rest.metadata.MetaData;
import uk.ac.ebi.quickgo.rest.metadata.MetaDataProvider;
import uk.ac.ebi.quickgo.rest.service.ServiceConfigException;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;

/**
 * @author Tony Wardell
 * Date: 08/03/2017
 * Time: 16:02
 * Created with IntelliJ IDEA.
 */
public class MetaDataProviderTest {

    private static final  Function<Path,List<MetaData>> FAKE_MAPPER = (Path p)
                                                            -> Arrays.asList(new MetaData("1.0",""));
    private static final String SERVICE_NAME = "Test Service";
    private static final Path PATH_TO_NOWHERE = Paths.get("/path/to/nowhere");

    @Test(expected = IllegalArgumentException.class)
    public void serviceIsNullThrowsIllegalArgumentException(){
        new MetaDataProvider(null, FAKE_MAPPER, PATH_TO_NOWHERE, 1 );
    }

    @Test(expected = IllegalArgumentException.class)
    public void mapperIsNullThrowsIllegalArgumentException(){
        new MetaDataProvider(SERVICE_NAME, null, PATH_TO_NOWHERE, 1 );
    }

    @Test(expected = IllegalArgumentException.class)
    public void rawStreamIsNullThrowsIllegalArgumentException(){
        new MetaDataProvider(SERVICE_NAME, FAKE_MAPPER, null, 1 );
    }

    @Test(expected = IllegalArgumentException.class)
    public void expectedNumberOfMetaDataLinesThrowsIllegalArgumentException(){
        new MetaDataProvider(SERVICE_NAME, FAKE_MAPPER, PATH_TO_NOWHERE, 0 );
    }

    @Test
    public void readFileForMetaDataWithoutProblems() throws Exception{
        MetaDataProvider metaDataProvider = new MetaDataProvider(SERVICE_NAME, FAKE_MAPPER, PATH_TO_NOWHERE, 1 );
        List<MetaData> metaDataList = metaDataProvider.lookupMetaData();
        assertThat(metaDataList, hasSize(1));
        assertThat(metaDataList.get(0).timestamp, is(""));
        assertThat(metaDataList.get(0).version, is("1.0"));
    }

    @Test(expected = ServiceConfigException.class)
    public void readFileForMetaDataProducesUnexpectedNumberOfLines() throws Exception{
        MetaDataProvider metaDataProvider = new MetaDataProvider(SERVICE_NAME, FAKE_MAPPER, PATH_TO_NOWHERE, 2 );
        metaDataProvider.lookupMetaData();
    }
}

@@ -815,139 +815,28 @@
 nal 
- Function%3CPath,List%3CMetaData%3E%3E FAKE_MAPPER = (Path p)%0A                                                            -%3E Arrays.asList(
+MetaData METADATA = 
 new 
@@ -848,17 +848,8 @@
 ata(
-%221.0%22,%22%22)
 );%0A 
@@ -876,44 +876,67 @@
 nal 
-String SERVICE_NAME = %22Test Service%22
+ Function%3CPath,MetaData%3E FAKE_MAPPER = (Path p) -%3E METADATA
 ;%0A  
@@ -1017,201 +1017,8 @@
 );%0A%0A
-    @Test(expected = IllegalArgumentException.class)%0A    public void serviceIsNullThrowsIllegalArgumentException()%7B%0A        new MetaDataProvider(null, FAKE_MAPPER, PATH_TO_NOWHERE, 1 );%0A    %7D%0A%0A
     
@@ -1157,30 +1157,16 @@
 rovider(
-SERVICE_NAME, 
 null, PA
@@ -1174,28 +1174,24 @@
 H_TO_NOWHERE
-, 1 
 );%0A    %7D%0A%0A  
@@ -1261,17 +1261,12 @@
 oid 
-rawStream
+path
 IsNu
@@ -1326,38 +1326,24 @@
 ataProvider(
-SERVICE_NAME, 
 FAKE_MAPPER,
@@ -1351,229 +1351,8 @@
 null
-, 1 );%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)%0A    public void expectedNumberOfMetaDataLinesThrowsIllegalArgumentException()%7B%0A        new MetaDataProvider(SERVICE_NAME, FAKE_MAPPER, PATH_TO_NOWHERE, 0 
 );%0A 
@@ -1499,38 +1499,24 @@
 ataProvider(
-SERVICE_NAME, 
 FAKE_MAPPER,
@@ -1535,12 +1535,8 @@
 HERE
-, 1 
 );%0A 
@@ -1546,21 +1546,16 @@
     
-List%3C
 MetaData
 %3E me
@@ -1554,22 +1554,11 @@
 Data
-%3E
  m
-etaDataList
+d
  = m
@@ -1615,452 +1615,23 @@
 at(m
-etaDataList, hasSize(1));%0A        assertThat(metaDataList.get(0).timestamp, is(%22%22));%0A        assertThat(metaDataList.get(0).version, is(%221.0%22));%0A    %7D%0A%0A    @Test(expected = ServiceConfigException.class)%0A    public void readFileForMetaDataProducesUnexpectedNumberOfLines() throws Exception%7B%0A        MetaDataProvider metaDataProvider = new MetaDataProvider(SERVICE_NAME, FAKE_MAPPER, PATH_TO_NOWHERE, 2 );%0A        metaDataProvider.lookupMetaData(
+d, is(METADATA)
 );%0A 

Remove redundant tests.