Skip to content

Commit ded60bc

Browse files
committed
new spring boot, query count test fixed
1 parent 43161a7 commit ded60bc

File tree

13 files changed

+442
-508
lines changed

13 files changed

+442
-508
lines changed

.mvn/wrapper/maven-wrapper.properties

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip
2-
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

config/docker-compose.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ services:
33
activemq_artemis:
44
# its not supported in M1 Mac, workaround is to enable Rosetta in Docker
55
# Docker settings → Features in development → check ☑ Use Rosetta for x86/amd64 emulation on Apple Silicon, and then restart Docker.
6-
image: 'apache/activemq-artemis:2.31.2-alpine'
6+
image: 'apache/activemq-artemis:2.37.0'
77
container_name: activemqArtemis
88
environment:
9-
- ARTEMIS_USER=admin
10-
- ARTEMIS_PASSWORD=admin
9+
- "ARTEMIS_USER=admin"
10+
- "ARTEMIS_PASSWORD=admin"
1111
ports:
1212
- 8161:8161 # use this to access from browser
1313
- 61616:61616
1414
networks:
1515
- seedappnet
1616
mysql:
17-
image: 'mysql:8.0.35'
17+
image: 'mysql'
1818
environment:
19-
- MYSQL_ROOT_PASSWORD=password
20-
- MYSQL_DATABASE=seedapp
19+
- "MYSQL_ROOT_PASSWORD=password"
20+
- "MYSQL_DATABASE=seedapp"
2121
ports:
2222
- 3306:3306
23-
command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp
23+
command: mysqld --lower_case_table_names=1 --character_set_server=utf8mb4 --explicit_defaults_for_timestamp
2424
networks:
2525
- seedappnet
2626
emailhog:
@@ -39,16 +39,16 @@ services:
3939
networks:
4040
- seedappnet
4141
keycloak:
42-
image: 'quay.io/keycloak/keycloak:23.0.3'
42+
image: 'quay.io/keycloak/keycloak:25.0.6'
4343
container_name: keycloak
4444
command: start-dev --import-realm
4545
environment:
46-
- KEYCLOAK_DB=dev-file
47-
- KEYCLOAK_ADMIN=admin
48-
- KEYCLOAK_ADMIN_PASSWORD=admin
49-
- KEYCLOAK_FEATURES=scripts
50-
- KEYCLOAK_HTTP_PORT=8080
51-
- KEYCLOAK_HTTPS_PORT=9443
46+
- "KEYCLOAK_DB=dev-file"
47+
- "KEYCLOAK_ADMIN=admin"
48+
- "KEYCLOAK_ADMIN_PASSWORD=admin"
49+
- "KEYCLOAK_FEATURES=scripts"
50+
- "KEYCLOAK_HTTP_PORT=8080"
51+
- "KEYCLOAK_HTTPS_PORT=9443"
5252
# entrypoint: /tmp/keycloak/config/docker-compose-entrypoint.sh --hostname host.docker.internal:8080
5353
volumes:
5454
- ../main-app/main-webapp/src/main/resources/keycloak/:/opt/keycloak/data/import

main-app/main-webapp/pom.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
<artifactId>jquery</artifactId>
185185
</dependency>
186186
<dependency>
187-
<groupId>org.webjars</groupId>
187+
<groupId>org.webjars.npm</groupId>
188188
<artifactId>bootstrap</artifactId>
189189
</dependency>
190190
<dependency>
@@ -237,12 +237,10 @@
237237
<dependency>
238238
<groupId>com.github.dasniko</groupId>
239239
<artifactId>testcontainers-keycloak</artifactId>
240-
<optional>true</optional>
241240
</dependency>
242241
<dependency>
243242
<groupId>org.testcontainers</groupId>
244243
<artifactId>testcontainers</artifactId>
245-
<optional>true</optional>
246244
</dependency>
247245
<dependency>
248246
<groupId>org.testcontainers</groupId>

