package uk.ac.ebi.quickgo.geneproduct.common;

import uk.ac.ebi.quickgo.common.solr.TemporarySolrDataStore;
import uk.ac.ebi.quickgo.geneproduct.common.document.GeneProductDocument;

import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationContextLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.ac.ebi.quickgo.geneproduct.common.common.GeneProductDocMocker.*;

/**
 * Tests the behaviour of the {@link GeneProductRepository}
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RepoConfig.class, loader = SpringApplicationContextLoader.class)
public class GeneProductRepositoryIT {
    @ClassRule
    public static final TemporarySolrDataStore solrDataStore = new TemporarySolrDataStore();

    @Autowired
    private GeneProductRepository geneProductRepository;

    @Before
    public void before() {
        geneProductRepository.deleteAll();
    }

    @Test
    public void addGeneProductToRepository() throws Exception {
        String id = "geneProduct1";

        GeneProductDocument doc = createDocWithId(id);

        GeneProductDocument savedDoc = geneProductRepository.save(doc);

        assertThat(savedDoc, is(doc));
    }
}

@@ -176,16 +176,43 @@
 ument;%0A%0A
+import java.util.Optional;%0A
 import o
@@ -224,24 +224,24 @@
 nit.Before;%0A
-
 import org.j
@@ -676,16 +676,72 @@
 rtThat;%0A
+import static org.hamcrest.Matchers.containsInAnyOrder;%0A
 import s
@@ -1566,24 +1566,24 @@
 save(doc);%0A%0A
-
         asse
@@ -1614,11 +1614,1380 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void add3GeneProductTosRepository() throws Exception %7B%0A        String id1 = %22geneProduct1%22;%0A        String id2 = %22geneProduct2%22;%0A        String id3 = %22geneProduct3%22;%0A%0A        GeneProductDocument doc1 = createDocWithId(id1);%0A        GeneProductDocument doc2 = createDocWithId(id2);%0A        GeneProductDocument doc3 = createDocWithId(id3);%0A%0A        geneProductRepository.save(doc1);%0A        geneProductRepository.save(doc2);%0A        geneProductRepository.save(doc3);%0A%0A        assertThat(geneProductRepository.findAll(), containsInAnyOrder(doc1, doc2, doc3));%0A    %7D%0A%0A    @Test%0A    public void removeGeneProductFromRepository() %7B%0A        String id = %22geneProduct1%22;%0A%0A        GeneProductDocument doc = createDocWithId(id);%0A%0A        geneProductRepository.save(doc);%0A%0A        geneProductRepository.delete(id);%0A%0A        Optional%3CGeneProductDocument%3E retrievedDoc = geneProductRepository.findById(id);%0A%0A        assertThat(retrievedDoc.isPresent(), is(false));%0A    %7D%0A%0A    @Test%0A    public void lookupGeneProductById() %7B%0A        String id = %22geneProduct1%22;%0A%0A        GeneProductDocument doc = createDocWithId(id);%0A%0A        geneProductRepository.save(doc);%0A%0A        Optional%3CGeneProductDocument%3E retrievedDoc = geneProductRepository.findById(id);%0A%0A        assertThat(retrievedDoc.isPresent(), is(true));%0A        assertThat(retrievedDoc.get(), is(doc));%0A%0A    %7D
 %0A%7D%0A

Add more tests to the integration test.