[BAEL-1686] - Updating test considerations
This commit is contained in:
parent
2b08d2c7ce
commit
3e2d544144
|
@ -94,4 +94,8 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<<<<<<< HEAD
|
||||||
</project>
|
</project>
|
||||||
|
=======
|
||||||
|
</project>
|
||||||
|
>>>>>>> 19a1633c35d6d49f9c51b8ecc3dbe127c91d75c3
|
||||||
|
|
|
@ -5,7 +5,7 @@ spring:
|
||||||
pool-name: hikari-pool
|
pool-name: hikari-pool
|
||||||
url: jdbc:mysql://localhost:3306/baeldung?verifyServerCertificate=false&useSSL=false&requireSSL=false
|
url: jdbc:mysql://localhost:3306/baeldung?verifyServerCertificate=false&useSSL=false&requireSSL=false
|
||||||
username: root
|
username: root
|
||||||
password: admin
|
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: create
|
ddl-auto: create
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.baeldung.springdatarestquerydsl;
|
||||||
|
|
||||||
|
import com.baeldung.Application;
|
||||||
|
import org.junit.Before;
|
||||||
|
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.http.MediaType;
|
||||||
|
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 java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration
|
||||||
|
public class IntegrationTest {
|
||||||
|
|
||||||
|
final MediaType contentType =
|
||||||
|
new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
||||||
|
|
||||||
|
@Autowired private WebApplicationContext webApplicationContext;
|
||||||
|
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Before public void setupMockMvc() {
|
||||||
|
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetJohn() throws Exception {
|
||||||
|
// Get John
|
||||||
|
mockMvc.perform(get("/personQuery?name=John")).andExpect(status().isOk()).andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("John")))
|
||||||
|
.andExpect(jsonPath("$[0].address.address", is("Fake Street 1")))
|
||||||
|
.andExpect(jsonPath("$[0].address.country", is("Fake Country")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetLisa() throws Exception {
|
||||||
|
// Get Lisa
|
||||||
|
mockMvc.perform(get("/personQuery?name=Lisa")).andExpect(status().isOk()).andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("Lisa")))
|
||||||
|
.andExpect(jsonPath("$[0].address.address", is("Real Street 1")))
|
||||||
|
.andExpect(jsonPath("$[0].address.country", is("Real Country")));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue