package com.goree.api.util;


import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebIntegrationTest({"server.port=48181"})
abstract public class RestTestWithDBUnit extends TestWithDBUnit {
    @Override
    abstract public String getDatasetFilePath();

    @Autowired
    private WebApplicationContext wac;


    protected MockMvc mockMvc;

    @Before
    public void setUp() {
        super.setUp();
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    }

    public ResultActions performSet(MockHttpServletRequestBuilder requestBuilder) throws Exception{
        return this.mockMvc.perform(requestBuilder.accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
                .andDo(print())
                .andExpect(status().isOk());


    }

    public ResultActions performSet(MockHttpServletRequestBuilder requestBuilder,String jsonData) throws Exception{
        return this.mockMvc.perform(requestBuilder
                .contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(jsonData)
                .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
                .andDo(print())
                .andExpect(status().isOk());

    }

    public ResultActions performSet(MockHttpServletRequestBuilder requestBuilder,byte[] contentData) throws Exception{
        return this.mockMvc.perform(requestBuilder
                .contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(contentData)
                .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
                .andDo(print())
                .andExpect(status().isOk());

    }

}

@@ -23,16 +23,60 @@
 util;%0A%0A%0A
+import com.goree.api.auth.FacebookSettings;%0A
 import o
@@ -92,16 +92,16 @@
 Before;%0A
-
 import o
@@ -984,16 +984,70 @@
 t wac;%0A%0A
+    @Autowired%0A    private FacebookSettings settings;%0A
 %0A    pro
@@ -1425,32 +1425,103 @@
 charset=UTF-8%22))
+%0A                .header(%22AuthToken%22, settings.longLivedTokenForTest())
 )%0A              
@@ -1751,32 +1751,103 @@
 (requestBuilder%0A
+                .header(%22AuthToken%22, settings.longLivedTokenForTest())%0A
                 
@@ -2218,32 +2218,32 @@
 rows Exception%7B%0A
-
         return t
@@ -2269,32 +2269,103 @@
 (requestBuilder%0A
+                .header(%22AuthToken%22, settings.longLivedTokenForTest())%0A
                 

Add AuthToken in header