1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.awful_table;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.io.Reader;
21
22 import org.apache.ibatis.BaseDataTest;
23 import org.apache.ibatis.io.Resources;
24 import org.apache.ibatis.session.SqlSession;
25 import org.apache.ibatis.session.SqlSessionFactory;
26 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29
30 class AwfulTableTest {
31 protected SqlSessionFactory sqlSessionFactory;
32
33 @BeforeEach
34 void setUp() throws Exception {
35 try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/MapperConfig.xml")) {
36 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
37 }
38
39 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
40 "org/apache/ibatis/submitted/awful_table/CreateDB.sql");
41 }
42
43 @Test
44 void testAwfulTableInsert() {
45 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
46 AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
47 AwfulTable record = new AwfulTable();
48 record.seteMail("fred@fred.com");
49 record.setEmailaddress("alsofred@fred.com");
50 record.setFirstFirstName("fred1");
51 record.setFrom("from field");
52 record.setId1(1);
53 record.setId2(2);
54 record.setId5(5);
55 record.setId6(6);
56 record.setId7(7);
57 record.setSecondFirstName("fred2");
58 record.setThirdFirstName("fred3");
59
60 mapper.insert(record);
61 Integer generatedCustomerId = record.getCustomerId();
62 assertEquals(57, generatedCustomerId.intValue());
63
64 AwfulTable returnedRecord = mapper.selectByPrimaryKey(generatedCustomerId);
65
66 assertEquals(generatedCustomerId, returnedRecord.getCustomerId());
67 assertEquals(record.geteMail(), returnedRecord.geteMail());
68 assertEquals(record.getEmailaddress(), returnedRecord.getEmailaddress());
69 assertEquals(record.getFirstFirstName(), returnedRecord.getFirstFirstName());
70 assertEquals(record.getFrom(), returnedRecord.getFrom());
71 assertEquals(record.getId1(), returnedRecord.getId1());
72 assertEquals(record.getId2(), returnedRecord.getId2());
73 assertEquals(record.getId5(), returnedRecord.getId5());
74 assertEquals(record.getId6(), returnedRecord.getId6());
75 assertEquals(record.getId7(), returnedRecord.getId7());
76 assertEquals(record.getSecondFirstName(), returnedRecord.getSecondFirstName());
77 assertEquals(record.getThirdFirstName(), returnedRecord.getThirdFirstName());
78 }
79 }
80
81 }