package guru.nidi.ramltester.uc.spring;

import guru.nidi.ramltester.RamlDefinition;
import guru.nidi.ramltester.spring.RequestResponseMatchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static guru.nidi.ramltester.spring.RamlResultMatchers.requestResponse;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = Application.class)
public class SimpleTest {

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;
    private RamlDefinition api;
    private RequestResponseMatchers requestResponse;

    @Before
    public void setup() {
        mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
        api = RamlDefinition.fromClasspath(getClass(), "api.yaml");
        requestResponse = requestResponse().withServletUri("http://nidi.guru/raml/simple/v1");
    }

    @Test
    public void greeting() throws Exception {
        this.mockMvc.perform(get("/greeting").accept(MediaType.parseMediaType("application/json")))
                .andExpect(requestResponse.matchesRaml(api))
                .andExpect(status().isOk())
                .andExpect(content().contentTypeCompatibleWith("application/json"))
                .andExpect(jsonPath("$.content").value("Hello, World!"));
    }

}
@@ -74,24 +74,106 @@
 Definition;%0A
+import guru.nidi.ramltester.RamlViolations;%0Aimport guru.nidi.ramltester.TestRaml;%0A
 import guru.
@@ -216,24 +216,49 @@
 seMatchers;%0A
+import org.junit.Assert;%0A
 import org.j
@@ -684,16 +684,71 @@
 ockMvc;%0A
+import org.springframework.test.web.servlet.MvcResult;%0A
 import o
@@ -1557,30 +1557,41 @@
   api = 
-RamlDefinition
+TestRaml.load(%22api.yaml%22)
 .fromCla
@@ -1611,20 +1611,8 @@
 ss()
-, %22api.yaml%22
 );%0A 
@@ -2057,16 +2057,16 @@
 json%22))%0A
-
         
@@ -2138,9 +2138,368 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void greetings() throws Exception %7B%0A        final MvcResult mvcResult = this.mockMvc.perform(get(%22/greeting%22).accept(MediaType.parseMediaType(%22application/json%22))).andReturn();%0A        final RamlViolations violations = api.testAgainst(mvcResult, %22http://nidi.guru/raml/simple/v1%22);%0A        Assert.assertTrue(violations.isEmpty());%0A    %7D%0A%0A
 %7D

update dependency