Skip to content

Instantly share code, notes, and snippets.

View colinbut's full-sized avatar
🎯
Focusing

Colin But colinbut

🎯
Focusing
View GitHub Profile
private static final String DB_DRIVER = "org.h2.Driver";
private static final String DB_CONNECTION = "jdbc:h2:~/test";
private static final String DB_USER = "";
private static final String DB_PASSWORD = "";
private static Connection getDBConnection() {
Connection dbConnection = null;
try {
Class.forName(DB_DRIVER);
} catch (ClassNotFoundException e) {
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"file:src/integration-test/resources/META-INF/test-context.xml"
})
@WebAppConfiguration
public class CustomerDetailsControllerIntegrationTest {
private MockMvc mockMvc;
@Autowired
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
@GetMapping("/{userId}")
public ResponseEntity<User> getUserDetails(@PathVariable("userId") Integer userId) {
return ResponseEntity.ok(userList.get(userId));
}
{
"userId": 1,
"firstName": "Joe",
"secondName": "Bloggs",
"email": "me@email.com",
"dob": "3880-09-28T23:00:00.000+0000",
"address": {
"firstLineAddress": "My First Line Address",
"secondLineAddress": "My Second Line Address",
"postCode": "MU3 28P",
@Test
public void testGetUserDetails() {
when().
get("/user/{userId}", 1).
then().
statusCode(200).
body("userId", equalTo(1),
"firstName", equalTo("Joe"),
"secondName", equalTo("Bloggs"),
"email", equalTo("me@email.com"),
<!-- Cucumber-JVM -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
public class ItemsListEnd2EndTest {
private ItemController itemController = new ItemController();
private String viewName;
@Given("^i am on the customers list page$")
public void i_am_on_the_customers_list_page() throws Throwable {
// steps to set up or verify you're on the customers list page
}