package sagan.questions.support;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Test;
import org.springframework.test.web.servlet.MvcResult;
import saganx.AbstractIntegrationTests;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class QuestionsIndexTests extends AbstractIntegrationTests {

    @Test
    public void showsQuestionsIndex() throws Exception {
        MvcResult result = mockMvc.perform(get("/questions")).andExpect(status().isOk())
                .andExpect(content().contentTypeCompatibleWith("text/html")).andReturn();

        Document document = Jsoup.parse(result.getResponse().getContentAsString());

        // questions
        assertThat(document.select("body").text(), containsString("QUESTIONS"));

        // tags
        assertThat(document.select("body").text(), containsString("Spring Framework"));
        assertThat(document.select("body").text(), containsString("spring-framework"));
        assertThat(document.select("body").text(), containsString("spring-core"));
        assertThat(document.select("body").text(), containsString("Spring Data"));
        assertThat(document.select("body").text(), containsString("spring-data"));
        assertThat(document.select("body").text(), containsString("spring-data-mongodb"));
    }
}

@@ -1082,12 +1082,92 @@
  // 
-tags
+see seed data in sagan-common/src/main/resources/database/V4__stackoverflow_tags.sql
 %0A   
@@ -1418,24 +1418,116 @@
 ng-core%22));%0A
+        assertThat(document.select(%22body%22).text(), containsString(%22dependency-injection%22));%0A
         asse
@@ -1672,32 +1672,32 @@
 spring-data%22));%0A
-
         assertTh
@@ -1767,20 +1767,109 @@
 mongodb%22));%0A
+        assertThat(document.select(%22body%22).text(), containsString(%22spring-data-neo4j%22));%0A
     %7D%0A%7D%0A

Add failing assertions that test for presence of tags in seed data