-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathEmbeddedDbJavaConfigTest.java
61 lines (42 loc) · 1.51 KB
/
EmbeddedDbJavaConfigTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.jayway.repository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.sql.DataSource;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = EmbeddedDbJavaConfig.class)
public class EmbeddedDbJavaConfigTest {
JdbcTemplate jdbcTemplate;
@Autowired
AccountRepository accountRepository;
@Autowired
DataSource dataSource;
@Before
public void setUp() {
jdbcTemplate = new JdbcTemplate(dataSource);
}
int getBalance(int accountNumber) {
return jdbcTemplate.queryForObject(
"SELECT balance FROM account_t WHERE account_number = ?",
Integer.class, accountNumber);
}
@Test
public void verifyEmbeddedDatabase() {
int firstBalance = getBalance(1);
assertThat(firstBalance, is(100));
int secondBalance = getBalance(2);
assertThat(secondBalance, is(200));
}
@Test
public void ormMappingShouldWork() {
AccountEntity accountEntity = accountRepository.findOne(1);
assertThat(accountEntity.getAccountNumber(), is(1));
assertThat(accountEntity.getBalance(), is(100));
}
}