package au.gov.ga.geodesy.domain.model.sitelog;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isIn;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.testng.annotations.Test;

import java.util.Set;

import au.gov.ga.geodesy.port.adapter.geodesyml.GeodesyMLSiteLogReader;
import au.gov.ga.geodesy.support.TestResources;
import au.gov.ga.geodesy.support.spring.IntegrationTest;

public class DocumentRepositoryITest extends IntegrationTest {

    @Autowired
    private DocumentRepository documentRepository;

    @Autowired
    private SiteLogRepository siteLogRepository;

    @Test
    @Rollback(false)
    public void saveAlic() throws Exception {
        String[] documentNames = {"ALIC_ant_000_20191027T143000.jpg", "ALIC_ant_090_20191027T143500.jpg"};
        SiteLog siteLog = new GeodesyMLSiteLogReader(TestResources.customGeodesyMLSiteLogReader("ALIC-with-2-associated-documents")).getSiteLog();
        Set<Document> documents = siteLog.getDocuments();
        assertThat(documents.size(), is(2));

        Document d1 = documents.iterator().next();
        assertThat(d1.getName(), isIn(documentNames));

        siteLogRepository.saveAndFlush(siteLog);

        Document d2 = documentRepository.findByName(d1.getName());
        assertThat(d2.getName(), isIn(documentNames));
    }

    @Test
    @Rollback(false)
    public void saveMobs() throws Exception {
        SiteLog siteLog = new GeodesyMLSiteLogReader(TestResources.customGeodesyMLSiteLogReader("MOBS")).getSiteLog();
        Set<Document> documents = siteLog.getDocuments();
        assertThat(documents.size(), is(1));

        Document d1 = documents.iterator().next();
        assertThat(d1.getName(), is("MOBS_ant_000_20191027T143000.jpg"));

        documentRepository.saveAndFlush(d1);
        Document d2 = documentRepository.findByName(d1.getName());
        assertThat(d2.getName(), is(d1.getName()));
    }
}

@@ -779,16 +779,28 @@
 oid save
+DocumentsFor
 Alic() t
@@ -1463,604 +1463,7 @@
    %7D
-%0A%0A    @Test%0A    @Rollback(false)%0A    public void saveMobs() throws Exception %7B%0A        SiteLog siteLog = new GeodesyMLSiteLogReader(TestResources.customGeodesyMLSiteLogReader(%22MOBS%22)).getSiteLog();%0A        Set%3CDocument%3E documents = siteLog.getDocuments();%0A        assertThat(documents.size(), is(1));%0A%0A        Document d1 = documents.iterator().next();%0A        assertThat(d1.getName(), is(%22MOBS_ant_000_20191027T143000.jpg%22));%0A%0A        documentRepository.saveAndFlush(d1);%0A        Document d2 = documentRepository.findByName(d1.getName());%0A        assertThat(d2.getName(), is(d1.getName()));%0A    %7D
 %0A%7D%0A

Tidy up DocumentRepositoryITest