package io.github.pascalgrimaud.qualitoast.web.rest;

import io.github.pascalgrimaud.qualitoast.QualiToastApp;
import io.github.pascalgrimaud.qualitoast.service.ElasticsearchIndexService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
 * Test class for ElasticsearchIndexResource REST controller.
 *
 * @see ElasticsearchIndexResource
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = QualiToastApp.class)
public class ElasticsearchIndexResourceIntTest {

    @Autowired
    private ElasticsearchIndexService elasticsearchIndexService;

    private MockMvc restElasticsearchMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        ElasticsearchIndexResource elasticResource = new ElasticsearchIndexResource(elasticsearchIndexService);
        this.restElasticsearchMockMvc = MockMvcBuilders.standaloneSetup(elasticResource)
            .build();
    }

    @Test
    public void launchReindex() throws Exception {
        restElasticsearchMockMvc.perform(post("/api/elasticsearch/index"))
            .andExpect(status().isAccepted());
    }
}

@@ -1641,16 +1641,312 @@
 ted());%0A
+        // As the ElasticsearchIndexService.reindexAll method is async%0A        // this test need to be achieved before going on other tests.%0A        // Otherwise, there can be some random failures like this:%0A        // SearchPhaseExecutionException: all shards failed%0A        Thread.sleep(5000);%0A
     %7D%0A%7D%0A

Fix random failures because of Async Elasticsearch Reindex