main-app/main-webapp/src/main/java/gt/app/config/DockerContainerConfig.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class DockerContainerConfig {
3232

3333
String userPwd = "admin";//use same for all
3434

35-
var mysql = new MySQLContainer<>("mysql:8.0.35").withDatabaseName("seedapp").withUsername(userPwd).withPassword(userPwd);
35+
var mysql = new MySQLContainer<>("mysql").withDatabaseName("seedapp").withUsername(userPwd).withPassword(userPwd);
3636
mysql.start();
3737

38-
var activeMQ = new GenericContainer<>("apache/activemq-artemis:2.31.2-alpine");
38+
var activeMQ = new GenericContainer<>("apache/activemq-artemis:2.37.0");
3939
activeMQ.setEnv(List.of("ARTEMIS_USER=admin", "ARTEMIS_PASSWORD=admin"));
4040
activeMQ.withExposedPorts(61616);
4141
activeMQ.start(); //using default ports
4242

43-
var kc = new KeycloakContainer("quay.io/keycloak/keycloak:23.0.3").withRealmImportFile("keycloak/realm-export.json");
43+
var kc = new KeycloakContainer("quay.io/keycloak/keycloak:25.0.6").withRealmImportFile("keycloak/realm-export.json");
4444
kc.start();
4545

4646
setProperty("KEYCLOAK_PORT", Integer.toString(kc.getHttpPort()));

main-app/main-webapp/src/main/resources/templates/_fragments/footer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<div th:fragment="js-imports(scripts)">
2020
<script src="/webjars/jquery/3.6.1/jquery.min.js"></script>
21-
<script src="/webjars/bootstrap/5.0.1/js/bootstrap.min.js"></script>
21+
<script src="/webjars/bootstrap/5.0.1/dist/js/bootstrap.min.js"></script>
2222

2323
<script src="https://cdn.jsdelivr.net/npm/@stomp/[email protected]/bundles/stomp.umd.min.js" integrity="sha512-vVSeibxEBKAfSkPFQ6vluowRjL1BsFLHz0yYyIq60UGN/aOtm4n5u5jHHaLtvc8pgkNAYsRkwvpkgEcBcefaPQ==" crossorigin="anonymous"></script>
2424
<script src="/webjars/jquery-toast-plugin/1.3.2/dist/jquery.toast.min.js"></script>

main-app/main-webapp/src/main/resources/templates/_fragments/header.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta content="" name="generator">
1111
<title th:replace="${title}"> Title ...</title>
1212

13-
<link href="/webjars/bootstrap/5.0.1/css/bootstrap.css" rel="stylesheet">
13+
<link href="/webjars/bootstrap/5.0.1/dist/css/bootstrap.css" rel="stylesheet">
1414
<link href="/webjars/jquery-toast-plugin/1.3.2/dist/jquery.toast.min.css" rel="stylesheet">
1515
<link rel="stylesheet" th:href="@{/static/css/wro-commons.css}"/>
1616

main-app/main-webapp/src/main/resources/templates/_fragments/user.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:th="http://www.thymeleaf.org">
44

55
<head>
6-
<link href="/webjars/bootstrap/5.0.1/css/bootstrap.css" rel="stylesheet">
6+
<link href="/webjars/bootstrap/5.0.1/dist/css/bootstrap.css" rel="stylesheet">
77
<link href="/wro4j/commons.css" rel="stylesheet">
88
<title></title>
99
</head>

main-app/main-webapp/src/test/java/gt/app/e2e/PublicPageIT.java

+26-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import gt.app.config.AppProperties;
44
import gt.app.frwk.TestDataManager;
5-
import io.hypersistence.utils.jdbc.validator.SQLStatementCountValidator;
5+
import net.ttddyy.dsproxy.QueryCountHolder;
66
import org.junit.jupiter.api.BeforeEach;
77
import org.junit.jupiter.api.Test;
88
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +14,7 @@
1414
import org.springframework.test.web.servlet.MockMvc;
1515
import org.springframework.test.web.servlet.MvcResult;
1616

17-
import static io.hypersistence.utils.jdbc.validator.SQLStatementCountValidator.*;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1818
import static org.junit.jupiter.api.Assertions.assertTrue;
1919
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2020
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -31,18 +31,20 @@ class PublicPageIT {
3131
@BeforeEach
3232
void cleanDB() {
3333
testDataManager.cleanDataAndCache();
34-
SQLStatementCountValidator.reset();
35-
3634
}
3735

3836
@Test
3937
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();
4143

4244
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();
4648

4749
String content = result.getResponse().getContentAsString();
4850
assertTrue(content.contains("Article App - HOME"));
@@ -54,20 +56,24 @@ void loadIndexPageAndVerifyResultIsCached(@Autowired MockMvc mvc) throws Excepti
5456
mvc.perform(get("/")).andExpect(status().isOk());
5557

5658
//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());
6163
}
6264

6365
@Test
6466
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();
6672

6773
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();
7177

7278
String content = result.getResponse().getContentAsString();
7379
assertTrue(content.contains("Article App - HOME"));
@@ -79,9 +85,9 @@ void testCacheAndDBBothAreResetBetweenTests(@Autowired MockMvc mvc) throws Excep
7985
mvc.perform(get("/")).andExpect(status().isOk());
8086

8187
//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());
8692
}
8793
}

main-app/main-webapp/src/test/java/gt/app/frwk/TestContainerConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class TestContainerConfig {
2727
static {
2828
log.info("Starting docker containers using TestContainers");
2929

30-
var activeMQ = new GenericContainer<>("apache/activemq-artemis:2.31.2-alpine");
30+
var activeMQ = new GenericContainer<>("apache/activemq-artemis:2.37.0");
3131
activeMQ.withExposedPorts(61616);
3232
activeMQ.setEnv(List.of("ARTEMIS_USER=admin", "ARTEMIS_PASSWORD=admin"));
3333

3434
activeMQ.start(); //using default ports
3535

36-
var kc = new KeycloakContainer("quay.io/keycloak/keycloak:23.0.3").withRealmImportFile("keycloak/realm-export.json");
36+
var kc = new KeycloakContainer("quay.io/keycloak/keycloak:25.0.6").withRealmImportFile("keycloak/realm-export.json");
3737
kc.start();
3838

3939
setProperty("KEYCLOAK_PORT", Integer.toString(kc.getHttpPort()));

main-app/main-webapp/src/test/resources/application.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spring:
99
datasource:
1010
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL
1111
jpa:
12-
show-sql: false
12+
show-sql: true
1313
open-in-view: false
1414
hibernate:
1515
ddl-auto: none # we use liquibase
@@ -73,6 +73,7 @@ decorator:
7373
datasource:
7474
enabled: true
7575
datasource-proxy:
76+
count-query: true
7677
slow-query:
7778
threshold: 1
7879
query:

0 commit comments

Comments
 (0)