2
2
3
3
import gt .app .config .AppProperties ;
4
4
import gt .app .frwk .TestDataManager ;
5
- import io . hypersistence . utils . jdbc . validator . SQLStatementCountValidator ;
5
+ import net . ttddyy . dsproxy . QueryCountHolder ;
6
6
import org .junit .jupiter .api .BeforeEach ;
7
7
import org .junit .jupiter .api .Test ;
8
8
import org .springframework .beans .factory .annotation .Autowired ;
14
14
import org .springframework .test .web .servlet .MockMvc ;
15
15
import org .springframework .test .web .servlet .MvcResult ;
16
16
17
- import static io . hypersistence . utils . jdbc . validator . SQLStatementCountValidator .* ;
17
+ import static org . junit . jupiter . api . Assertions . assertEquals ;
18
18
import static org .junit .jupiter .api .Assertions .assertTrue ;
19
19
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
20
20
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
@@ -31,18 +31,20 @@ class PublicPageIT {
31
31
@ BeforeEach
32
32
void cleanDB () {
33
33
testDataManager .cleanDataAndCache ();
34
- SQLStatementCountValidator .reset ();
35
-
36
34
}
37
35
38
36
@ Test
39
37
void loadIndexPageAndVerifyResultIsCached (@ Autowired MockMvc mvc ) throws Exception {
40
- SQLStatementCountValidator .reset ();
38
+ //gt.app.DataCreator creates test data
39
+ long selectCount = QueryCountHolder .getGrandTotal ().getSelect ();
40
+ long deleteCount = QueryCountHolder .getGrandTotal ().getDelete ();
41
+ long insertCount = QueryCountHolder .getGrandTotal ().getInsert ();
42
+ long updateCount = QueryCountHolder .getGrandTotal ().getUpdate ();
41
43
42
44
MvcResult result = mvc .perform (get ("/" ))
43
- .andExpect (status ().isOk ())
44
- .andExpect (content ().contentTypeCompatibleWith (MediaType .TEXT_HTML_VALUE ))
45
- .andReturn ();
45
+ .andExpect (status ().isOk ())
46
+ .andExpect (content ().contentTypeCompatibleWith (MediaType .TEXT_HTML_VALUE ))
47
+ .andReturn ();
46
48
47
49
String content = result .getResponse ().getContentAsString ();
48
50
assertTrue (content .contains ("Article App - HOME" ));
@@ -54,20 +56,24 @@ void loadIndexPageAndVerifyResultIsCached(@Autowired MockMvc mvc) throws Excepti
54
56
mvc .perform (get ("/" )).andExpect (status ().isOk ());
55
57
56
58
//only one select
57
- // assertSelectCount(1 );
58
- // assertDeleteCount(0 );
59
- // assertInsertCount(0 );
60
- // assertUpdateCount(0 );
59
+ assertEquals ( selectCount + 1 , QueryCountHolder . getGrandTotal (). getSelect () );
60
+ assertEquals ( deleteCount , QueryCountHolder . getGrandTotal (). getDelete () );
61
+ assertEquals ( insertCount , QueryCountHolder . getGrandTotal (). getInsert () );
62
+ assertEquals ( updateCount , QueryCountHolder . getGrandTotal (). getUpdate () );
61
63
}
62
64
63
65
@ Test
64
66
void testCacheAndDBBothAreResetBetweenTests (@ Autowired MockMvc mvc ) throws Exception {
65
- SQLStatementCountValidator .reset ();
67
+ //gt.app.DataCreator creates test data
68
+ long selectCount = QueryCountHolder .getGrandTotal ().getSelect ();
69
+ long deleteCount = QueryCountHolder .getGrandTotal ().getDelete ();
70
+ long insertCount = QueryCountHolder .getGrandTotal ().getInsert ();
71
+ long updateCount = QueryCountHolder .getGrandTotal ().getUpdate ();
66
72
67
73
MvcResult result = mvc .perform (get ("/" ))
68
- .andExpect (status ().isOk ())
69
- .andExpect (content ().contentTypeCompatibleWith (MediaType .TEXT_HTML_VALUE ))
70
- .andReturn ();
74
+ .andExpect (status ().isOk ())
75
+ .andExpect (content ().contentTypeCompatibleWith (MediaType .TEXT_HTML_VALUE ))
76
+ .andReturn ();
71
77
72
78
String content = result .getResponse ().getContentAsString ();
73
79
assertTrue (content .contains ("Article App - HOME" ));
@@ -79,9 +85,9 @@ void testCacheAndDBBothAreResetBetweenTests(@Autowired MockMvc mvc) throws Excep
79
85
mvc .perform (get ("/" )).andExpect (status ().isOk ());
80
86
81
87
//only one select
82
- // assertSelectCount(1 );
83
- // assertDeleteCount(0 );
84
- // assertInsertCount(0 );
85
- // assertUpdateCount(0 );
88
+ assertEquals ( selectCount + 1 , QueryCountHolder . getGrandTotal (). getSelect () );
89
+ assertEquals ( deleteCount , QueryCountHolder . getGrandTotal (). getDelete () );
90
+ assertEquals ( insertCount , QueryCountHolder . getGrandTotal (). getInsert () );
91
+ assertEquals ( updateCount , QueryCountHolder . getGrandTotal (). getUpdate () );
86
92
}
87
93
}
0 commit comments