/*
 * Copyright 2017 Warren Fan. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author Warren Fan
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HelloSpringBootTest {

    @Autowired
    private TestRestTemplate restTemplate;

    @Test
    public void helloTest() {
        String body = this.restTemplate.getForObject("/demo", String.class);
        assertThat(body).isEqualTo("{\"name\":\"SpringBoot\"}");
    }
}

@@ -788,216 +788,571 @@
 est.
-context.SpringBootTest;%0Aimport org.springframework.boot.test.web.client.TestRestTemplate;%0Aimport org.springframework.test.context.junit4.SpringRunner;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat
+autoconfigure.web.servlet.AutoConfigureMockMvc;%0Aimport org.springframework.boot.test.context.SpringBootTest;%0Aimport org.springframework.http.MediaType;%0Aimport org.springframework.test.context.junit4.SpringRunner;%0Aimport org.springframework.test.web.servlet.MockMvc;%0Aimport org.springframework.test.web.servlet.request.MockMvcRequestBuilders;%0A%0Aimport static org.hamcrest.Matchers.equalTo;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
 ;%0A%0A/
@@ -1485,16 +1485,38 @@
 M_PORT)%0A
+@AutoConfigureMockMvc%0A
 public c
@@ -1574,37 +1574,19 @@
 ate 
-TestRestTemplate restTemplate
+MockMvc mvc
 ;%0A%0A 
@@ -1626,115 +1626,200 @@
 t() 
-%7B%0A        String body = this.restTemplate.getForObject(%22/demo%22, String.class);%0A        assertThat(body).isE
+throws Exception %7B%0A        mvc.perform(MockMvcRequestBuilders.get(%22/demo%22).accept(MediaType.APPLICATION_JSON))%0A            .andExpect(status().isOk())%0A            .andExpect(content().string(e
 qual
@@ -1849,16 +1849,18 @@
 oot%5C%22%7D%22)
+))
 ;%0A    %7D%0A

test our '/demo' interface.